-
Notifications
You must be signed in to change notification settings - Fork 0
/
pacific_tzinfo.py
32 lines (25 loc) · 1.03 KB
/
pacific_tzinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# pulled from:
# http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html
import datetime
class Pacific_tzinfo(datetime.tzinfo):
"""Implementation of the Pacific timezone."""
def utcoffset(self, dt):
return datetime.timedelta(hours=-8) + self.dst(dt)
def _FirstSunday(self, dt):
"""First Sunday on or after dt."""
return dt + datetime.timedelta(days=(6-dt.weekday()))
def dst(self, dt):
# 2 am on the second Sunday in March
dst_start = self._FirstSunday(datetime.datetime(dt.year, 3, 8, 2))
# 1 am on the first Sunday in November
dst_end = self._FirstSunday(datetime.datetime(dt.year, 11, 1, 1))
if dst_start <= dt.replace(tzinfo=None) < dst_end:
return datetime.timedelta(hours=1)
else:
return datetime.timedelta(hours=0)
def tzname(self, dt):
if self.dst(dt) == datetime.timedelta(hours=0):
return "PST"
else:
return "PDT"
Pacific = Pacific_tzinfo()