Commit 52347a7e authored by Hanno Schlichting's avatar Hanno Schlichting

Pull in DateTime from the new external package location

parent db20880e
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Encapsulation of date/time values"""
__version__='$Revision: 1.99 $'[11:-2]
import re, math, DateTimeZone
from time import time, gmtime, localtime
from time import daylight, timezone, altzone, strftime
from datetime import datetime
from interfaces import IDateTime
from interfaces import DateTimeError, SyntaxError, DateError, TimeError
from zope.interface import implements
from pytz_support import PytzCache
_cache = PytzCache
default_datefmt = None
def getDefaultDateFormat():
global default_datefmt
if default_datefmt is None:
try:
from App.config import getConfiguration
default_datefmt = getConfiguration().datetime_format
return default_datefmt
except:
return 'us'
else:
return default_datefmt
try:
from time import tzname
except:
tzname=('UNKNOWN','UNKNOWN')
# To control rounding errors, we round system time to the nearest
# microsecond. Then delicate calculations can rely on that the
# maximum precision that needs to be preserved is known.
_system_time = time
def time():
return round(_system_time(), 6)
# Determine machine epoch
tm=((0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
(0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335))
yr,mo,dy,hr,mn,sc=gmtime(0)[:6]
i=int(yr-1)
to_year =int(i*365+i/4-i/100+i/400-693960.0)
to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo]
EPOCH =(to_year+to_month+dy+(hr/24.0+mn/1440.0+sc/86400.0))*86400
jd1901 =2415385L
numericTimeZoneMatch = re.compile(r'[+-][0-9][0-9][0-9][0-9]').match
iso8601Match = re.compile(r'''
(?P<year>\d\d\d\d) # four digits year
(?:-? # one optional dash
(?: # followed by:
(?P<year_day>\d\d\d # three digits year day
(?!\d)) # when there is no fourth digit
| # or:
W # one W
(?P<week>\d\d) # two digits week
(?:-? # one optional dash
(?P<week_day>\d) # one digit week day
)? # week day is optional
| # or:
(?P<month>\d\d)? # two digits month
(?:-? # one optional dash
(?P<day>\d\d)? # two digits day
)? # after day is optional
) #
)? # after year is optional
(?:[T ] # one T or one whitespace
(?P<hour>\d\d) # two digits hour
(?::? # one optional colon
(?P<minute>\d\d)? # two digits minute
(?::? # one optional colon
(?P<second>\d\d)? # two digits second
(?:[.,] # one dot or one comma
(?P<fraction>\d+) # n digits fraction
)? # after second is optional
)? # after minute is optional
)? # after hour is optional
(?: # timezone:
(?P<Z>Z) # one Z
| # or:
(?P<signal>[-+]) # one plus or one minus as signal
(?P<hour_off>\d # one digit for hour offset...
(?:\d(?!\d$) # ...or two, if not the last two digits
)?) # second hour offset digit is optional
(?::? # one optional colon
(?P<min_off>\d\d) # two digits minute offset
)? # after hour offset is optional
)? # timezone is optional
)? # time is optional
(?P<garbage>.*) # store the extra garbage
''', re.VERBOSE).match
def _findLocalTimeZoneName(isDST):
if not daylight:
# Daylight savings does not occur in this time zone.
isDST = 0
try:
# Get the name of the current time zone depending
# on DST.
_localzone = _cache._zmap[tzname[isDST].lower()]
except:
try:
# Generate a GMT-offset zone name.
if isDST:
localzone = altzone
else:
localzone = timezone
offset=(-localzone/(60*60.0))
majorOffset=int(offset)
if majorOffset != 0 :
minorOffset=abs(int((offset % majorOffset) * 60.0))
else: minorOffset = 0
m=majorOffset >= 0 and '+' or ''
lz='%s%0.02d%0.02d' % (m, majorOffset, minorOffset)
_localzone = _cache._zmap[('GMT%s' % lz).lower()]
except:
_localzone = ''
return _localzone
# Some utility functions for calculating dates:
def _calcSD(t):
# Returns timezone-independent days since epoch and the fractional
# part of the days.
dd = t + EPOCH - 86400.0
d = dd / 86400.0
s = d - math.floor(d)
return s, d
def _calcDependentSecond(tz, t):
# Calculates the timezone-dependent second (integer part only)
# from the timezone-independent second.
fset = _tzoffset(tz, t)
return fset + long(math.floor(t)) + long(EPOCH) - 86400L
def _calcDependentSecond2(yr,mo,dy,hr,mn,sc):
# Calculates the timezone-dependent second (integer part only)
# from the date given.
ss = int(hr) * 3600 + int(mn) * 60 + int(sc)
x = long(_julianday(yr,mo,dy)-jd1901) * 86400 + ss
return x
def _calcIndependentSecondEtc(tz, x, ms):
# Derive the timezone-independent second from the timezone
# dependent second.
fsetAtEpoch = _tzoffset(tz, 0.0)
nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
# nearTime is now within an hour of being correct.
# Recalculate t according to DST.
fset = long(_tzoffset(tz, nearTime))
x_adjusted = x - fset + ms
d = x_adjusted / 86400.0
t = x_adjusted - long(EPOCH) + 86400L
micros = (x + 86400 - fset) * 1000000 + \
long(round(ms * 1000000.0)) - long(EPOCH * 1000000.0)
s = d - math.floor(d)
return s,d,t,micros
def _calcHMS(x, ms):
# hours, minutes, seconds from integer and float.
hr = x / 3600
x = x - hr * 3600
mn = x / 60
sc = x - mn * 60 + ms
return hr,mn,sc
def _calcYMDHMS(x, ms):
# x is a timezone-dependent integer of seconds.
# Produces yr,mo,dy,hr,mn,sc.
yr,mo,dy=_calendarday(x / 86400 + jd1901)
x = int(x - (x / 86400) * 86400)
hr = x / 3600
x = x - hr * 3600
mn = x / 60
sc = x - mn * 60 + ms
return yr,mo,dy,hr,mn,sc
def _julianday(yr,mo,dy):
y,m,d=long(yr),long(mo),long(dy)
if m > 12L:
y=y+m/12L
m=m%12L
elif m < 1L:
m=-m
y=y-m/12L-1L
m=12L-m%12L
if y > 0L:
yr_correct=0L
else:
yr_correct=3L
if m < 3L:
y,m=y-1L,m+12L
if y*10000L+m*100L+d > 15821014L:
b=2L-y/100L+y/400L
else:
b=0L
return (1461L*y-yr_correct)/4L+306001L*(m+1L)/10000L+d+1720994L+b
def _calendarday(j):
j=long(j)
if(j < 2299160L):
b=j+1525L
else:
a=(4L*j-7468861L)/146097L
b=j+1526L+a-a/4L
c=(20L*b-2442L)/7305L
d=1461L*c/4L
e=10000L*(b-d)/306001L
dy=int(b-d-306001L*e/10000L)
mo=(e < 14L) and int(e-1L) or int(e-13L)
yr=(mo > 2) and (c-4716L) or (c-4715L)
return int(yr),int(mo),int(dy)
def _tzoffset(tz, t):
"""Returns the offset in seconds to GMT from a specific timezone (tz) at
a specific time (t). NB! The _tzoffset result is the same same sign as
the time zone, i.e. GMT+2 has a 7200 second offset. This is the opposite
sign of time.timezone which (confusingly) is -7200 for GMT+2."""
try:
return DateTime._tzinfo[tz].info(t)[0]
except:
if numericTimeZoneMatch(tz) is not None:
return int(tz[0:3])*3600+int(tz[0]+tz[3:5])*60
else:
return 0 # ??
def _correctYear(year):
# Y2K patch.
if year >= 0 and year < 100:
# 00-69 means 2000-2069, 70-99 means 1970-1999.
if year < 70:
year = 2000 + year
else:
year = 1900 + year
return year
def safegmtime(t):
'''gmtime with a safety zone.'''
try:
t_int = int(t)
if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a long!
return gmtime(t_int)
except (ValueError, OverflowError):
raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t)
def safelocaltime(t):
'''localtime with a safety zone.'''
try:
t_int = int(t)
if isinstance(t_int, long):
raise OverflowError # Python 2.3 fix: int can return a long!
return localtime(t_int)
except (ValueError, OverflowError):
raise TimeError, 'The time %f is beyond the range ' \
'of this Python implementation.' % float(t)
def _tzoffset2rfc822zone(seconds):
"""Takes an offset, such as from _tzoffset(), and returns an rfc822
compliant zone specification. Please note that the result of
_tzoffset() is the negative of what time.localzone and time.altzone is."""
return "%+03d%02d" % divmod( (seconds/60), 60)
def _tzoffset2iso8601zone(seconds):
"""Takes an offset, such as from _tzoffset(), and returns an ISO 8601
compliant zone specification. Please note that the result of
_tzoffset() is the negative of what time.localzone and time.altzone is."""
return "%+03d:%02d" % divmod( (seconds/60), 60)
class DateTime:
"""DateTime objects represent instants in time and provide
interfaces for controlling its representation without
affecting the absolute value of the object.
DateTime objects may be created from a wide variety of string
or numeric data, or may be computed from other DateTime objects.
DateTimes support the ability to convert their representations
to many major timezones, as well as the ablility to create a
DateTime object in the context of a given timezone.
DateTime objects provide partial numerical behavior:
- Two date-time objects can be subtracted to obtain a time,
in days between the two.
- A date-time object and a positive or negative number may
be added to obtain a new date-time object that is the given
number of days later than the input date-time object.
- A positive or negative number and a date-time object may
be added to obtain a new date-time object that is the given
number of days later than the input date-time object.
- A positive or negative number may be subtracted from a
date-time object to obtain a new date-time object that is
the given number of days earlier than the input date-time
object.
DateTime objects may be converted to integer, long, or float
numbers of days since January 1, 1901, using the standard int,
long, and float functions (Compatibility Note: int, long and
float return the number of days since 1901 in GMT rather than
local machine timezone). DateTime objects also provide access
to their value in a float format usable with the python time
module, provided that the value of the object falls in the
range of the epoch-based time module, and as a datetime.datetime
object.
A DateTime object should be considered immutable; all conversion
and numeric operations return a new DateTime object rather than
modify the current object."""
implements(IDateTime)
# For security machinery:
__roles__=None
__allow_access_to_unprotected_subobjects__=1
# Make class-specific exceptions available as attributes.
DateError = DateError
TimeError = TimeError
DateTimeError = DateTimeError
SyntaxError = SyntaxError
def __init__(self,*args, **kw):
"""Return a new date-time object"""
try:
return self._parse_args(*args, **kw)
except (DateError, TimeError, DateTimeError):
raise
except:
raise SyntaxError('Unable to parse %s, %s' % (args, kw))
def _parse_args(self, *args, **kw):
"""Return a new date-time object.
A DateTime object always maintains its value as an absolute
UTC time, and is represented in the context of some timezone
based on the arguments used to create the object. A DateTime
object's methods return values based on the timezone context.
Note that in all cases the local machine timezone is used for
representation if no timezone is specified.
DateTimes may be created with from zero to seven arguments.
- If the function is called with no arguments or with None,
then the current date/time is returned, represented in the
timezone of the local machine.
- If the function is invoked with a single string argument
which is a recognized timezone name, an object representing
the current time is returned, represented in the specified
timezone.
- If the function is invoked with a single string argument
representing a valid date/time, an object representing
that date/time will be returned.
As a general rule, any date-time representation that is
recognized and unambigous to a resident of North America
is acceptable. The reason for this qualification is that
in North America, a date like: 2/1/1994 is interpreted
as February 1, 1994, while in some parts of the world,
it is interpreted as January 2, 1994.
A date/time string consists of two components, a date
component and an optional time component, separated by one
or more spaces. If the time component is omited, 12:00am is
assumed. Any recognized timezone name specified as the final
element of the date/time string will be used for computing
the date/time value. If you create a DateTime with the
string 'Mar 9, 1997 1:45pm US/Pacific', the value will
essentially be the same as if you had captured time.time()
at the specified date and time on a machine in that timezone:
<PRE>
e=DateTime('US/Eastern')
# returns current date/time, represented in US/Eastern.
x=DateTime('1997/3/9 1:45pm')
# returns specified time, represented in local machine zone.
y=DateTime('Mar 9, 1997 13:45:00')
# y is equal to x
</PRE>
The date component consists of year, month, and day
values. The year value must be a one-, two-, or
four-digit integer. If a one- or two-digit year is
used, the year is assumed to be in the twentieth
century. The month may be an integer, from 1 to 12, a
month name, or a month abreviation, where a period may
optionally follow the abreviation. The day must be an
integer from 1 to the number of days in the month. The
year, month, and day values may be separated by
periods, hyphens, forward, shashes, or spaces. Extra
spaces are permitted around the delimiters. Year,
month, and day values may be given in any order as long
as it is possible to distinguish the components. If all
three components are numbers that are less than 13,
then a a month-day-year ordering is assumed.
The time component consists of hour, minute, and second
values separated by colons. The hour value must be an
integer between 0 and 23 inclusively. The minute value
must be an integer between 0 and 59 inclusively. The
second value may be an integer value between 0 and
59.999 inclusively. The second value or both the minute
and second values may be ommitted. The time may be
followed by am or pm in upper or lower case, in which
case a 12-hour clock is assumed.
New in Zope 2.4:
The DateTime constructor automatically detects and handles
ISO8601 compliant dates (YYYY-MM-DDThh:ss:mmTZD).
New in Zope 2.9.6:
The existing ISO8601 parser was extended to support almost
the whole ISO8601 specification. New formats includes:
<PRE>
y=DateTime('1993-045')
# returns the 45th day from 1993, which is 14th February
w=DateTime('1993-W06-7')
# returns the 7th day from the 6th week from 1993, which
# is also 14th February
</PRE>
See http://en.wikipedia.org/wiki/ISO_8601 for full specs.
Note that the Zope DateTime parser assumes timezone naive ISO
strings to be in UTC rather than local time as specified.
- If the DateTime function is invoked with a single Numeric
argument, the number is assumed to be a floating point value
such as that returned by time.time().
A DateTime object is returned that represents the GMT value
of the time.time() float represented in the local machine's
timezone.
- If the DateTime function is invoked with a single argument
that is a DateTime instane, a copy of the passed object will
be created.
- New in 2.11:
The DateTime function may now be invoked with a single argument
that is a datetime.datetime instance. DateTimes may be converted
back to datetime.datetime objects with asdatetime().
DateTime instances may be converted to a timezone naive
datetime.datetime in UTC with utcdatetime().
- If the function is invoked with two numeric arguments, then
the first is taken to be an integer year and the second
argument is taken to be an offset in days from the beginning
of the year, in the context of the local machine timezone.
The date-time value returned is the given offset number of
days from the beginning of the given year, represented in
the timezone of the local machine. The offset may be positive
or negative.
Two-digit years are assumed to be in the twentieth
century.
- If the function is invoked with two arguments, the first
a float representing a number of seconds past the epoch
in gmt (such as those returned by time.time()) and the
second a string naming a recognized timezone, a DateTime
with a value of that gmt time will be returned, represented
in the given timezone.
<PRE>
import time
t=time.time()
now_east=DateTime(t,'US/Eastern')
# Time t represented as US/Eastern
now_west=DateTime(t,'US/Pacific')
# Time t represented as US/Pacific
# now_east == now_west
# only their representations are different
</PRE>
- If the function is invoked with three or more numeric
arguments, then the first is taken to be an integer
year, the second is taken to be an integer month, and
the third is taken to be an integer day. If the
combination of values is not valid, then a
DateError is raised. Two-digit years are assumed
to be in the twentieth century. The fourth, fifth, and
sixth arguments specify a time in hours, minutes, and
seconds; hours and minutes should be positive integers
and seconds is a positive floating point value, all of
these default to zero if not given. An optional string may
be given as the final argument to indicate timezone (the
effect of this is as if you had taken the value of time.time()
at that time on a machine in the specified timezone).
New in Zope 2.7:
A new keyword parameter "datefmt" can be passed to the
constructor. If set to "international", the constructor
is forced to treat ambigious dates as "days before month
before year". This useful if you need to parse non-US
dates in a reliable way
In any case that a floating point number of seconds is given
or derived, it's rounded to the nearest millisecond.
If a string argument passed to the DateTime constructor cannot be
parsed, it will raise DateTime.SyntaxError. Invalid date components
will raise a DateError, while invalid time or timezone components
will raise a DateTimeError.
The module function Timezones() will return a list of the (common)
timezones recognized by the DateTime module. Recognition of
timezone names is case-insensitive.
"""
datefmt = kw.get('datefmt', getDefaultDateFormat())
d=t=s=None
ac=len(args)
microsecs = None
if ac==10:
# Internal format called only by DateTime
yr,mo,dy,hr,mn,sc,tz,t,d,s=args
elif ac == 11:
# Internal format that includes milliseconds (from the epoch)
yr,mo,dy,hr,mn,sc,tz,t,d,s,millisecs=args
microsecs = millisecs * 1000
elif ac == 12:
# Internal format that includes microseconds (from the epoch) and a
# flag indicating whether this was constructed in a timezone naive
# manner
yr,mo,dy,hr,mn,sc,tz,t,d,s,microsecs,tznaive=args
if tznaive is not None: # preserve this information
self._timezone_naive = tznaive
elif not args or (ac and args[0]==None):
# Current time, to be displayed in local timezone
t = time()
lt = safelocaltime(t)
tz = self.localZone(lt)
ms = (t - math.floor(t))
s,d = _calcSD(t)
yr,mo,dy,hr,mn,sc=lt[:6]
sc=sc+ms
self._timezone_naive = False
elif ac==1:
arg=args[0]
if arg=='':
raise SyntaxError, arg
if isinstance(arg, DateTime):
"""Construct a new DateTime instance from a given
DateTime instance.
"""
t = arg.timeTime()
s,d = _calcSD(t)
yr,mo,dy,hr,mn,sc,tz = arg.parts()
elif isinstance(arg, datetime):
yr,mo,dy,hr,mn,sc,numerictz,tznaive=self._parse_iso8601_preserving_tznaive(arg.isoformat())
if arg.tzinfo is None:
self._timezone_naive = True
tz = None
else:
self._timezone_naive = False
# if we have a pytz tzinfo, use the `zone` attribute as a key
tz = getattr(arg.tzinfo, 'zone', numerictz)
ms = sc - math.floor(sc)
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
if tz:
try:
zone = self._tzinfo[tz]
except DateTimeError:
try:
zone = self._tzinfo[numerictz]
except DateTimeError:
raise DateTimeError, \
'Unknown time zone in date: %s' % arg
tz = zone.tzinfo.zone
else:
tz = self._calcTimezoneName(x, ms)
s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
elif isinstance(arg, (unicode, str)) and arg.lower() in self._tzinfo._zidx:
# Current time, to be displayed in specified timezone
t,tz=time(),self._tzinfo._zmap[arg.lower()]
ms=(t-math.floor(t))
# Use integer arithmetic as much as possible.
s,d = _calcSD(t)
x = _calcDependentSecond(tz, t)
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x, ms)
elif isinstance(arg, (unicode, str)):
# Date/time string
iso8601 = iso8601Match(arg.strip())
fields_iso8601 = iso8601 and iso8601.groupdict() or {}
if fields_iso8601 and not fields_iso8601.get('garbage'):
yr,mo,dy,hr,mn,sc,tz,tznaive=self._parse_iso8601_preserving_tznaive(arg)
self._timezone_naive = tznaive
else:
yr,mo,dy,hr,mn,sc,tz=self._parse(arg, datefmt)
if not self._validDate(yr,mo,dy):
raise DateError, 'Invalid date: %s' % arg
if not self._validTime(hr,mn,int(sc)):
raise TimeError, 'Invalid time: %s' % arg
ms = sc - math.floor(sc)
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
if tz:
try: tz=self._tzinfo._zmap[tz.lower()]
except KeyError:
if numericTimeZoneMatch(tz) is None:
raise DateTimeError, \
'Unknown time zone in date: %s' % arg
else:
tz = self._calcTimezoneName(x, ms)
s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
else:
# Seconds from epoch, gmt
t = arg
lt = safelocaltime(t)
tz = self.localZone(lt)
ms=(t-math.floor(t))
s,d = _calcSD(t)
yr,mo,dy,hr,mn,sc=lt[:6]
sc=sc+ms
elif ac==2:
if isinstance(args[1], str):
# Seconds from epoch (gmt) and timezone
t,tz=args
ms = (t - math.floor(t))
tz=self._tzinfo._zmap[tz.lower()]
# Use integer arithmetic as much as possible.
s,d = _calcSD(t)
x = _calcDependentSecond(tz, t)
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x, ms)
else:
# Year, julian expressed in local zone
t = time()
lt = safelocaltime(t)
tz = self.localZone(lt)
yr,jul=args
yr = _correctYear(yr)
d=(_julianday(yr,1,0)-jd1901)+jul
x_float = d * 86400.0
x_floor = math.floor(x_float)
ms = x_float - x_floor
x = long(x_floor)
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x, ms)
s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
else:
# Explicit format
yr,mo,dy=args[:3]
hr,mn,sc,tz=0,0,0,0
yr = _correctYear(yr)
if not self._validDate(yr,mo,dy):
raise DateError, 'Invalid date: %s' % (args,)
args=args[3:]
if args:
hr,args=args[0],args[1:]
if args:
mn,args=args[0],args[1:]
if args:
sc,args=args[0],args[1:]
if args:
tz,args=args[0],args[1:]
if args:
raise DateTimeError,'Too many arguments'
if not self._validTime(hr,mn,sc):
raise TimeError, 'Invalid time: %s' % `args`
leap = (yr % 4 == 0) and (yr % 100 != 0 or yr % 400 == 0)
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
ms = sc - math.floor(sc)
if tz:
try: tz=self._tzinfo._zmap[tz.lower()]
except KeyError:
if numericTimeZoneMatch(tz) is None:
raise DateTimeError, \
'Unknown time zone: %s' % tz
else:
# Get local time zone name
tz = self._calcTimezoneName(x, ms)
s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)
if hr>12:
self._pmhour=hr-12
self._pm='pm'
else:
self._pmhour=hr or 12
self._pm= (hr==12) and 'pm' or 'am'
self._dayoffset=dx=int((_julianday(yr,mo,dy)+2L)%7)
self._fmon,self._amon,self._pmon= \
self._months[mo],self._months_a[mo],self._months_p[mo]
self._fday,self._aday,self._pday= \
self._days[dx],self._days_a[dx],self._days_p[dx]
# Round to nearest microsecond in platform-independent way. You
# cannot rely on C sprintf (Python '%') formatting to round
# consistently; doing it ourselves ensures that all but truly
# horrid C sprintf implementations will yield the same result
# x-platform, provided the format asks for exactly 6 digits after
# the decimal point.
sc = round(sc, 6)
if sc >= 60.0: # can happen if, e.g., orig sc was 59.9999999
sc = 59.999999
self._nearsec=math.floor(sc)
self._year,self._month,self._day =yr,mo,dy
self._hour,self._minute,self._second =hr,mn,sc
self.time,self._d,self._t,self._tz =s,d,t,tz
if microsecs is None:
microsecs = long(math.floor(t * 1000000.0))
self._micros = microsecs
# self._micros is the time since the epoch
# in long integer microseconds.
int_pattern =re.compile(r'([0-9]+)') #AJ
flt_pattern =re.compile(r':([0-9]+\.[0-9]+)') #AJ
name_pattern =re.compile(r'([a-zA-Z]+)', re.I) #AJ
space_chars =' \t\n'
delimiters ='-/.:,+'
_month_len =((0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31),
(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31))
_until_month=((0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
(0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335))
_months =['','January','February','March','April','May','June','July',
'August', 'September', 'October', 'November', 'December']
_months_a =['','Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
_months_p =['','Jan.', 'Feb.', 'Mar.', 'Apr.', 'May', 'June',
'July', 'Aug.', 'Sep.', 'Oct.', 'Nov.', 'Dec.']
_monthmap ={'january': 1, 'jan': 1,
'february': 2, 'feb': 2,
'march': 3, 'mar': 3,
'april': 4, 'apr': 4,
'may': 5,
'june': 6, 'jun': 6,
'july': 7, 'jul': 7,
'august': 8, 'aug': 8,
'september': 9, 'sep': 9, 'sept': 9,
'october': 10, 'oct': 10,
'november': 11, 'nov': 11,
'december': 12, 'dec': 12}
_days =['Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday']
_days_a =['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
_days_p =['Sun.', 'Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.']
_daymap ={'sunday': 1, 'sun': 1,
'monday': 2, 'mon': 2,
'tuesday': 3, 'tues': 3, 'tue': 3,
'wednesday': 4, 'wed': 4,
'thursday': 5, 'thurs': 5, 'thur': 5, 'thu': 5,
'friday': 6, 'fri': 6,
'saturday': 7, 'sat': 7}
_localzone0 = _findLocalTimeZoneName(0)
_localzone1 = _findLocalTimeZoneName(1)
_multipleZones = (_localzone0 != _localzone1)
# For backward compatibility only:
_isDST = localtime(time())[8]
_localzone = _isDST and _localzone1 or _localzone0
_tzinfo = PytzCache()
def localZone(self, ltm=None):
'''Returns the time zone on the given date. The time zone
can change according to daylight savings.'''
if not DateTime._multipleZones:
return DateTime._localzone0
if ltm == None:
ltm = localtime(time())
isDST = ltm[8]
lz = isDST and DateTime._localzone1 or DateTime._localzone0
return lz
def _calcTimezoneName(self, x, ms):
# Derive the name of the local time zone at the given
# timezone-dependent second.
if not DateTime._multipleZones:
return DateTime._localzone0
fsetAtEpoch = _tzoffset(DateTime._localzone0, 0.0)
nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
# nearTime is within an hour of being correct.
try:
ltm = safelocaltime(nearTime)
except:
# We are beyond the range of Python's date support.
# Hopefully we can assume that daylight savings schedules
# repeat every 28 years. Calculate the name of the
# time zone using a supported range of years.
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x, 0)
yr = ((yr - 1970) % 28) + 1970
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
nearTime = x - fsetAtEpoch - long(EPOCH) + 86400L + ms
# nearTime might still be negative if we are east of Greenwich.
# But we can asume on 1969/12/31 were no timezone changes.
nearTime = max(0, nearTime)
ltm = safelocaltime(nearTime)
tz = self.localZone(ltm)
return tz
def _parse(self,st, datefmt=getDefaultDateFormat()):
# Parse date-time components from a string
month=year=tz=tm=None
spaces =self.space_chars
intpat =self.int_pattern
fltpat =self.flt_pattern
wordpat =self.name_pattern
delimiters =self.delimiters
MonthNumbers =self._monthmap
DayOfWeekNames=self._daymap
ValidZones =self._tzinfo._zidx
TimeModifiers =['am','pm']
# Find timezone first, since it should always be the last
# element, and may contain a slash, confusing the parser.
st= st.strip()
sp=st.split()
tz=sp[-1]
if tz and (tz.lower() in ValidZones):
self._timezone_naive = False
st=' '.join(sp[:-1])
else:
self._timezone_naive = True
tz = None # Decide later, since the default time zone
# could depend on the date.
ints,dels=[],[]
i,l=0,len(st)
while i < l:
while i < l and st[i] in spaces : i=i+1
if i < l and st[i] in delimiters:
d=st[i]
i=i+1
else:
d=''
while i < l and st[i] in spaces : i=i+1
# The float pattern needs to look back 1 character, because it
# actually looks for a preceding colon like ':33.33'. This is
# needed to avoid accidentally matching the date part of a
# dot-separated date string such as '1999.12.31'.
if i > 0: b=i-1
else: b=i
ts_results = fltpat.match(st, b)
if ts_results:
s=ts_results.group(1)
i=i+len(s)
ints.append(float(s))
continue
#AJ
ts_results = intpat.match(st, i)
if ts_results:
s=ts_results.group(0)
ls=len(s)
i=i+ls
if (ls==4 and d and d in '+-' and
(len(ints) + (not not month) >= 3)):
tz='%s%s' % (d,s)
else:
v=int(s)
ints.append(v)
continue
ts_results = wordpat.match(st, i)
if ts_results:
o,s=ts_results.group(0),ts_results.group(0).lower()
i=i+len(s)
if i < l and st[i]=='.': i=i+1
# Check for month name:
if MonthNumbers.has_key(s):
v=MonthNumbers[s]
if month is None: month=v
else: raise SyntaxError, st
continue
# Check for time modifier:
if s in TimeModifiers:
if tm is None: tm=s
else: raise SyntaxError, st
continue
# Check for and skip day of week:
if DayOfWeekNames.has_key(s):
continue
raise SyntaxError, st
day=None
if ints[-1] > 60 and d not in ['.',':','/'] and len(ints) > 2:
year=ints[-1]
del ints[-1]
if month:
day=ints[0]
del ints[:1]
else:
month=ints[0]
day=ints[1]
del ints[:2]
elif month:
if len(ints) > 1:
if ints[0] > 31:
year=ints[0]
day=ints[1]
else:
year=ints[1]
day=ints[0]
del ints[:2]
elif len(ints) > 2:
if ints[0] > 31:
year=ints[0]
if ints[1] > 12:
day=ints[1]
month=ints[2]
else:
day=ints[2]
month=ints[1]
if ints[1] > 31:
year=ints[1]
if ints[0] > 12 and ints[2] <= 12:
day=ints[0]
month=ints[2]
elif ints[2] > 12 and ints[0] <= 12:
day=ints[2]
month=ints[0]
elif ints[2] > 31:
year=ints[2]
if ints[0] > 12:
day=ints[0]
month=ints[1]
else:
if datefmt=="us":
day=ints[1]
month=ints[0]
else:
day=ints[0]
month=ints[1]
elif ints[0] <= 12:
month=ints[0]
day=ints[1]
year=ints[2]
del ints[:3]
if day is None:
# Use today's date.
year,month,day = localtime(time())[:3]
year = _correctYear(year)
if year < 1000: raise SyntaxError, st
leap = year%4==0 and (year%100!=0 or year%400==0)
try:
if not day or day > self._month_len[leap][month]:
raise DateError, st
except IndexError:
raise DateError, st
tod=0
if ints:
i=ints[0]
# Modify hour to reflect am/pm
if tm and (tm=='pm') and i<12: i=i+12
if tm and (tm=='am') and i==12: i=0
if i > 24: raise TimeError, st
tod = tod + int(i) * 3600
del ints[0]
if ints:
i=ints[0]
if i > 60: raise TimeError, st
tod = tod + int(i) * 60
del ints[0]
if ints:
i=ints[0]
if i > 60: raise TimeError, st
tod = tod + i
del ints[0]
if ints: raise SyntaxError,st
tod_int = int(math.floor(tod))
ms = tod - tod_int
hr,mn,sc = _calcHMS(tod_int, ms)
if not tz:
# Figure out what time zone it is in the local area
# on the given date.
x = _calcDependentSecond2(year,month,day,hr,mn,sc)
tz = self._calcTimezoneName(x, ms)
return year,month,day,hr,mn,sc,tz
# Internal methods
def __getinitargs__(self):
return (None,)
def _validDate(self,y,m,d):
if m<1 or m>12 or y<0 or d<1 or d>31:
return 0
return d<=self._month_len[(y%4==0 and (y%100!=0 or y%400==0))][m]
def _validTime(self,h,m,s):
return h>=0 and h<=23 and m>=0 and m<=59 and s>=0 and s < 60
def __getattr__(self, name):
if '%' in name:
return strftimeFormatter(self, name)
raise AttributeError, name
# Conversion and comparison methods
def timeTime(self):
"""Return the date/time as a floating-point number in UTC,
in the format used by the python time module.
Note that it is possible to create date/time values with
DateTime that have no meaningful value to the time module.
"""
return self._t
def toZone(self, z):
"""Return a DateTime with the value as the current
object, represented in the indicated timezone.
"""
t,tz=self._t,self._tzinfo._zmap[z.lower()]
micros = self.micros()
tznaive = False # you're performing a timzone change, can't be naive
try:
# Try to use time module for speed.
yr,mo,dy,hr,mn,sc=safegmtime(t+_tzoffset(tz, t))[:6]
sc=self._second
return self.__class__(yr,mo,dy,hr,mn,sc,tz,t,
self._d,self.time,micros,tznaive)
except: # gmtime can't perform the calculation in the given range.
# Calculate the difference between the two time zones.
tzdiff = _tzoffset(tz, t) - _tzoffset(self._tz, t)
if tzdiff == 0:
return self
sc = self._second
ms = sc - math.floor(sc)
x = _calcDependentSecond2(self._year, self._month, self._day,
self._hour, self._minute, sc)
x_new = x + tzdiff
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x_new, ms)
return self.__class__(yr,mo,dy,hr,mn,sc,tz,t,
self._d,self.time,micros,tznaive)
def isFuture(self):
"""Return true if this object represents a date/time
later than the time of the call.
"""
return (self._t > time())
def isPast(self):
"""Return true if this object represents a date/time
earlier than the time of the call.
"""
return (self._t < time())
def isCurrentYear(self):
"""Return true if this object represents a date/time
that falls within the current year, in the context
of this object\'s timezone representation.
"""
t=time()
return safegmtime(t+_tzoffset(self._tz, t))[0]==self._year
def isCurrentMonth(self):
"""Return true if this object represents a date/time
that falls within the current month, in the context
of this object\'s timezone representation.
"""
t=time()
gmt=safegmtime(t+_tzoffset(self._tz, t))
return gmt[0]==self._year and gmt[1]==self._month
def isCurrentDay(self):
"""Return true if this object represents a date/time
that falls within the current day, in the context
of this object\'s timezone representation.
"""
t=time()
gmt=safegmtime(t+_tzoffset(self._tz, t))
return gmt[0]==self._year and gmt[1]==self._month and gmt[2]==self._day
def isCurrentHour(self):
"""Return true if this object represents a date/time
that falls within the current hour, in the context
of this object\'s timezone representation.
"""
t=time()
gmt=safegmtime(t+_tzoffset(self._tz, t))
return (gmt[0]==self._year and gmt[1]==self._month and
gmt[2]==self._day and gmt[3]==self._hour)
def isCurrentMinute(self):
"""Return true if this object represents a date/time
that falls within the current minute, in the context
of this object\'s timezone representation.
"""
t=time()
gmt=safegmtime(t+_tzoffset(self._tz, t))
return (gmt[0]==self._year and gmt[1]==self._month and
gmt[2]==self._day and gmt[3]==self._hour and
gmt[4]==self._minute)
def earliestTime(self):
"""Return a new DateTime object that represents the earliest
possible time (in whole seconds) that still falls within
the current object\'s day, in the object\'s timezone context.
"""
return self.__class__(self._year,self._month,self._day,0,0,0,self._tz)
def latestTime(self):
"""Return a new DateTime object that represents the latest
possible time (in whole seconds) that still falls within
the current object\'s day, in the object\'s timezone context.
"""
return self.__class__(self._year,self._month,self._day,
23,59,59,self._tz)
def greaterThan(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time greater
than the specified DateTime or time module style time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros > t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t > t)
__gt__ = greaterThan
def greaterThanEqualTo(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time greater
than or equal to the specified DateTime or time module style
time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros >= t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t >= t)
__ge__ = greaterThanEqualTo
def equalTo(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time equal to
the specified DateTime or time module style time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros == t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t == t)
__eq__ = equalTo
def notEqualTo(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time not equal
to the specified DateTime or time module style time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros != t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t != t)
__ne__ = notEqualTo
def lessThan(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time less than
the specified DateTime or time module style time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros < t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t < t)
__lt__ = lessThan
def lessThanEqualTo(self,t):
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
by the python time module.
Returns true if the object represents a date/time less than
or equal to the specified DateTime or time module style time.
Revised to give more correct results through comparison of
long integer microseconds.
"""
# Optimized for sorting speed
try:
return (self._micros <= t._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return (self._t <= t)
__le__ = lessThanEqualTo
def isLeapYear(self):
"""Return true if the current year (in the context of the
object\'s timezone) is a leap year.
"""
return self._year%4==0 and (self._year%100!=0 or self._year%400==0)
def dayOfYear(self):
"""Return the day of the year, in context of the timezone
representation of the object.
"""
d=int(self._d+(_tzoffset(self._tz, self._t)/86400.0))
return int((d+jd1901)-_julianday(self._year,1,0))
# Component access
def parts(self):
"""Return a tuple containing the calendar year, month,
day, hour, minute second and timezone of the object.
"""
return self._year, self._month, self._day, self._hour, \
self._minute, self._second, self._tz
def timezone(self):
"""Return the timezone in which the object is represented."""
return self._tz
def tzoffset(self):
"""Return the timezone offset for the objects timezone."""
return _tzoffset(self._tz, self._t)
def year(self):
"""Return the calendar year of the object."""
return self._year
def month(self):
"""Return the month of the object as an integer."""
return self._month
def Month(self):
"""Return the full month name."""
return self._fmon
def aMonth(self):
"""Return the abreviated month name."""
return self._amon
def Mon(self):
"""Compatibility: see aMonth."""
return self._amon
def pMonth(self):
"""Return the abreviated (with period) month name."""
return self._pmon
def Mon_(self):
"""Compatibility: see pMonth."""
return self._pmon
def day(self):
"""Return the integer day."""
return self._day
def Day(self):
"""Return the full name of the day of the week."""
return self._fday
def DayOfWeek(self):
"""Compatibility: see Day."""
return self._fday
def aDay(self):
"""Return the abreviated name of the day of the week."""
return self._aday
def pDay(self):
"""Return the abreviated (with period) name of the day of the week."""
return self._pday
def Day_(self):
"""Compatibility: see pDay."""
return self._pday
def dow(self):
"""Return the integer day of the week, where sunday is 0."""
return self._dayoffset
def dow_1(self):
"""Return the integer day of the week, where sunday is 1."""
return self._dayoffset+1
def h_12(self):
"""Return the 12-hour clock representation of the hour."""
return self._pmhour
def h_24(self):
"""Return the 24-hour clock representation of the hour."""
return self._hour
def ampm(self):
"""Return the appropriate time modifier (am or pm)."""
return self._pm
def hour(self):
"""Return the 24-hour clock representation of the hour."""
return self._hour
def minute(self):
"""Return the minute."""
return self._minute
def second(self):
"""Return the second."""
return self._second
def millis(self):
"""Return the millisecond since the epoch in GMT."""
try:
micros = self._micros
except AttributeError:
micros = self._upgrade_old()
return micros / 1000
def micros(self):
"""Return the microsecond since the epoch in GMT."""
try:
return self._micros
except AttributeError:
return self._upgrade_old()
def timezoneNaive(self):
"""The python datetime module introduces the idea of distinguishing
between timezone aware and timezone naive datetime values. For lossless
conversion to and from datetime.datetime record if we record this
information using True / False. DateTime makes no distinction, when we
don't have any information we return None here.
"""
try:
return self._timezone_naive
except AttributeError:
return None
def _upgrade_old(self):
"""Upgrades a previously pickled DateTime object."""
micros = long(math.floor(self._t * 1000000.0))
#self._micros = micros # don't upgrade instances in place
return micros
def strftime(self, format):
"""Format the date/time using the *current timezone representation*."""
x = _calcDependentSecond2(self._year, self._month, self._day,
self._hour, self._minute, self._second)
ltz = self._calcTimezoneName(x, 0)
tzdiff = _tzoffset(ltz, self._t) - _tzoffset(self._tz, self._t)
zself = self + tzdiff/86400.0
microseconds = int((zself._second - zself._nearsec) * 1000000)
# Note: in older versions strftime() accepted also unicode strings
# as format strings (just because time.strftime() did not perform
# any type checking). So we convert unicode strings to utf8,
# pass them to strftime and convert them back to unicode if necessary.
format_is_unicode = False
if isinstance(format, unicode):
format = format.encode('utf-8')
format_is_unicode = True
ds = datetime(zself._year, zself._month, zself._day, zself._hour,
zself._minute, int(zself._nearsec),
microseconds).strftime(format)
return format_is_unicode and unicode(ds, 'utf-8') or ds
# General formats from previous DateTime
def Date(self):
"""Return the date string for the object."""
return "%s/%2.2d/%2.2d" % (self._year, self._month, self._day)
def Time(self):
"""Return the time string for an object to the nearest second."""
return '%2.2d:%2.2d:%2.2d' % (self._hour,self._minute,self._nearsec)
def TimeMinutes(self):
"""Return the time string for an object not showing seconds."""
return '%2.2d:%2.2d' % (self._hour,self._minute)
def AMPM(self):
"""Return the time string for an object to the nearest second."""
return '%2.2d:%2.2d:%2.2d %s' % (
self._pmhour,self._minute,self._nearsec,self._pm)
def AMPMMinutes(self):
"""Return the time string for an object not showing seconds."""
return '%2.2d:%2.2d %s' % (self._pmhour,self._minute,self._pm)
def PreciseTime(self):
"""Return the time string for the object."""
return '%2.2d:%2.2d:%06.3f' % (self._hour,self._minute,self._second)
def PreciseAMPM(self):
"""Return the time string for the object."""
return '%2.2d:%2.2d:%06.3f %s' % (
self._pmhour,self._minute,self._second,self._pm)
def yy(self):
"""Return calendar year as a 2 digit string."""
return str(self._year)[-2:]
def mm(self):
"""Return month as a 2 digit string."""
return '%02d' % self._month
def dd(self):
"""Return day as a 2 digit string."""
return '%02d' % self._day
def rfc822(self):
"""Return the date in RFC 822 format."""
tzoffset = _tzoffset2rfc822zone(_tzoffset(self._tz, self._t))
return '%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s' % (
self._aday,self._day,self._amon,self._year,
self._hour,self._minute,self._nearsec,tzoffset)
# New formats
def fCommon(self):
"""Return a string representing the object\'s value
in the format: March 1, 1997 1:45 pm.
"""
return '%s %s, %4.4d %s:%2.2d %s' % (
self._fmon,self._day,self._year,self._pmhour,
self._minute,self._pm)
def fCommonZ(self):
"""Return a string representing the object\'s value
in the format: March 1, 1997 1:45 pm US/Eastern.
"""
return '%s %s, %4.4d %d:%2.2d %s %s' % (
self._fmon,self._day,self._year,self._pmhour,
self._minute,self._pm,self._tz)
def aCommon(self):
"""Return a string representing the object\'s value
in the format: Mar 1, 1997 1:45 pm.
"""
return '%s %s, %4.4d %s:%2.2d %s' % (
self._amon,self._day,self._year,self._pmhour,
self._minute,self._pm)
def aCommonZ(self):
"""Return a string representing the object\'s value
in the format: Mar 1, 1997 1:45 pm US/Eastern.
"""
return '%s %s, %4.4d %d:%2.2d %s %s' % (
self._amon,self._day,self._year,self._pmhour,
self._minute,self._pm,self._tz)
def pCommon(self):
"""Return a string representing the object\'s value
in the format: Mar. 1, 1997 1:45 pm.
"""
return '%s %s, %4.4d %s:%2.2d %s' % (
self._pmon,self._day,self._year,self._pmhour,
self._minute,self._pm)
def pCommonZ(self):
"""Return a string representing the object\'s value
in the format: Mar. 1, 1997 1:45 pm US/Eastern.
"""
return '%s %s, %4.4d %d:%2.2d %s %s' % (
self._pmon,self._day,self._year,self._pmhour,
self._minute,self._pm,self._tz)
def ISO(self):
"""Return the object in ISO standard format.
Note: this is *not* ISO 8601-format! See the ISO8601 and
HTML4 methods below for ISO 8601-compliant output.
Dates are output as: YYYY-MM-DD HH:MM:SS
"""
return "%.4d-%.2d-%.2d %.2d:%.2d:%.2d" % (
self._year, self._month, self._day,
self._hour, self._minute, self._second)
def ISO8601(self):
"""Return the object in ISO 8601-compatible format containing the
date, time with seconds-precision and the time zone identifier.
See: http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSTZD
T is a literal character.
TZD is Time Zone Designator, format +HH:MM or -HH:MM
If the instance is timezone naive (it was not specified with a timezone
when it was constructed) then the timezone is ommitted.
The HTML4 method below offers the same formatting, but converts
to UTC before returning the value and sets the TZD "Z".
"""
if self.timezoneNaive():
return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d" % (
self._year, self._month, self._day,
self._hour, self._minute, self._second)
tzoffset = _tzoffset2iso8601zone(_tzoffset(self._tz, self._t))
return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d%s" % (
self._year, self._month, self._day,
self._hour, self._minute, self._second, tzoffset)
def HTML4(self):
"""Return the object in the format used in the HTML4.0 specification,
one of the standard forms in ISO8601.
See: http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSZ
T, Z are literal characters.
The time is in UTC.
"""
newdate = self.toZone('UTC')
return "%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2dZ" % (
newdate._year, newdate._month, newdate._day,
newdate._hour, newdate._minute, newdate._second)
def asdatetime(self):
"""Return a standard libary datetime.datetime
"""
tznaive = self.timezoneNaive()
if tznaive:
tzinfo = None
else:
tzinfo = self._tzinfo[self._tz].tzinfo
second = int(self._second)
microsec = self.micros() % 1000000
dt = datetime(self._year, self._month, self._day, self._hour,
self._minute, second, microsec, tzinfo)
return dt
def utcdatetime(self):
"""Convert the time to UTC then return a timezone naive datetime object"""
utc = self.toZone('UTC')
second = int(utc._second)
microsec = utc.micros() % 1000000
dt = datetime(utc._year, utc._month, utc._day, utc._hour,
utc._minute, second, microsec)
return dt
def __add__(self,other):
"""A DateTime may be added to a number and a number may be
added to a DateTime; two DateTimes cannot be added.
"""
if hasattr(other,'_t'):
raise DateTimeError,'Cannot add two DateTimes'
o=float(other)
tz = self._tz
#t = (self._t + (o*86400.0))
omicros = round(o*86400000000)
tmicros = self.micros() + omicros
#d = (self._d + o)
t = tmicros / 1000000.0
d = (tmicros + long(EPOCH*1000000)) / 86400000000.0
s = d - math.floor(d)
ms = t - math.floor(t)
x = _calcDependentSecond(tz, t)
yr,mo,dy,hr,mn,sc = _calcYMDHMS(x, ms)
return self.__class__(yr,mo,dy,hr,mn,sc,self._tz,t,d,s, None, self.timezoneNaive())
__radd__=__add__
def __sub__(self,other):
"""Either a DateTime or a number may be subtracted from a
DateTime, however, a DateTime may not be subtracted from
a number.
"""
if hasattr(other, '_d'):
return (self.micros() - other.micros()) / 86400000000.0
else:
return self.__add__(-(other))
def __repr__(self):
"""Convert a DateTime to a string that looks like a Python
expression.
"""
return '%s(\'%s\')' % (self.__class__.__name__,str(self))
def __str__(self):
"""Convert a DateTime to a string."""
y,m,d = self._year,self._month,self._day
h,mn,s,t = self._hour,self._minute,self._second,self._tz
if h == mn == s == 0:
# hh:mm:ss all zero -- suppress the time.
return '%4.4d/%2.2d/%2.2d' % (y, m, d)
elif s == int(s):
# A whole number of seconds -- suppress milliseconds.
return '%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d %s' % (
y, m, d, h, mn, s, t)
else:
# s is already rounded to the nearest microsecond, and
# it's not a whole number of seconds. Be sure to print
# 2 digits before the decimal point.
return '%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%06.6f %s' % (
y, m, d, h, mn, s, t)
def __cmp__(self,obj):
"""Compare a DateTime with another DateTime object, or a
float such as those returned by time.time().
NOTE: __cmp__ support is provided for backward compatibility
only, and mixing DateTimes with ExtensionClasses could cause
__cmp__ to break.
You should use the methods lessThan, greaterThan, lessThanEqualTo,
greaterThanEqualTo, equalTo and notEqualTo to avoid potential
problems later!
"""
# Optimized for sorting speed.
try:
return cmp(self._micros, obj._micros)
except AttributeError:
try: self._micros
except AttributeError: self._upgrade_old()
return cmp(self._t,obj)
def __hash__(self):
"""Compute a hash value for a DateTime."""
return int(((self._year%100*12+self._month)*31+
self._day+self.time)*100)
def __int__(self):
"""Convert to an integer number of seconds since the epoch (gmt)."""
return int(self.micros() / 1000000)
def __long__(self):
"""Convert to a long-int number of seconds since the epoch (gmt)."""
return long(self.micros() / 1000000)
def __float__(self):
"""Convert to floating-point number of seconds since the epoch (gmt)."""
return float(self._t)
def _parse_iso8601(self,s):
# preserve the previously implied contract
# who know where this could be used...
return _parse_iso8601_preserving_tznaive(s)[:7]
def _parse_iso8601_preserving_tznaive(self,s):
try:
return self.__parse_iso8601(s)
except IndexError:
raise SyntaxError, (
'Not an ISO 8601 compliant date string: "%s"' % s)
def __parse_iso8601(self,s):
"""Parse an ISO 8601 compliant date.
See: http://en.wikipedia.org/wiki/ISO_8601
"""
month = day = week_day = 1
year = hour = minute = seconds = hour_off = min_off = 0
tznaive = True
iso8601 = iso8601Match(s.strip())
fields = iso8601 and iso8601.groupdict() or {}
if not iso8601 or fields.get('garbage'):
raise IndexError
if fields['year']:
year = int(fields['year'])
if fields['month']:
month = int(fields['month'])
if fields['day']:
day = int(fields['day'])
if fields['year_day']:
d = DateTime('%s-01-01' % year) + int(fields['year_day']) - 1
month = d.month()
day = d.day()
if fields['week']:
week = int(fields['week'])
if fields['week_day']:
week_day = int(fields['week_day'])
d = DateTime('%s-01-04' % year)
d = d - (d.dow()+6) % 7 + week * 7 + week_day - 8
month = d.month()
day = d.day()
if fields['hour']:
hour = int(fields['hour'])
if fields['minute']:
minute = int(fields['minute'])
elif fields['fraction']:
minute = 60.0 * float('0.%s' % fields['fraction'])
seconds, minute = math.modf(minute)
minute = int(minute)
seconds = 60.0 * seconds
# Avoid reprocess when handling seconds, bellow
fields['fraction'] = None
if fields['second']:
seconds = int(fields['second'])
if fields['fraction']:
seconds = seconds + float('0.%s' % fields['fraction'])
elif fields['fraction']:
seconds = 60.0 * float('0.%s' % fields['fraction'])
if fields['hour_off']:
hour_off = int(fields['hour_off'])
if fields['signal'] == '-':
hour_off *= -1
if fields['min_off']:
min_off = int(fields['min_off'])
if fields['signal'] or fields['Z']:
tznaive = False
else:
tznaive = True
# Differ from the specification here. To preserve backwards
# compatibility assume a default timezone == UTC.
tz = 'GMT%+03d%02d' % (hour_off, min_off)
return year, month, day, hour, minute, seconds, tz, tznaive
def JulianDay(self):
"""Return the Julian day.
See: http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
"""
a = (14 - self._month)/12 #integer division, discard remainder
y = self._year + 4800 - a
m = self._month + (12*a) - 3
return self._day + (153*m+2)/5 + 365*y + y/4 - y/100 + y/400 - 32045
def week(self):
"""Return the week number according to ISO.
See: http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
"""
J = self.JulianDay()
d4 = (J + 31741 - (J % 7)) % 146097 % 36524 % 1461
L = d4/1460
d1 = (( d4 - L) % 365) + L
return d1/7 + 1
def encode(self, out):
"""Encode value for XML-RPC."""
out.write('<value><dateTime.iso8601>')
out.write(self.ISO8601())
out.write('</dateTime.iso8601></value>\n')
class strftimeFormatter:
def __init__(self, dt, format):
self._dt=dt
self._f=format
def __call__(self):
return self._dt.strftime(self._f)
# Module methods
def Timezones():
"""Return the list of recognized timezone names"""
return sorted(list(PytzCache._zmap.values()))
The DateTime package
====================
Encapsulation of date/time values.
Function Timezones()
--------------------
Returns the list of recognized timezone names:
>>> from DateTime import Timezones
>>> zones = set(Timezones())
Almost all of the standard pytz timezones are included, with the exception
of some commonly-used but ambiguous abbreviations, where historical Zope
usage conflicts with the name used by pytz:
>>> import pytz
>>> [x for x in pytz.all_timezones if x not in zones]
['CET', 'EET', 'EST', 'MET', 'MST', 'WET']
Class DateTime
--------------
DateTime objects represent instants in time and provide interfaces for
controlling its representation without affecting the absolute value of
the object.
DateTime objects may be created from a wide variety of string or
numeric data, or may be computed from other DateTime objects.
DateTimes support the ability to convert their representations to many
major timezones, as well as the ablility to create a DateTime object
in the context of a given timezone.
DateTime objects provide partial numerical behavior:
* Two date-time objects can be subtracted to obtain a time, in days
between the two.
* A date-time object and a positive or negative number may be added to
obtain a new date-time object that is the given number of days later
than the input date-time object.
* A positive or negative number and a date-time object may be added to
obtain a new date-time object that is the given number of days later
than the input date-time object.
* A positive or negative number may be subtracted from a date-time
object to obtain a new date-time object that is the given number of
days earlier than the input date-time object.
DateTime objects may be converted to integer, long, or float numbers
of days since January 1, 1901, using the standard int, long, and float
functions (Compatibility Note: int, long and float return the number
of days since 1901 in GMT rather than local machine timezone).
DateTime objects also provide access to their value in a float format
usable with the python time module, provided that the value of the
object falls in the range of the epoch-based time module.
A DateTime object should be considered immutable; all conversion and numeric
operations return a new DateTime object rather than modify the current object.
A DateTime object always maintains its value as an absolute UTC time,
and is represented in the context of some timezone based on the
arguments used to create the object. A DateTime object's methods
return values based on the timezone context.
Note that in all cases the local machine timezone is used for
representation if no timezone is specified.
Constructor for DateTime
------------------------
DateTime() returns a new date-time object. DateTimes may be created
with from zero to seven arguments:
* If the function is called with no arguments, then the current date/
time is returned, represented in the timezone of the local machine.
* If the function is invoked with a single string argument which is a
recognized timezone name, an object representing the current time is
returned, represented in the specified timezone.
* If the function is invoked with a single string argument
representing a valid date/time, an object representing that date/
time will be returned.
As a general rule, any date-time representation that is recognized
and unambigous to a resident of North America is acceptable. (The
reason for this qualification is that in North America, a date like:
2/1/1994 is interpreted as February 1, 1994, while in some parts of
the world, it is interpreted as January 2, 1994.) A date/ time
string consists of two components, a date component and an optional
time component, separated by one or more spaces. If the time
component is omited, 12:00am is assumed. Any recognized timezone
name specified as the final element of the date/time string will be
used for computing the date/time value. (If you create a DateTime
with the string "Mar 9, 1997 1:45pm US/Pacific", the value will
essentially be the same as if you had captured time.time() at the
specified date and time on a machine in that timezone).
o Returns current date/time, represented in US/Eastern:
>>> from DateTime import DateTime
>>> e = DateTime('US/Eastern')
>>> e.timezone()
'US/Eastern'
o Returns specified time, represented in local machine zone:
>>> x = DateTime('1997/3/9 1:45pm')
>>> x.parts() # doctest: +ELLIPSIS
(1997, 3, 9, 13, 45, 0.0, ...)
o Specified time in local machine zone, verbose format:
>>> y = DateTime('Mar 9, 1997 13:45:00')
>>> y.parts() # doctest: +ELLIPSIS
(1997, 3, 9, 13, 45, 0.0, ...)
>>> y == x
True
The date component consists of year, month, and day values. The
year value must be a one-, two-, or four-digit integer. If a one-
or two-digit year is used, the year is assumed to be in the
twentieth century. The month may an integer, from 1 to 12, a month
name, or a month abreviation, where a period may optionally follow
the abreviation. The day must be an integer from 1 to the number of
days in the month. The year, month, and day values may be separated
by periods, hyphens, forward, shashes, or spaces. Extra spaces are
permitted around the delimiters. Year, month, and day values may be
given in any order as long as it is possible to distinguish the
components. If all three components are numbers that are less than
13, then a a month-day-year ordering is assumed.
The time component consists of hour, minute, and second values
separated by colons. The hour value must be an integer between 0
and 23 inclusively. The minute value must be an integer between 0
and 59 inclusively. The second value may be an integer value
between 0 and 59.999 inclusively. The second value or both the
minute and second values may be ommitted. The time may be followed
by am or pm in upper or lower case, in which case a 12-hour clock is
assumed.
* If the DateTime function is invoked with a single Numeric argument,
the number is assumed to be either a floating point value such as
that returned by time.time() , or a number of days after January 1,
1901 00:00:00 UTC.
A DateTime object is returned that represents either the gmt value
of the time.time() float represented in the local machine's
timezone, or that number of days after January 1, 1901. Note that
the number of days after 1901 need to be expressed from the
viewpoint of the local machine's timezone. A negative argument will
yield a date-time value before 1901.
* If the function is invoked with two numeric arguments, then the
first is taken to be an integer year and the second argument is
taken to be an offset in days from the beginning of the year, in the
context of the local machine timezone. The date-time value returned
is the given offset number of days from the beginning of the given
year, represented in the timezone of the local machine. The offset
may be positive or negative. Two-digit years are assumed to be in
the twentieth century.
* If the function is invoked with two arguments, the first a float
representing a number of seconds past the epoch in gmt (such as
those returned by time.time()) and the second a string naming a
recognized timezone, a DateTime with a value of that gmt time will
be returned, represented in the given timezone.
>>> import time
>>> t = time.time()
Time t represented as US/Eastern:
>>> now_east = DateTime(t, 'US/Eastern')
Time t represented as US/Pacific:
>>> now_west = DateTime(t, 'US/Pacific')
Only their representations are different:
>>> now_east == now_west
True
* If the function is invoked with three or more numeric arguments,
then the first is taken to be an integer year, the second is taken
to be an integer month, and the third is taken to be an integer day.
If the combination of values is not valid, then a DateTimeError is
raised. Two-digit years are assumed to be in the twentieth century.
The fourth, fifth, and sixth arguments are floating point, positive
or negative offsets in units of hours, minutes, and days, and
default to zero if not given. An optional string may be given as
the final argument to indicate timezone (the effect of this is as if
you had taken the value of time.time() at that time on a machine in
the specified timezone).
If a string argument passed to the DateTime constructor cannot be
parsed, it will raise DateTime.SyntaxError. Invalid date, time, or
timezone components will raise a DateTime.DateTimeError.
The module function Timezones() will return a list of the timezones
recognized by the DateTime module. Recognition of timezone names is
case-insensitive.
Instance Methods for DateTime (IDateTime interface)
---------------------------------------------------
Conversion and comparison methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ``timeTime()`` returns the date/time as a floating-point number in
UTC, in the format used by the python time module. Note that it is
possible to create date /time values with DateTime that have no
meaningful value to the time module, and in such cases a
DateTimeError is raised. A DateTime object's value must generally
be between Jan 1, 1970 (or your local machine epoch) and Jan 2038 to
produce a valid time.time() style value.
>>> dt = DateTime('Mar 9, 1997 13:45:00 US/Eastern')
>>> dt.timeTime()
857933100.0
>>> DateTime('2040/01/01 UTC').timeTime()
2208988800.0
>>> DateTime('1900/01/01 UTC').timeTime()
-2208988800.0
* ``toZone(z)`` returns a DateTime with the value as the current
object, represented in the indicated timezone:
>>> dt.toZone('UTC')
DateTime('1997/03/09 18:45:00 UTC')
>>> dt.toZone('UTC') == dt
True
* ``isFuture()`` returns true if this object represents a date/time
later than the time of the call:
>>> dt.isFuture()
False
>>> DateTime('Jan 1 3000').isFuture() # not time-machine safe!
True
* ``isPast()`` returns true if this object represents a date/time
earlier than the time of the call:
>>> dt.isPast()
True
>>> DateTime('Jan 1 3000').isPast() # not time-machine safe!
False
* ``isCurrentYear()`` returns true if this object represents a
date/time that falls within the current year, in the context of this
object's timezone representation:
>>> dt.isCurrentYear()
False
>>> DateTime().isCurrentYear()
True
* ``isCurrentMonth()`` returns true if this object represents a
date/time that falls within the current month, in the context of
this object's timezone representation:
>>> dt.isCurrentMonth()
False
>>> DateTime().isCurrentMonth()
True
* ``isCurrentDay()`` returns true if this object represents a
date/time that falls within the current day, in the context of this
object's timezone representation:
>>> dt.isCurrentDay()
False
>>> DateTime().isCurrentDay()
True
* ``isCurrentHour()`` returns true if this object represents a
date/time that falls within the current hour, in the context of this
object's timezone representation:
>>> dt.isCurrentHour()
False
>>> DateTime().isCurrentHour()
True
* ``isCurrentMinute()`` returns true if this object represents a
date/time that falls within the current minute, in the context of
this object's timezone representation:
>>> dt.isCurrentMinute()
False
>>> DateTime().isCurrentMinute()
True
* ``isLeapYear()`` returns true if the current year (in the context of
the object's timezone) is a leap year:
>>> dt.isLeapYear()
False
>>> DateTime('Mar 8 2004').isLeapYear()
True
* ``earliestTime()`` returns a new DateTime object that represents the
earliest possible time (in whole seconds) that still falls within
the current object's day, in the object's timezone context:
>>> dt.earliestTime()
DateTime('1997/03/09')
* ``latestTime()`` return a new DateTime object that represents the
latest possible time (in whole seconds) that still falls within the
current object's day, in the object's timezone context
>>> dt.latestTime()
DateTime('1997/03/09 23:59:59 US/Eastern')
Component access
~~~~~~~~~~~~~~~~
* ``parts()`` returns a tuple containing the calendar year, month,
day, hour, minute second and timezone of the object
>>> dt.parts()
(1997, 3, 9, 13, 45, 0.0, 'US/Eastern')
* ``timezone()`` returns the timezone in which the object is represented:
>>> dt.timezone() in Timezones()
True
* ``tzoffset()`` returns the timezone offset for the objects timezone:
>>> dt.tzoffset()
-18000
* ``year()`` returns the calendar year of the object:
>>> dt.year()
1997
* ``month()`` retursn the month of the object as an integer:
>>> dt.month()
3
* ``Month()`` returns the full month name:
>>> dt.Month()
'March'
* ``aMonth()`` returns the abreviated month name:
>>> dt.aMonth()
'Mar'
* ``pMonth()`` returns the abreviated (with period) month name:
>>> dt.pMonth()
'Mar.'
* ``day()`` returns the integer day:
>>> dt.day()
9
* ``Day()`` returns the full name of the day of the week:
>>> dt.Day()
'Sunday'
* ``dayOfYear()`` returns the day of the year, in context of the
timezone representation of the object:
>>> dt.dayOfYear()
68
* ``aDay()`` returns the abreviated name of the day of the week:
>>> dt.aDay()
'Sun'
* ``pDay()`` returns the abreviated (with period) name of the day of
the week:
>>> dt.pDay()
'Sun.'
* ``dow()`` returns the integer day of the week, where Sunday is 0:
>>> dt.dow()
0
* ``dow_1()`` returns the integer day of the week, where sunday is 1:
>>> dt.dow_1()
1
* ``h_12()`` returns the 12-hour clock representation of the hour:
>>> dt.h_12()
1
* ``h_24()`` returns the 24-hour clock representation of the hour:
>>> dt.h_24()
13
* ``ampm()`` returns the appropriate time modifier (am or pm):
>>> dt.ampm()
'pm'
* ``hour()`` returns the 24-hour clock representation of the hour:
>>> dt.hour()
13
* ``minute()`` returns the minute:
>>> dt.minute()
45
* ``second()`` returns the second:
>>> dt.second()
0.0
* ``millis()`` returns the milliseconds since the epoch in GMT.
>>> dt.millis()
857933100000L
strftime()
~~~~~~~~~~
See ``tests/testDateTime.py``.
General formats from previous DateTime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ``Date()`` return the date string for the object:
>>> dt.Date()
'1997/03/09'
* ``Time()`` returns the time string for an object to the nearest
second:
>>> dt.Time()
'13:45:00'
* ``TimeMinutes()`` returns the time string for an object not showing
seconds:
>>> dt.TimeMinutes()
'13:45'
* ``AMPM()`` returns the time string for an object to the nearest second:
>>> dt.AMPM()
'01:45:00 pm'
* ``AMPMMinutes()`` returns the time string for an object not showing
seconds:
>>> dt.AMPMMinutes()
'01:45 pm'
* ``PreciseTime()`` returns the time string for the object:
>>> dt.PreciseTime()
'13:45:00.000'
* ``PreciseAMPM()`` returns the time string for the object:
>>> dt.PreciseAMPM()
'01:45:00.000 pm'
* ``yy()`` returns the calendar year as a 2 digit string
>>> dt.yy()
'97'
* ``mm()`` returns the month as a 2 digit string
>>> dt.mm()
'03'
* ``dd()`` returns the day as a 2 digit string:
>>> dt.dd()
'09'
* ``rfc822()`` returns the date in RFC 822 format:
>>> dt.rfc822()
'Sun, 09 Mar 1997 13:45:00 -0500'
New formats
~~~~~~~~~~~
* ``fCommon()`` returns a string representing the object's value in
the format: March 9, 1997 1:45 pm:
>>> dt.fCommon()
'March 9, 1997 1:45 pm'
* ``fCommonZ()`` returns a string representing the object's value in
the format: March 9, 1997 1:45 pm US/Eastern:
>>> dt.fCommonZ()
'March 9, 1997 1:45 pm US/Eastern'
* ``aCommon()`` returns a string representing the object's value in
the format: Mar 9, 1997 1:45 pm:
>>> dt.aCommon()
'Mar 9, 1997 1:45 pm'
* ``aCommonZ()`` return a string representing the object's value in
the format: Mar 9, 1997 1:45 pm US/Eastern:
>>> dt.aCommonZ()
'Mar 9, 1997 1:45 pm US/Eastern'
* ``pCommon()`` returns a string representing the object's value in
the format Mar. 9, 1997 1:45 pm:
>>> dt.pCommon()
'Mar. 9, 1997 1:45 pm'
* ``pCommonZ()`` returns a string representing the object's value in
the format: Mar. 9, 1997 1:45 pm US/Eastern:
>>> dt.pCommonZ()
'Mar. 9, 1997 1:45 pm US/Eastern'
* ``ISO()`` returns a string with the date/time in ISO format. Note:
this is not ISO 8601-format! See the ISO8601 and HTML4 methods below
for ISO 8601-compliant output. Dates are output as: YYYY-MM-DD HH:MM:SS
>>> dt.ISO()
'1997-03-09 13:45:00'
* ``ISO8601()`` returns the object in ISO 8601-compatible format
containing the date, time with seconds-precision and the time zone
identifier - see http://www.w3.org/TR/NOTE-datetime. Dates are
output as: YYYY-MM-DDTHH:MM:SSTZD (T is a literal character, TZD is
Time Zone Designator, format +HH:MM or -HH:MM).
The ``HTML4()`` method below offers the same formatting, but
converts to UTC before returning the value and sets the TZD"Z"
>>> dt.ISO8601()
'1997-03-09T13:45:00-05:00'
* ``HTML4()`` returns the object in the format used in the HTML4.0
specification, one of the standard forms in ISO8601. See
http://www.w3.org/TR/NOTE-datetime. Dates are output as:
YYYY-MM-DDTHH:MM:SSZ (T, Z are literal characters, the time is in
UTC.):
>>> dt.HTML4()
'1997-03-09T18:45:00Z'
* ``JulianDay()`` returns the Julian day according to
http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
>>> dt.JulianDay()
2450517
* ``week()`` returns the week number according to ISO
see http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
>>> dt.week()
10
Deprecated API
~~~~~~~~~~~~~~
* DayOfWeek(): see Day()
* Day_(): see pDay()
* Mon(): see aMonth()
* Mon_(): see pMonth
General Services Provided by DateTime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DateTimes can be repr()'ed; the result will be a string indicating how
to make a DateTime object like this:
>>> `dt`
"DateTime('1997/03/09 13:45:00 US/Eastern')"
When we convert them into a string, we get a nicer string that could
actually be shown to a user:
>>> str(dt)
'1997/03/09 13:45:00 US/Eastern'
The hash value of a DateTime is based on the date and time and is
equal for different representations of the DateTime:
>>> hash(dt)
3618678
>>> hash(dt.toZone('UTC'))
3618678
A DateTime can be compared with another DateTime or float via
``cmp()``. NOTE: __cmp__ support is provided for backward
compatibility only, and mixing DateTimes with ExtensionClasses could
cause __cmp__ to break. You should use the methods lessThan,
greaterThan, lessThanEqualTo, greaterThanEqualTo, equalTo and
notEqualTo to avoid potential problems later!
>>> cmp(dt, dt)
0
>>> cmp(dt, dt.toZone('UTC'))
0
>>> cmp(dt, dt.timeTime())
0
>>> cmp(dt, DateTime('2000/01/01'))
-1
>>> cmp(dt, DateTime('1900/01/01'))
1
DateTime objects can be compared to other DateTime objects OR floating
point numbers such as the ones which are returned by the python time
module. On comparison for equality, True is returned if the object
represents a date/time equal to the specified DateTime or time module
style time:
>>> dt == dt
True
>>> dt == dt.toZone('UTC')
True
>>> dt == dt.timeTime()
True
>>> dt == DateTime()
False
>>> dt.equalTo(dt)
True
>>> dt.equalTo(dt.toZone('UTC'))
True
>>> dt.equalTo(dt.timeTime())
True
>>> dt.equalTo(DateTime())
False
Same goes for inequalities:
>>> dt != dt
False
>>> dt != dt.toZone('UTC')
False
>>> dt != dt.timeTime()
False
>>> dt != DateTime()
True
>>> dt.notEqualTo(dt)
False
>>> dt.notEqualTo(dt.toZone('UTC'))
False
>>> dt.notEqualTo(dt.timeTime())
False
>>> dt.notEqualTo(DateTime())
True
>>> dt > dt
False
>>> DateTime() > dt
True
>>> dt > DateTime().timeTime()
False
>>> DateTime().timeTime() > dt
True
>>> dt.greaterThan(dt)
False
>>> DateTime().greaterThan(dt)
True
>>> dt.greaterThan(DateTime().timeTime())
False
>>> dt >= dt
True
>>> DateTime() >= dt
True
>>> dt >= DateTime().timeTime()
False
>>> DateTime().timeTime() >= dt
True
>>> dt.greaterThanEqualTo(dt)
True
>>> DateTime().greaterThanEqualTo(dt)
True
>>> dt.greaterThanEqualTo(DateTime().timeTime())
False
>>> dt < dt
False
>>> DateTime() < dt
False
>>> dt < DateTime().timeTime()
True
>>> DateTime().timeTime() < dt
False
>>> dt.lessThan(dt)
False
>>> DateTime().lessThan(dt)
False
>>> dt.lessThan(DateTime().timeTime())
True
>>> dt <= dt
True
>>> DateTime() <= dt
False
>>> dt <= DateTime().timeTime()
True
>>> DateTime().timeTime() <= dt
False
>>> dt.lessThanEqualTo(dt)
True
>>> DateTime().lessThanEqualTo(dt)
False
>>> dt.lessThanEqualTo(DateTime().timeTime())
True
Numeric Services Provided by DateTime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A DateTime may be added to a number and a number may be added to a
DateTime:
>>> dt + 5
DateTime('1997/03/14 13:45:00 US/Eastern')
>>> 5 + dt
DateTime('1997/03/14 13:45:00 US/Eastern')
Two DateTimes cannot be added:
>>> dt + dt
Traceback (most recent call last):
...
DateTimeError: Cannot add two DateTimes
Either a DateTime or a number may be subtracted from a DateTime,
however, a DateTime may not be subtracted from a number:
>>> DateTime('1997/03/10 13:45 US/Eastern') - dt
1.0
>>> dt - 1
DateTime('1997/03/08 13:45:00 US/Eastern')
>>> 1 - dt
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for -: 'int' and 'instance'
DateTimes can also be converted to integers (number of seconds since
the epoch), longs (not too long ;)) and floats:
>>> int(dt)
857933100
>>> long(dt)
857933100L
>>> float(dt)
857933100.0
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
# This data is used only for testing legacy compatibility with pytz
_data={
'GMT': ('GMT', 0, 1, [], '', [(0, 0, 0)], 'GMT\000'),
'GMT+0': ('GMT+0', 0, 1, [], '', [(0, 0, 0)], 'GMT+0000\000'),
'GMT+1': ('GMT+1', 0, 1, [], '', [(3600, 0, 0)], 'GMT+0100\000'),
'GMT+2': ('GMT+2', 0, 1, [], '', [(7200, 0, 0)], 'GMT+0200\000'),
'GMT+3': ('GMT+3', 0, 1, [], '', [(10800, 0, 0)], 'GMT+0300\000'),
'GMT+4': ('GMT+4', 0, 1, [], '', [(14400, 0, 0)], 'GMT+0400\000'),
'GMT+5': ('GMT+5', 0, 1, [], '', [(18000, 0, 0)], 'GMT+0500\000'),
'GMT+6': ('GMT+6', 0, 1, [], '', [(21600, 0, 0)], 'GMT+0600\000'),
'GMT+7': ('GMT+7', 0, 1, [], '', [(25200, 0, 0)], 'GMT+0700\000'),
'GMT+8': ('GMT+8', 0, 1, [], '', [(28800, 0, 0)], 'GMT+0800\000'),
'GMT+9': ('GMT+9', 0, 1, [], '', [(32400, 0, 0)], 'GMT+0900\000'),
'GMT+10': ('GMT+10', 0, 1, [], '', [(36000, 0, 0)], 'GMT+1000\000'),
'GMT+11': ('GMT+11', 0, 1, [], '', [(39600, 0, 0)], 'GMT+1100\000'),
'GMT+12': ('GMT+12', 0, 1, [], '', [(43200, 0, 0)], 'GMT+1200\000'),
'GMT+13': ('GMT+13', 0, 1, [], '', [(46800, 0, 0)], 'GMT+1300\000'),
'GMT-1': ('GMT-1', 0, 1, [], '', [(-3600, 0, 0)], 'GMT-0100\000'),
'GMT-2': ('GMT-2', 0, 1, [], '', [(-7200, 0, 0)], 'GMT-0200\000'),
'GMT-3': ('GMT-3', 0, 1, [], '', [(-10800, 0, 0)], 'GMT-0300\000'),
'GMT-4': ('GMT-4', 0, 1, [], '', [(-14400, 0, 0)], 'GMT-0400\000'),
'GMT-5': ('GMT-5', 0, 1, [], '', [(-18000, 0, 0)], 'GMT-0500\000'),
'GMT-6': ('GMT-6', 0, 1, [], '', [(-21600, 0, 0)], 'GMT-0600\000'),
'GMT-7': ('GMT-7', 0, 1, [], '', [(-25200, 0, 0)], 'GMT-0700\000'),
'GMT-8': ('GMT-8', 0, 1, [], '', [(-28800, 0, 0)], 'GMT-0800\000'),
'GMT-9': ('GMT-9', 0, 1, [], '', [(-32400, 0, 0)], 'GMT-0900\000'),
'GMT-10': ('GMT-10', 0, 1, [], '', [(-36000, 0, 0)], 'GMT-1000\000'),
'GMT-11': ('GMT-11', 0, 1, [], '', [(-39600, 0, 0)], 'GMT-1100\000'),
'GMT-12': ('GMT-12', 0, 1, [], '', [(-43200, 0, 0)], 'GMT-1200\000'),
'GMT+0130': ('GMT+0130', 0, 1, [], '', [(5400, 0, 0)], 'GMT+0130\000'),
'GMT+0230': ('GMT+0230', 0, 1, [], '', [(9000, 0, 0)], 'GMT+0230\000'),
'GMT+0330': ('GMT+0330', 0, 1, [], '', [(12600, 0, 0)], 'GMT+0330\000'),
'GMT+0430': ('GMT+0430', 0, 1, [], '', [(16200, 0, 0)], 'GMT+0430\000'),
'GMT+0530': ('GMT+0530', 0, 1, [], '', [(19800, 0, 0)], 'GMT+0530\000'),
'GMT+0630': ('GMT+0630', 0, 1, [], '', [(23400, 0, 0)], 'GMT+0630\000'),
'GMT+0730': ('GMT+0730', 0, 1, [], '', [(27000, 0, 0)], 'GMT+0730\000'),
'GMT+0830': ('GMT+0830', 0, 1, [], '', [(30600, 0, 0)], 'GMT+0830\000'),
'GMT+0930': ('GMT+0930', 0, 1, [], '', [(34200, 0, 0)], 'GMT+0930\000'),
'GMT+1030': ('GMT+1030', 0, 1, [], '', [(37800, 0, 0)], 'GMT+1030\000'),
'GMT+1130': ('GMT+1130', 0, 1, [], '', [(41400, 0, 0)], 'GMT+1130\000'),
'GMT+1230': ('GMT+1230', 0, 1, [], '', [(45000, 0, 0)], 'GMT+1230\000'),
'GMT-0130': ('GMT-0130', 0, 1, [], '', [(-5400, 0, 0)], 'GMT-0130\000'),
'GMT-0230': ('GMT-0230', 0, 1, [], '', [(-9000, 0, 0)], 'GMT-0230\000'),
'GMT-0330': ('GMT-0330', 0, 1, [], '', [(-12600, 0, 0)], 'GMT-0330\000'),
'GMT-0430': ('GMT-0430', 0, 1, [], '', [(-16200, 0, 0)], 'GMT-0430\000'),
'GMT-0530': ('GMT-0530', 0, 1, [], '', [(-19800, 0, 0)], 'GMT-0530\000'),
'GMT-0630': ('GMT-0630', 0, 1, [], '', [(-23400, 0, 0)], 'GMT-0630\000'),
'GMT-0730': ('GMT-0730', 0, 1, [], '', [(-27000, 0, 0)], 'GMT-0730\000'),
'GMT-0830': ('GMT-0830', 0, 1, [], '', [(-30600, 0, 0)], 'GMT-0830\000'),
'GMT-0930': ('GMT-0930', 0, 1, [], '', [(-34200, 0, 0)], 'GMT-0930\000'),
'GMT-1030': ('GMT-1030', 0, 1, [], '', [(-37800, 0, 0)], 'GMT-1030\000'),
'GMT-1130': ('GMT-1130', 0, 1, [], '', [(-41400, 0, 0)], 'GMT-1130\000'),
'GMT-1230': ('GMT-1230', 0, 1, [], '', [(-45000, 0, 0)], 'GMT-1230\000'),
'US/Indiana-Starke': ('US/Indiana-Starke', 56, 4, [-1633276800, -1615136400, -1601827200, -1583686800, -880214400, -765392400, -84384000, -68662800, -52934400, -37213200, -21484800, -5763600, 9964800, 25686000, 41414400, 57740400, 73468800, 89190000, 104918400, 120639600, 126691200, 152089200, 162374400, 183538800, 199267200, 215593200, 230716800, 247042800, 262771200, 278492400, 294220800, 309942000, 325670400, 341391600, 357120000, 372841200, 388569600, 404895600, 420019200, 436345200, 452073600, 467794800, 483523200, 499244400, 514972800, 530694000, 544608000, 562143600, 576057600, 594198000, 607507200, 625647600, 638956800, 657097200, 671011200, 688546800], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\003', [(-18000, 1, 0), (-21600, 0, 4), (-18000, 1, 8), (-18000, 0, 12)], 'CDT\000CST\000CWT\000EST\000'), 'Japan': ('Japan', 0, 1, [], '', [(32400, 0, 0)], 'JST\000'), 'Cuba': ('Cuba', 118, 2, [290581200, 308721600, 322030800, 340171200, 358318800, 371620800, 389768400, 403070400, 421218000, 434520000, 453272400, 466574400, 484722000, 498024000, 516171600, 529473600, 547621200, 560923200, 579070800, 592372800, 611125200, 623822400, 642574800, 655876800, 674024400, 687326400, 705474000, 718776000, 736923600, 750225600, 768373200, 781675200, 800427600, 813124800, 831877200, 845179200, 863326800, 876628800, 894776400, 908078400, 926226000, 939528000, 958280400, 970977600, 989730000, 1003032000, 1021179600, 1034481600, 1052629200, 1065931200, 1084078800, 1097380800, 1115528400, 1128830400, 1147582800, 1160280000, 1179032400, 1192334400, 1210482000, 1223784000, 1241931600, 1255233600, 1273381200, 1286683200, 1304830800, 1318132800, 1336885200, 1350187200, 1368334800, 1381636800, 1399784400, 1413086400, 1431234000, 1444536000, 1462683600, 1475985600, 1494738000, 1507435200, 1526187600, 1539489600, 1557637200, 1570939200, 1589086800, 1602388800, 1620536400, 1633838400, 1651986000, 1665288000, 1684040400, 1696737600, 1715490000, 1728792000, 1746939600, 1760241600, 1778389200, 1791691200, 1809838800, 1823140800, 1841893200, 1854590400, 1873342800, 1886644800, 1904792400, 1918094400, 1936242000, 1949544000, 1967691600, 1980993600, 1999141200, 2012443200, 2031195600, 2043892800, 2062645200, 2075947200, 2094094800, 2107396800, 2125544400, 2138846400], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 1, 0), (-18000, 0, 4)], 'CDT\000CST\000'), 'Singapore': ('Singapore', 0, 1, [], '', [(28800, 0, 0)], 'SST\000'), 'Chile/Continental': ('Chile/Continental', 121, 2, [245217600, 258519600, 276667200, 289969200, 308721600, 321418800, 340171200, 352868400, 371620800, 384922800, 403070400, 416372400, 434520000, 447822000, 466574400, 479271600, 498024000, 510721200, 529473600, 542170800, 560923200, 574225200, 592372800, 605674800, 623822400, 637124400, 655876800, 668574000, 687326400, 700023600, 718776000, 732078000, 750225600, 763527600, 781675200, 794977200, 813124800, 826426800, 845179200, 857876400, 876628800, 889326000, 908078400, 921380400, 939528000, 952830000, 970977600, 984279600, 1003032000, 1015729200, 1034481600, 1047178800, 1065931200, 1079233200, 1097380800, 1110682800, 1128830400, 1142132400, 1160280000, 1173582000, 1192334400, 1205031600, 1223784000, 1236481200, 1255233600, 1268535600, 1286683200, 1299985200, 1318132800, 1331434800, 1350187200, 1362884400, 1381636800, 1394334000, 1413086400, 1425783600, 1444536000, 1457838000, 1475985600, 1489287600, 1507435200, 1520737200, 1539489600, 1552186800, 1570939200, 1583636400, 1602388800, 1615690800, 1633838400, 1647140400, 1665288000, 1678590000, 1696737600, 1710039600, 1728792000, 1741489200, 1760241600, 1772938800, 1791691200, 1804993200, 1823140800, 1836442800, 1854590400, 1867892400, 1886644800, 1899342000, 1918094400, 1930791600, 1949544000, 1962846000, 1980993600, 1994295600, 2012443200, 2025745200, 2043892800, 2057194800, 2075947200, 2088644400, 2107396800, 2120094000, 2138846400], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000', [(-10800, 1, 0), (-14400, 0, 4)], 'CDT\000CST\000'), 'Brazil/West': ('Brazil/West', 101, 2, [561967200, 571640400, 593416800, 603090000, 625557600, 634539600, 656920800, 665989200, 688370400, 697438800, 719820000, 729493200, 751269600, 760942800, 782719200, 792392400, 814860000, 823842000, 846223200, 855291600, 877672800, 887432400, 909122400, 918795600, 940572000, 950245200, 972712800, 981694800, 1004076000, 1013144400, 1035525600, 1044594000, 1066975200, 1076734800, 1098424800, 1108098000, 1129874400, 1139547600, 1162015200, 1170997200, 1193378400, 1202446800, 1224828000, 1234587600, 1256277600, 1265950800, 1287727200, 1297400400, 1319176800, 1328850000, 1351231200, 1360299600, 1382680800, 1391749200, 1414130400, 1423890000, 1445580000, 1455253200, 1477029600, 1486702800, 1509170400, 1518152400, 1540533600, 1549602000, 1571983200, 1581051600, 1603432800, 1613106000, 1634882400, 1644555600, 1666332000, 1676005200, 1698472800, 1707454800, 1729836000, 1738904400, 1761285600, 1771045200, 1792735200, 1802408400, 1824184800, 1833858000, 1856325600, 1865307600, 1887688800, 1896757200, 1919138400, 1928206800, 1950588000, 1960347600, 1982037600, 1991710800, 2013487200, 2023160400, 2045628000, 2054610000, 2076991200, 2086059600, 2108440800, 2118200400, 2139890400], '\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 0, 0), (-10800, 1, 4)], 'WST\000WDT\000'), 'Mexico/BajaSur': ('Mexico/BajaSur', 0, 1, [], '', [(-25200, 0, 0)], 'MST\000'), 'Israel': ('Israel', 42, 2, [609890400, 622587600, 640735200, 653432400, 670975200, 683672400, 704239200, 716936400, 735084000, 747781200, 765324000, 778021200, 798588000, 811285200, 829432800, 842130000, 862696800, 875394000, 892936800, 905634000, 923781600, 936478800, 957045600, 969742800, 987285600, 999982800, 1018130400, 1030827600, 1051394400, 1064091600, 1082239200, 1094936400, 1114898400, 1127595600, 1145743200, 1158440400, 1176588000, 1189285200, 1209247200, 1221944400, 1240092000, 1252789200], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(10800, 1, 0), (7200, 0, 4)], 'IDT\000IST\000'), 'Canada/Newfoundland': ('Canada/Newfoundland', 138, 2, [-21493800, -5772600, 9955800, 25677000, 41405400, 57731400, 73459800, 89181000, 104909400, 120630600, 136359000, 152080200, 167808600, 183529800, 199258200, 215584200, 230707800, 247033800, 262762200, 278483400, 294211800, 309933000, 325661400, 341382600, 357111000, 372832200, 388560600, 404886600, 420010200, 436336200, 452064600, 467785800, 483514200, 499235400, 514963800, 530685000, 544599000, 562134600, 576048600, 594189000, 607498200, 625638600, 638947800, 657088200, 671002200, 688537800, 702451800, 719987400, 733901400, 752041800, 765351000, 783491400, 796800600, 814941000, 828855000, 846390600, 860304600, 877840200, 891754200, 909289800, 923203800, 941344200, 954653400, 972793800, 986103000, 1004243400, 1018157400, 1035693000, 1049607000, 1067142600, 1081056600, 1099197000, 1112506200, 1130646600, 1143955800, 1162096200, 1175405400, 1193545800, 1207459800, 1224995400, 1238909400, 1256445000, 1270359000, 1288499400, 1301808600, 1319949000, 1333258200, 1351398600, 1365312600, 1382848200, 1396762200, 1414297800, 1428211800, 1445747400, 1459661400, 1477801800, 1491111000, 1509251400, 1522560600, 1540701000, 1554615000, 1572150600, 1586064600, 1603600200, 1617514200, 1635654600, 1648963800, 1667104200, 1680413400, 1698553800, 1712467800, 1730003400, 1743917400, 1761453000, 1775367000, 1792902600, 1806816600, 1824957000, 1838266200, 1856406600, 1869715800, 1887856200, 1901770200, 1919305800, 1933219800, 1950755400, 1964669400, 1982809800, 1996119000, 2014259400, 2027568600, 2045709000, 2059018200, 2077158600, 2091072600, 2108608200, 2122522200, 2140057800], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-9000, 1, 0), (-12600, 0, 4)], 'NDT\000NST\000'), 'GB-Eire': ('GB-Eire', 241, 4, [-1697238000, -1680476400, -1664146800, -1650150000, -1633906800, -1617490800, -1601852400, -1586041200, -1570402800, -1552172400, -1538348400, -1522537200, -1507503600, -1490569200, -1473634800, -1458342000, -1441321200, -1428879600, -1410735600, -1396220400, -1379286000, -1364770800, -1347836400, -1333321200, -1316386800, -1301266800, -1284332400, -1269817200, -1252882800, -1238367600, -1221433200, -1206918000, -1189983600, -1175468400, -1158534000, -1144018800, -1127084400, -1111964400, -1095030000, -1080514800, -1063580400, -1049065200, -1032130800, -1017615600, -1000681200, -986166000, -969231600, -950482800, -942015600, -904518000, -896050800, -875487600, -864601200, -844038000, -832546800, -812588400, -798073200, -781052400, -772066800, -764809200, -748479600, -733359600, -719449200, -717030000, -706748400, -699490800, -687999600, -668041200, -654735600, -636591600, -622076400, -605746800, -590626800, -574297200, -558572400, -542242800, -527122800, -512607600, -496278000, -481158000, -464223600, -449708400, -432774000, -417654000, -401324400, -386204400, -369270000, -354754800, -337820400, -323305200, -306975600, -291855600, -276735600, -257986800, -245286000, -226537200, -213231600, -195087600, -182386800, -163638000, -150937200, -132188400, -119487600, -100738800, -88038000, -68684400, -59007600, -37238400, 57715200, 69814800, 89168400, 101264400, 120618000, 132714000, 152067600, 164163600, 183517200, 196218000, 214966800, 227667600, 246416400, 259117200, 278470800, 290566800, 309920400, 322016400, 341370000, 354675600, 372819600, 386125200, 404269200, 417574800, 435718800, 449024400, 467773200, 481078800, 499222800, 512528400, 530672400, 543978000, 562122000, 575427600, 593571600, 606877200, 625626000, 638326800, 657075600, 670381200, 688525200, 701830800, 719974800, 733280400, 751424400, 764730000, 782874000, 796179600, 814928400, 828234000, 846378000, 859683600, 877827600, 891133200, 909277200, 922582800, 940726800, 954032400, 972781200, 985482000, 1004230800, 1017536400, 1035680400, 1048986000, 1067130000, 1080435600, 1098579600, 1111885200, 1130029200, 1143334800, 1162083600, 1174784400, 1193533200, 1206838800, 1224982800, 1238288400, 1256432400, 1269738000, 1287882000, 1301187600, 1319331600, 1332637200, 1351386000, 1364691600, 1382835600, 1396141200, 1414285200, 1427590800, 1445734800, 1459040400, 1477184400, 1490490000, 1509238800, 1521939600, 1540688400, 1553994000, 1572138000, 1585443600, 1603587600, 1616893200, 1635037200, 1648342800, 1666486800, 1679792400, 1698541200, 1711846800, 1729990800, 1743296400, 1761440400, 1774746000, 1792890000, 1806195600, 1824339600, 1837645200, 1856394000, 1869094800, 1887843600, 1901149200, 1919293200, 1932598800, 1950742800, 1964048400, 1982192400, 1995498000, 2013642000, 2026947600, 2045696400, 2058397200, 2077146000, 2090451600, 2108595600, 2121901200, 2140045200], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\002\000\002\000\002\000\002\000\002\000\001\000\001\000\002\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\003\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(3600, 1, 0), (0, 0, 4), (7200, 1, 8), (3600, 0, 0)], 'BST\000GMT\000DST\000'), 'Hongkong': ('Hongkong', 0, 1, [], '', [(28800, 0, 0)], 'HKT\000'), 'Turkey': ('Turkey', 104, 2, [512517600, 528238800, 543967200, 559688400, 575416800, 591138000, 606866400, 622587600, 638316000, 654642000, 670370400, 686091600, 701820000, 717541200, 733269600, 748990800, 764719200, 780440400, 796168800, 811890000, 828223200, 843944400, 859672800, 875394000, 891122400, 906843600, 922572000, 938293200, 954021600, 969742800, 985471200, 1001797200, 1017525600, 1033246800, 1048975200, 1064696400, 1080424800, 1096146000, 1111874400, 1127595600, 1143324000, 1159045200, 1174773600, 1191099600, 1206828000, 1222549200, 1238277600, 1253998800, 1269727200, 1285448400, 1301176800, 1316898000, 1332626400, 1348952400, 1364680800, 1380402000, 1396130400, 1411851600, 1427580000, 1443301200, 1459029600, 1474750800, 1490479200, 1506200400, 1521928800, 1538254800, 1553983200, 1569704400, 1585432800, 1601154000, 1616882400, 1632603600, 1648332000, 1664053200, 1679781600, 1695502800, 1711836000, 1727557200, 1743285600, 1759006800, 1774735200, 1790456400, 1806184800, 1821906000, 1837634400, 1853355600, 1869084000, 1885410000, 1901138400, 1916859600, 1932588000, 1948309200, 1964037600, 1979758800, 1995487200, 2011208400, 2026936800, 2042658000, 2058386400, 2074712400, 2090440800, 2106162000, 2121890400, 2137611600], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(14400, 1, 0), (10800, 0, 8)], 'EET DST\000EET\000'), 'US/Samoa': ('US/Samoa', 2, 3, [-86878800, 439038000], '\001\002', [(-39600, 0, 0), (-39600, 0, 4), (-39600, 0, 8)], 'NST\000BST\000SST\000'), 'Iran': ('Iran', 100, 2, [575418600, 590535000, 606868200, 621984600, 638317800, 653434200, 670372200, 684883800, 701821800, 716938200, 733271400, 748387800, 764721000, 779837400, 796170600, 811287000, 828225000, 842736600, 859674600, 874791000, 891124200, 906240600, 922573800, 937690200, 954023400, 969139800, 985473000, 1000589400, 1017527400, 1032039000, 1048977000, 1064093400, 1080426600, 1095543000, 1111876200, 1126992600, 1143325800, 1158442200, 1174775400, 1189891800, 1206829800, 1221946200, 1238279400, 1253395800, 1269729000, 1284845400, 1301178600, 1316295000, 1332628200, 1347744600, 1364682600, 1379194200, 1396132200, 1411248600, 1427581800, 1442698200, 1459031400, 1474147800, 1490481000, 1505597400, 1521930600, 1537047000, 1553985000, 1568496600, 1585434600, 1600551000, 1616884200, 1632000600, 1648333800, 1663450200, 1679783400, 1694899800, 1711837800, 1726349400, 1743287400, 1758403800, 1774737000, 1789853400, 1806186600, 1821303000, 1837636200, 1852752600, 1869085800, 1884202200, 1901140200, 1915651800, 1932589800, 1947706200, 1964039400, 1979155800, 1995489000, 2010605400, 2026938600, 2042055000, 2058388200, 2073504600, 2090442600, 2105559000, 2121892200, 2137008600], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(16200, 1, 0), (12600, 0, 4)], 'IDT\000IST\000'), 'US/Pacific': ('US/Pacific', 148, 3, [-1633269600, -1615129200, -1601820000, -1583679600, -880207200, -765385200, -84376800, -68655600, -52927200, -37206000, -21477600, -5756400, 9972000, 25693200, 41421600, 57747600, 73476000, 89197200, 104925600, 120646800, 126698400, 152096400, 162381600, 183546000, 199274400, 215600400, 230724000, 247050000, 262778400, 278499600, 294228000, 309949200, 325677600, 341398800, 357127200, 372848400, 388576800, 404902800, 420026400, 436352400, 452080800, 467802000, 483530400, 499251600, 514980000, 530701200, 544615200, 562150800, 576064800, 594205200, 607514400, 625654800, 638964000, 657104400, 671018400, 688554000, 702468000, 720003600, 733917600, 752058000, 765367200, 783507600, 796816800, 814957200, 828871200, 846406800, 860320800, 877856400, 891770400, 909306000, 923220000, 941360400, 954669600, 972810000, 986119200, 1004259600, 1018173600, 1035709200, 1049623200, 1067158800, 1081072800, 1099213200, 1112522400, 1130662800, 1143972000, 1162112400, 1175421600, 1193562000, 1207476000, 1225011600, 1238925600, 1256461200, 1270375200, 1288515600, 1301824800, 1319965200, 1333274400, 1351414800, 1365328800, 1382864400, 1396778400, 1414314000, 1428228000, 1445763600, 1459677600, 1477818000, 1491127200, 1509267600, 1522576800, 1540717200, 1554631200, 1572166800, 1586080800, 1603616400, 1617530400, 1635670800, 1648980000, 1667120400, 1680429600, 1698570000, 1712484000, 1730019600, 1743933600, 1761469200, 1775383200, 1792918800, 1806832800, 1824973200, 1838282400, 1856422800, 1869732000, 1887872400, 1901786400, 1919322000, 1933236000, 1950771600, 1964685600, 1982826000, 1996135200, 2014275600, 2027584800, 2045725200, 2059034400, 2077174800, 2091088800, 2108624400, 2122538400, 2140074000], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-25200, 1, 0), (-28800, 0, 4), (-25200, 1, 8)], 'PDT\000PST\000PWT\000'), 'Brazil/East': ('Brazil/East', 101, 2, [561963600, 571636800, 593413200, 603086400, 625554000, 634536000, 656917200, 665985600, 688366800, 697435200, 719816400, 729489600, 751266000, 760939200, 782715600, 792388800, 814856400, 823838400, 846219600, 855288000, 877669200, 887428800, 909118800, 918792000, 940568400, 950241600, 972709200, 981691200, 1004072400, 1013140800, 1035522000, 1044590400, 1066971600, 1076731200, 1098421200, 1108094400, 1129870800, 1139544000, 1162011600, 1170993600, 1193374800, 1202443200, 1224824400, 1234584000, 1256274000, 1265947200, 1287723600, 1297396800, 1319173200, 1328846400, 1351227600, 1360296000, 1382677200, 1391745600, 1414126800, 1423886400, 1445576400, 1455249600, 1477026000, 1486699200, 1509166800, 1518148800, 1540530000, 1549598400, 1571979600, 1581048000, 1603429200, 1613102400, 1634878800, 1644552000, 1666328400, 1676001600, 1698469200, 1707451200, 1729832400, 1738900800, 1761282000, 1771041600, 1792731600, 1802404800, 1824181200, 1833854400, 1856322000, 1865304000, 1887685200, 1896753600, 1919134800, 1928203200, 1950584400, 1960344000, 1982034000, 1991707200, 2013483600, 2023156800, 2045624400, 2054606400, 2076987600, 2086056000, 2108437200, 2118196800, 2139886800], '\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-10800, 0, 0), (-7200, 1, 4)], 'EST\000EDT\000'), 'Chile/EasterIsland': ('Chile/EasterIsland', 121, 2, [245224800, 258526800, 276674400, 289976400, 308728800, 321426000, 340178400, 352875600, 371628000, 384930000, 403077600, 416379600, 434527200, 447829200, 466581600, 479278800, 498031200, 510728400, 529480800, 542178000, 560930400, 574232400, 592380000, 605682000, 623829600, 637131600, 655884000, 668581200, 687333600, 700030800, 718783200, 732085200, 750232800, 763534800, 781682400, 794984400, 813132000, 826434000, 845186400, 857883600, 876636000, 889333200, 908085600, 921387600, 939535200, 952837200, 970984800, 984286800, 1003039200, 1015736400, 1034488800, 1047186000, 1065938400, 1079240400, 1097388000, 1110690000, 1128837600, 1142139600, 1160287200, 1173589200, 1192341600, 1205038800, 1223791200, 1236488400, 1255240800, 1268542800, 1286690400, 1299992400, 1318140000, 1331442000, 1350194400, 1362891600, 1381644000, 1394341200, 1413093600, 1425790800, 1444543200, 1457845200, 1475992800, 1489294800, 1507442400, 1520744400, 1539496800, 1552194000, 1570946400, 1583643600, 1602396000, 1615698000, 1633845600, 1647147600, 1665295200, 1678597200, 1696744800, 1710046800, 1728799200, 1741496400, 1760248800, 1772946000, 1791698400, 1805000400, 1823148000, 1836450000, 1854597600, 1867899600, 1886652000, 1899349200, 1918101600, 1930798800, 1949551200, 1962853200, 1981000800, 1994302800, 2012450400, 2025752400, 2043900000, 2057202000, 2075954400, 2088651600, 2107404000, 2120101200, 2138853600], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000', [(-18000, 1, 0), (-21600, 0, 4)], 'EDT\000EST\000'), 'Brazil/DeNoronha': ('Brazil/DeNoronha', 101, 2, [561960000, 571633200, 593409600, 603082800, 625550400, 634532400, 656913600, 665982000, 688363200, 697431600, 719812800, 729486000, 751262400, 760935600, 782712000, 792385200, 814852800, 823834800, 846216000, 855284400, 877665600, 887425200, 909115200, 918788400, 940564800, 950238000, 972705600, 981687600, 1004068800, 1013137200, 1035518400, 1044586800, 1066968000, 1076727600, 1098417600, 1108090800, 1129867200, 1139540400, 1162008000, 1170990000, 1193371200, 1202439600, 1224820800, 1234580400, 1256270400, 1265943600, 1287720000, 1297393200, 1319169600, 1328842800, 1351224000, 1360292400, 1382673600, 1391742000, 1414123200, 1423882800, 1445572800, 1455246000, 1477022400, 1486695600, 1509163200, 1518145200, 1540526400, 1549594800, 1571976000, 1581044400, 1603425600, 1613098800, 1634875200, 1644548400, 1666324800, 1675998000, 1698465600, 1707447600, 1729828800, 1738897200, 1761278400, 1771038000, 1792728000, 1802401200, 1824177600, 1833850800, 1856318400, 1865300400, 1887681600, 1896750000, 1919131200, 1928199600, 1950580800, 1960340400, 1982030400, 1991703600, 2013480000, 2023153200, 2045620800, 2054602800, 2076984000, 2086052400, 2108433600, 2118193200, 2139883200], '\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-7200, 0, 0), (-3600, 1, 4)], 'FST\000FDT\000'), 'US/Aleutian': ('US/Aleutian', 149, 5, [-1633262400, -1615122000, -1601812800, -1583672400, -880200000, -765378000, -84369600, -68648400, -52920000, -37198800, -21470400, -5749200, 9979200, 25700400, 41428800, 57754800, 73483200, 89204400, 104932800, 120654000, 126705600, 152103600, 162388800, 183553200, 199281600, 215607600, 230731200, 247057200, 262785600, 278506800, 294235200, 309956400, 325684800, 341406000, 357134400, 372855600, 388584000, 404910000, 420033600, 436359600, 439034400, 452088000, 467809200, 483537600, 499258800, 514987200, 530708400, 544622400, 562158000, 576072000, 594212400, 607521600, 625662000, 638971200, 657111600, 671025600, 688561200, 702475200, 720010800, 733924800, 752065200, 765374400, 783514800, 796824000, 814964400, 828878400, 846414000, 860328000, 877863600, 891777600, 909313200, 923227200, 941367600, 954676800, 972817200, 986126400, 1004266800, 1018180800, 1035716400, 1049630400, 1067166000, 1081080000, 1099220400, 1112529600, 1130670000, 1143979200, 1162119600, 1175428800, 1193569200, 1207483200, 1225018800, 1238932800, 1256468400, 1270382400, 1288522800, 1301832000, 1319972400, 1333281600, 1351422000, 1365336000, 1382871600, 1396785600, 1414321200, 1428235200, 1445770800, 1459684800, 1477825200, 1491134400, 1509274800, 1522584000, 1540724400, 1554638400, 1572174000, 1586088000, 1603623600, 1617537600, 1635678000, 1648987200, 1667127600, 1680436800, 1698577200, 1712491200, 1730026800, 1743940800, 1761476400, 1775390400, 1792926000, 1806840000, 1824980400, 1838289600, 1856430000, 1869739200, 1887879600, 1901793600, 1919329200, 1933243200, 1950778800, 1964692800, 1982833200, 1996142400, 2014282800, 2027592000, 2045732400, 2059041600, 2077182000, 2091096000, 2108631600, 2122545600, 2140081200], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003\004\003', [(-32400, 1, 0), (-36000, 0, 5), (-32400, 1, 10), (-36000, 0, 15), (-32400, 1, 20)], 'AHDT\000AHST\000AHWT\000HAST\000HADT\000'), 'Canada/Atlantic': ('Canada/Atlantic', 138, 2, [-21492000, -5770800, 9957600, 25678800, 41407200, 57733200, 73461600, 89182800, 104911200, 120632400, 136360800, 152082000, 167810400, 183531600, 199260000, 215586000, 230709600, 247035600, 262764000, 278485200, 294213600, 309934800, 325663200, 341384400, 357112800, 372834000, 388562400, 404888400, 420012000, 436338000, 452066400, 467787600, 483516000, 499237200, 514965600, 530686800, 544600800, 562136400, 576050400, 594190800, 607500000, 625640400, 638949600, 657090000, 671004000, 688539600, 702453600, 719989200, 733903200, 752043600, 765352800, 783493200, 796802400, 814942800, 828856800, 846392400, 860306400, 877842000, 891756000, 909291600, 923205600, 941346000, 954655200, 972795600, 986104800, 1004245200, 1018159200, 1035694800, 1049608800, 1067144400, 1081058400, 1099198800, 1112508000, 1130648400, 1143957600, 1162098000, 1175407200, 1193547600, 1207461600, 1224997200, 1238911200, 1256446800, 1270360800, 1288501200, 1301810400, 1319950800, 1333260000, 1351400400, 1365314400, 1382850000, 1396764000, 1414299600, 1428213600, 1445749200, 1459663200, 1477803600, 1491112800, 1509253200, 1522562400, 1540702800, 1554616800, 1572152400, 1586066400, 1603602000, 1617516000, 1635656400, 1648965600, 1667106000, 1680415200, 1698555600, 1712469600, 1730005200, 1743919200, 1761454800, 1775368800, 1792904400, 1806818400, 1824958800, 1838268000, 1856408400, 1869717600, 1887858000, 1901772000, 1919307600, 1933221600, 1950757200, 1964671200, 1982811600, 1996120800, 2014261200, 2027570400, 2045710800, 2059020000, 2077160400, 2091074400, 2108610000, 2122524000, 2140059600], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-10800, 1, 0), (-14400, 0, 4)], 'ADT\000AST\000'), 'Mexico/General': ('Mexico/General', 0, 1, [], '', [(-21600, 0, 0)], 'CST\000'), 'Greenwich': ('Greenwich', 0, 1, [], '', [(0, 0, 0)], 'GMT\000'), 'Egypt': ('Egypt', 152, 2, [-305164800, -291949200, -273628800, -260413200, -242092800, -228877200, -210556800, -197341200, -178934400, -165718800, -147398400, -134182800, -115862400, -102646800, -84326400, -71110800, -52704000, -39488400, -21168000, -7952400, 10368000, 23583600, 41904000, 55119600, 73526400, 86742000, 105062400, 118278000, 136598400, 149814000, 168134400, 181350000, 199756800, 212972400, 231292800, 244508400, 262828800, 276044400, 294364800, 307580400, 325987200, 339202800, 420595200, 433810800, 452217600, 465433200, 483753600, 496969200, 515289600, 528505200, 546825600, 560041200, 578448000, 591663600, 609984000, 623199600, 641520000, 654735600, 673056000, 686271600, 704678400, 717894000, 736214400, 749430000, 767750400, 780966000, 799286400, 812502000, 830908800, 844124400, 862444800, 875660400, 893980800, 907196400, 925516800, 938732400, 957139200, 970354800, 988675200, 1001890800, 1020211200, 1033426800, 1051747200, 1064962800, 1083369600, 1096585200, 1114905600, 1128121200, 1146441600, 1159657200, 1177977600, 1191193200, 1209600000, 1222815600, 1241136000, 1254351600, 1272672000, 1285887600, 1304208000, 1317423600, 1335830400, 1349046000, 1367366400, 1380582000, 1398902400, 1412118000, 1430438400, 1443654000, 1462060800, 1475276400, 1493596800, 1506812400, 1525132800, 1538348400, 1556668800, 1569884400, 1588291200, 1601506800, 1619827200, 1633042800, 1651363200, 1664578800, 1682899200, 1696114800, 1714521600, 1727737200, 1746057600, 1759273200, 1777593600, 1790809200, 1809129600, 1822345200, 1840752000, 1853967600, 1872288000, 1885503600, 1903824000, 1917039600, 1935360000, 1948575600, 1966982400, 1980198000, 1998518400, 2011734000, 2030054400, 2043270000, 2061590400, 2074806000, 2093212800, 2106428400, 2124748800, 2137964400], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(10800, 1, 0), (7200, 0, 8)], 'EET DST\000EET\000'), 'US/Eastern': ('US/Eastern', 148, 3, [-1633280400, -1615140000, -1601830800, -1583690400, -880218000, -765396000, -84387600, -68666400, -52938000, -37216800, -21488400, -5767200, 9961200, 25682400, 41410800, 57736800, 73465200, 89186400, 104914800, 120636000, 126687600, 152085600, 162370800, 183535200, 199263600, 215589600, 230713200, 247039200, 262767600, 278488800, 294217200, 309938400, 325666800, 341388000, 357116400, 372837600, 388566000, 404892000, 420015600, 436341600, 452070000, 467791200, 483519600, 499240800, 514969200, 530690400, 544604400, 562140000, 576054000, 594194400, 607503600, 625644000, 638953200, 657093600, 671007600, 688543200, 702457200, 719992800, 733906800, 752047200, 765356400, 783496800, 796806000, 814946400, 828860400, 846396000, 860310000, 877845600, 891759600, 909295200, 923209200, 941349600, 954658800, 972799200, 986108400, 1004248800, 1018162800, 1035698400, 1049612400, 1067148000, 1081062000, 1099202400, 1112511600, 1130652000, 1143961200, 1162101600, 1175410800, 1193551200, 1207465200, 1225000800, 1238914800, 1256450400, 1270364400, 1288504800, 1301814000, 1319954400, 1333263600, 1351404000, 1365318000, 1382853600, 1396767600, 1414303200, 1428217200, 1445752800, 1459666800, 1477807200, 1491116400, 1509256800, 1522566000, 1540706400, 1554620400, 1572156000, 1586070000, 1603605600, 1617519600, 1635660000, 1648969200, 1667109600, 1680418800, 1698559200, 1712473200, 1730008800, 1743922800, 1761458400, 1775372400, 1792908000, 1806822000, 1824962400, 1838271600, 1856412000, 1869721200, 1887861600, 1901775600, 1919311200, 1933225200, 1950760800, 1964674800, 1982815200, 1996124400, 2014264800, 2027574000, 2045714400, 2059023600, 2077164000, 2091078000, 2108613600, 2122527600, 2140063200], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 1, 0), (-18000, 0, 4), (-14400, 1, 8)], 'EDT\000EST\000EWT\000'), 'Brazil/Acre': ('Brazil/Acre', 101, 2, [561970800, 571644000, 593420400, 603093600, 625561200, 634543200, 656924400, 665992800, 688374000, 697442400, 719823600, 729496800, 751273200, 760946400, 782722800, 792396000, 814863600, 823845600, 846226800, 855295200, 877676400, 887436000, 909126000, 918799200, 940575600, 950248800, 972716400, 981698400, 1004079600, 1013148000, 1035529200, 1044597600, 1066978800, 1076738400, 1098428400, 1108101600, 1129878000, 1139551200, 1162018800, 1171000800, 1193382000, 1202450400, 1224831600, 1234591200, 1256281200, 1265954400, 1287730800, 1297404000, 1319180400, 1328853600, 1351234800, 1360303200, 1382684400, 1391752800, 1414134000, 1423893600, 1445583600, 1455256800, 1477033200, 1486706400, 1509174000, 1518156000, 1540537200, 1549605600, 1571986800, 1581055200, 1603436400, 1613109600, 1634886000, 1644559200, 1666335600, 1676008800, 1698476400, 1707458400, 1729839600, 1738908000, 1761289200, 1771048800, 1792738800, 1802412000, 1824188400, 1833861600, 1856329200, 1865311200, 1887692400, 1896760800, 1919142000, 1928210400, 1950591600, 1960351200, 1982041200, 1991714400, 2013490800, 2023164000, 2045631600, 2054613600, 2076994800, 2086063200, 2108444400, 2118204000, 2139894000], '\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-18000, 0, 0), (-14400, 1, 4)], 'AST\000ADT\000'), 'US/Mountain': ('US/Mountain', 148, 3, [-1633273200, -1615132800, -1601823600, -1583683200, -880210800, -765388800, -84380400, -68659200, -52930800, -37209600, -21481200, -5760000, 9968400, 25689600, 41418000, 57744000, 73472400, 89193600, 104922000, 120643200, 126694800, 152092800, 162378000, 183542400, 199270800, 215596800, 230720400, 247046400, 262774800, 278496000, 294224400, 309945600, 325674000, 341395200, 357123600, 372844800, 388573200, 404899200, 420022800, 436348800, 452077200, 467798400, 483526800, 499248000, 514976400, 530697600, 544611600, 562147200, 576061200, 594201600, 607510800, 625651200, 638960400, 657100800, 671014800, 688550400, 702464400, 720000000, 733914000, 752054400, 765363600, 783504000, 796813200, 814953600, 828867600, 846403200, 860317200, 877852800, 891766800, 909302400, 923216400, 941356800, 954666000, 972806400, 986115600, 1004256000, 1018170000, 1035705600, 1049619600, 1067155200, 1081069200, 1099209600, 1112518800, 1130659200, 1143968400, 1162108800, 1175418000, 1193558400, 1207472400, 1225008000, 1238922000, 1256457600, 1270371600, 1288512000, 1301821200, 1319961600, 1333270800, 1351411200, 1365325200, 1382860800, 1396774800, 1414310400, 1428224400, 1445760000, 1459674000, 1477814400, 1491123600, 1509264000, 1522573200, 1540713600, 1554627600, 1572163200, 1586077200, 1603612800, 1617526800, 1635667200, 1648976400, 1667116800, 1680426000, 1698566400, 1712480400, 1730016000, 1743930000, 1761465600, 1775379600, 1792915200, 1806829200, 1824969600, 1838278800, 1856419200, 1869728400, 1887868800, 1901782800, 1919318400, 1933232400, 1950768000, 1964682000, 1982822400, 1996131600, 2014272000, 2027581200, 2045721600, 2059030800, 2077171200, 2091085200, 2108620800, 2122534800, 2140070400], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-21600, 1, 0), (-25200, 0, 4), (-21600, 1, 8)], 'MDT\000MST\000MWT\000'), 'US/Central': ('US/Central', 148, 3, [-1633276800, -1615136400, -1601827200, -1583686800, -880214400, -765392400, -84384000, -68662800, -52934400, -37213200, -21484800, -5763600, 9964800, 25686000, 41414400, 57740400, 73468800, 89190000, 104918400, 120639600, 126691200, 152089200, 162374400, 183538800, 199267200, 215593200, 230716800, 247042800, 262771200, 278492400, 294220800, 309942000, 325670400, 341391600, 357120000, 372841200, 388569600, 404895600, 420019200, 436345200, 452073600, 467794800, 483523200, 499244400, 514972800, 530694000, 544608000, 562143600, 576057600, 594198000, 607507200, 625647600, 638956800, 657097200, 671011200, 688546800, 702460800, 719996400, 733910400, 752050800, 765360000, 783500400, 796809600, 814950000, 828864000, 846399600, 860313600, 877849200, 891763200, 909298800, 923212800, 941353200, 954662400, 972802800, 986112000, 1004252400, 1018166400, 1035702000, 1049616000, 1067151600, 1081065600, 1099206000, 1112515200, 1130655600, 1143964800, 1162105200, 1175414400, 1193554800, 1207468800, 1225004400, 1238918400, 1256454000, 1270368000, 1288508400, 1301817600, 1319958000, 1333267200, 1351407600, 1365321600, 1382857200, 1396771200, 1414306800, 1428220800, 1445756400, 1459670400, 1477810800, 1491120000, 1509260400, 1522569600, 1540710000, 1554624000, 1572159600, 1586073600, 1603609200, 1617523200, 1635663600, 1648972800, 1667113200, 1680422400, 1698562800, 1712476800, 1730012400, 1743926400, 1761462000, 1775376000, 1792911600, 1806825600, 1824966000, 1838275200, 1856415600, 1869724800, 1887865200, 1901779200, 1919314800, 1933228800, 1950764400, 1964678400, 1982818800, 1996128000, 2014268400, 2027577600, 2045718000, 2059027200, 2077167600, 2091081600, 2108617200, 2122531200, 2140066800], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-18000, 1, 0), (-21600, 0, 4), (-18000, 1, 8)], 'CDT\000CST\000CWT\000'), 'US/Hawaii': ('US/Hawaii', 9, 4, [-1633260600, -1615120200, -1601811000, -1583670600, -1157283000, -1157200200, -880198200, -765376200, -712150200], '\000\001\000\001\000\001\002\001\003', [(-34200, 1, 0), (-37800, 0, 4), (-34200, 1, 8), (-36000, 0, 4)], 'HDT\000HST\000HWT\000'), 'US/Arizona': ('US/Arizona', 6, 3, [-1633273200, -1615132800, -1601823600, -1583683200, -880210800, -765388800], '\000\001\000\001\002\001', [(-21600, 1, 0), (-25200, 0, 4), (-21600, 1, 8)], 'MDT\000MST\000MWT\000'), 'Jamaica': ('Jamaica', 148, 3, [-1633280400, -1615140000, -1601830800, -1583690400, -880218000, -765396000, -84387600, -68666400, -52938000, -37216800, -21488400, -5767200, 9961200, 25682400, 41410800, 57736800, 73465200, 89186400, 104914800, 120636000, 126687600, 152085600, 162370800, 183535200, 199263600, 215589600, 230713200, 247039200, 262767600, 278488800, 294217200, 309938400, 325666800, 341388000, 357116400, 372837600, 388566000, 404892000, 420015600, 436341600, 452070000, 467791200, 483519600, 499240800, 514969200, 530690400, 544604400, 562140000, 576054000, 594194400, 607503600, 625644000, 638953200, 657093600, 671007600, 688543200, 702457200, 719992800, 733906800, 752047200, 765356400, 783496800, 796806000, 814946400, 828860400, 846396000, 860310000, 877845600, 891759600, 909295200, 923209200, 941349600, 954658800, 972799200, 986108400, 1004248800, 1018162800, 1035698400, 1049612400, 1067148000, 1081062000, 1099202400, 1112511600, 1130652000, 1143961200, 1162101600, 1175410800, 1193551200, 1207465200, 1225000800, 1238914800, 1256450400, 1270364400, 1288504800, 1301814000, 1319954400, 1333263600, 1351404000, 1365318000, 1382853600, 1396767600, 1414303200, 1428217200, 1445752800, 1459666800, 1477807200, 1491116400, 1509256800, 1522566000, 1540706400, 1554620400, 1572156000, 1586070000, 1603605600, 1617519600, 1635660000, 1648969200, 1667109600, 1680418800, 1698559200, 1712473200, 1730008800, 1743922800, 1761458400, 1775372400, 1792908000, 1806822000, 1824962400, 1838271600, 1856412000, 1869721200, 1887861600, 1901775600, 1919311200, 1933225200, 1950760800, 1964674800, 1982815200, 1996124400, 2014264800, 2027574000, 2045714400, 2059023600, 2077164000, 2091078000, 2108613600, 2122527600, 2140063200], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 1, 0), (-18000, 0, 4), (-14400, 1, 8)], 'EDT\000EST\000EWT\000'), 'Poland': ('Poland', 104, 2, [512524800, 528249600, 543974400, 559699200, 575424000, 591148800, 606873600, 622598400, 638323200, 654652800, 670377600, 686102400, 701827200, 717552000, 733276800, 749001600, 764726400, 780451200, 796176000, 811900800, 828230400, 843955200, 859680000, 875404800, 891129600, 906854400, 922579200, 938304000, 954028800, 969753600, 985478400, 1001808000, 1017532800, 1033257600, 1048982400, 1064707200, 1080432000, 1096156800, 1111881600, 1127606400, 1143331200, 1159056000, 1174780800, 1191110400, 1206835200, 1222560000, 1238284800, 1254009600, 1269734400, 1285459200, 1301184000, 1316908800, 1332633600, 1348963200, 1364688000, 1380412800, 1396137600, 1411862400, 1427587200, 1443312000, 1459036800, 1474761600, 1490486400, 1506211200, 1521936000, 1538265600, 1553990400, 1569715200, 1585440000, 1601164800, 1616889600, 1632614400, 1648339200, 1664064000, 1679788800, 1695513600, 1711843200, 1727568000, 1743292800, 1759017600, 1774742400, 1790467200, 1806192000, 1821916800, 1837641600, 1853366400, 1869091200, 1885420800, 1901145600, 1916870400, 1932595200, 1948320000, 1964044800, 1979769600, 1995494400, 2011219200, 2026944000, 2042668800, 2058393600, 2074723200, 2090448000, 2106172800, 2121897600, 2137622400], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(7200, 1, 0), (3600, 0, 8)], 'MET DST\000MET\000'), 'Canada/East-Saskatchewan': ('Canada/East-Saskatchewan', 0, 1, [], '', [(-21600, 0, 0)], 'CST\000'), 'US/Alaska': ('US/Alaska', 148, 3, [-1633266000, -1615125600, -1601816400, -1583676000, -880203600, -765381600, -84373200, -68652000, -52923600, -37202400, -21474000, -5752800, 9975600, 25696800, 41425200, 57751200, 73479600, 89200800, 104929200, 120650400, 126702000, 152100000, 162385200, 183549600, 199278000, 215604000, 230727600, 247053600, 262782000, 278503200, 294231600, 309952800, 325681200, 341402400, 357130800, 372852000, 388580400, 404906400, 420030000, 436356000, 452084400, 467805600, 483534000, 499255200, 514983600, 530704800, 544618800, 562154400, 576068400, 594208800, 607518000, 625658400, 638967600, 657108000, 671022000, 688557600, 702471600, 720007200, 733921200, 752061600, 765370800, 783511200, 796820400, 814960800, 828874800, 846410400, 860324400, 877860000, 891774000, 909309600, 923223600, 941364000, 954673200, 972813600, 986122800, 1004263200, 1018177200, 1035712800, 1049626800, 1067162400, 1081076400, 1099216800, 1112526000, 1130666400, 1143975600, 1162116000, 1175425200, 1193565600, 1207479600, 1225015200, 1238929200, 1256464800, 1270378800, 1288519200, 1301828400, 1319968800, 1333278000, 1351418400, 1365332400, 1382868000, 1396782000, 1414317600, 1428231600, 1445767200, 1459681200, 1477821600, 1491130800, 1509271200, 1522580400, 1540720800, 1554634800, 1572170400, 1586084400, 1603620000, 1617534000, 1635674400, 1648983600, 1667124000, 1680433200, 1698573600, 1712487600, 1730023200, 1743937200, 1761472800, 1775386800, 1792922400, 1806836400, 1824976800, 1838286000, 1856426400, 1869735600, 1887876000, 1901790000, 1919325600, 1933239600, 1950775200, 1964689200, 1982829600, 1996138800, 2014279200, 2027588400, 2045728800, 2059038000, 2077178400, 2091092400, 2108628000, 2122542000, 2140077600], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-28800, 1, 0), (-32400, 0, 5), (-28800, 1, 10)], 'AKDT\000AKST\000AKWT\000'), 'Canada/Mountain': ('Canada/Mountain', 138, 2, [-21481200, -5760000, 9968400, 25689600, 41418000, 57744000, 73472400, 89193600, 104922000, 120643200, 136371600, 152092800, 167821200, 183542400, 199270800, 215596800, 230720400, 247046400, 262774800, 278496000, 294224400, 309945600, 325674000, 341395200, 357123600, 372844800, 388573200, 404899200, 420022800, 436348800, 452077200, 467798400, 483526800, 499248000, 514976400, 530697600, 544611600, 562147200, 576061200, 594201600, 607510800, 625651200, 638960400, 657100800, 671014800, 688550400, 702464400, 720000000, 733914000, 752054400, 765363600, 783504000, 796813200, 814953600, 828867600, 846403200, 860317200, 877852800, 891766800, 909302400, 923216400, 941356800, 954666000, 972806400, 986115600, 1004256000, 1018170000, 1035705600, 1049619600, 1067155200, 1081069200, 1099209600, 1112518800, 1130659200, 1143968400, 1162108800, 1175418000, 1193558400, 1207472400, 1225008000, 1238922000, 1256457600, 1270371600, 1288512000, 1301821200, 1319961600, 1333270800, 1351411200, 1365325200, 1382860800, 1396774800, 1414310400, 1428224400, 1445760000, 1459674000, 1477814400, 1491123600, 1509264000, 1522573200, 1540713600, 1554627600, 1572163200, 1586077200, 1603612800, 1617526800, 1635667200, 1648976400, 1667116800, 1680426000, 1698566400, 1712480400, 1730016000, 1743930000, 1761465600, 1775379600, 1792915200, 1806829200, 1824969600, 1838278800, 1856419200, 1869728400, 1887868800, 1901782800, 1919318400, 1933232400, 1950768000, 1964682000, 1982822400, 1996131600, 2014272000, 2027581200, 2045721600, 2059030800, 2077171200, 2091085200, 2108620800, 2122534800, 2140070400], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-21600, 1, 0), (-25200, 0, 4)], 'MDT\000MST\000'), 'Universal': ('Universal', 0, 1, [], '', [(0, 0, 0)], 'GMT\000'), 'US/East-Indiana': ('US/East-Indiana', 6, 3, [-1633280400, -1615140000, -1601830800, -1583690400, -880218000, -765396000], '\000\001\000\001\002\001', [(-14400, 1, 0), (-18000, 0, 4), (-14400, 1, 8)], 'EDT\000EST\000EWT\000'), 'Canada/Yukon': ('Canada/Yukon', 138, 2, [-21474000, -5752800, 9975600, 25696800, 41425200, 57751200, 73479600, 89200800, 104929200, 120650400, 136378800, 152100000, 167828400, 183549600, 199278000, 215604000, 230727600, 247053600, 262782000, 278503200, 294231600, 309952800, 325681200, 341402400, 357130800, 372852000, 388580400, 404906400, 420030000, 436356000, 452084400, 467805600, 483534000, 499255200, 514983600, 530704800, 544618800, 562154400, 576068400, 594208800, 607518000, 625658400, 638967600, 657108000, 671022000, 688557600, 702471600, 720007200, 733921200, 752061600, 765370800, 783511200, 796820400, 814960800, 828874800, 846410400, 860324400, 877860000, 891774000, 909309600, 923223600, 941364000, 954673200, 972813600, 986122800, 1004263200, 1018177200, 1035712800, 1049626800, 1067162400, 1081076400, 1099216800, 1112526000, 1130666400, 1143975600, 1162116000, 1175425200, 1193565600, 1207479600, 1225015200, 1238929200, 1256464800, 1270378800, 1288519200, 1301828400, 1319968800, 1333278000, 1351418400, 1365332400, 1382868000, 1396782000, 1414317600, 1428231600, 1445767200, 1459681200, 1477821600, 1491130800, 1509271200, 1522580400, 1540720800, 1554634800, 1572170400, 1586084400, 1603620000, 1617534000, 1635674400, 1648983600, 1667124000, 1680433200, 1698573600, 1712487600, 1730023200, 1743937200, 1761472800, 1775386800, 1792922400, 1806836400, 1824976800, 1838286000, 1856426400, 1869735600, 1887876000, 1901790000, 1919325600, 1933239600, 1950775200, 1964689200, 1982829600, 1996138800, 2014279200, 2027588400, 2045728800, 2059038000, 2077178400, 2091092400, 2108628000, 2122542000, 2140077600], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-28800, 1, 0), (-32400, 0, 4)], 'YDT\000YST\000'), 'Iceland': ('Iceland', 0, 1, [], '', [(0, 0, 0)], 'WET\000'), 'Canada/Eastern': ('Canada/Eastern', 138, 2, [-21488400, -5767200, 9961200, 25682400, 41410800, 57736800, 73465200, 89186400, 104914800, 120636000, 136364400, 152085600, 167814000, 183535200, 199263600, 215589600, 230713200, 247039200, 262767600, 278488800, 294217200, 309938400, 325666800, 341388000, 357116400, 372837600, 388566000, 404892000, 420015600, 436341600, 452070000, 467791200, 483519600, 499240800, 514969200, 530690400, 544604400, 562140000, 576054000, 594194400, 607503600, 625644000, 638953200, 657093600, 671007600, 688543200, 702457200, 719992800, 733906800, 752047200, 765356400, 783496800, 796806000, 814946400, 828860400, 846396000, 860310000, 877845600, 891759600, 909295200, 923209200, 941349600, 954658800, 972799200, 986108400, 1004248800, 1018162800, 1035698400, 1049612400, 1067148000, 1081062000, 1099202400, 1112511600, 1130652000, 1143961200, 1162101600, 1175410800, 1193551200, 1207465200, 1225000800, 1238914800, 1256450400, 1270364400, 1288504800, 1301814000, 1319954400, 1333263600, 1351404000, 1365318000, 1382853600, 1396767600, 1414303200, 1428217200, 1445752800, 1459666800, 1477807200, 1491116400, 1509256800, 1522566000, 1540706400, 1554620400, 1572156000, 1586070000, 1603605600, 1617519600, 1635660000, 1648969200, 1667109600, 1680418800, 1698559200, 1712473200, 1730008800, 1743922800, 1761458400, 1775372400, 1792908000, 1806822000, 1824962400, 1838271600, 1856412000, 1869721200, 1887861600, 1901775600, 1919311200, 1933225200, 1950760800, 1964674800, 1982815200, 1996124400, 2014264800, 2027574000, 2045714400, 2059023600, 2077164000, 2091078000, 2108613600, 2122527600, 2140063200], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 1, 0), (-18000, 0, 4)], 'EDT\000EST\000'), 'Canada/Pacific': ('Canada/Pacific', 138, 2, [-21477600, -5756400, 9972000, 25693200, 41421600, 57747600, 73476000, 89197200, 104925600, 120646800, 136375200, 152096400, 167824800, 183546000, 199274400, 215600400, 230724000, 247050000, 262778400, 278499600, 294228000, 309949200, 325677600, 341398800, 357127200, 372848400, 388576800, 404902800, 420026400, 436352400, 452080800, 467802000, 483530400, 499251600, 514980000, 530701200, 544615200, 562150800, 576064800, 594205200, 607514400, 625654800, 638964000, 657104400, 671018400, 688554000, 702468000, 720003600, 733917600, 752058000, 765367200, 783507600, 796816800, 814957200, 828871200, 846406800, 860320800, 877856400, 891770400, 909306000, 923220000, 941360400, 954669600, 972810000, 986119200, 1004259600, 1018173600, 1035709200, 1049623200, 1067158800, 1081072800, 1099213200, 1112522400, 1130662800, 1143972000, 1162112400, 1175421600, 1193562000, 1207476000, 1225011600, 1238925600, 1256461200, 1270375200, 1288515600, 1301824800, 1319965200, 1333274400, 1351414800, 1365328800, 1382864400, 1396778400, 1414314000, 1428228000, 1445763600, 1459677600, 1477818000, 1491127200, 1509267600, 1522576800, 1540717200, 1554631200, 1572166800, 1586080800, 1603616400, 1617530400, 1635670800, 1648980000, 1667120400, 1680429600, 1698570000, 1712484000, 1730019600, 1743933600, 1761469200, 1775383200, 1792918800, 1806832800, 1824973200, 1838282400, 1856422800, 1869732000, 1887872400, 1901786400, 1919322000, 1933236000, 1950771600, 1964685600, 1982826000, 1996135200, 2014275600, 2027584800, 2045725200, 2059034400, 2077174800, 2091088800, 2108624400, 2122538400, 2140074000], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-25200, 1, 0), (-28800, 0, 4)], 'PDT\000PST\000'), 'Mexico/BajaNorte': ('Mexico/BajaNorte', 102, 2, [544615200, 562150800, 576064800, 594205200, 607514400, 625654800, 638964000, 657104400, 671018400, 688554000, 702468000, 720003600, 733917600, 752058000, 765367200, 783507600, 796816800, 814957200, 828871200, 846406800, 860320800, 877856400, 891770400, 909306000, 923220000, 941360400, 954669600, 972810000, 986119200, 1004259600, 1018173600, 1035709200, 1049623200, 1067158800, 1081072800, 1099213200, 1112522400, 1130662800, 1143972000, 1162112400, 1175421600, 1193562000, 1207476000, 1225011600, 1238925600, 1256461200, 1270375200, 1288515600, 1301824800, 1319965200, 1333274400, 1351414800, 1365328800, 1382864400, 1396778400, 1414314000, 1428228000, 1445763600, 1459677600, 1477818000, 1491127200, 1509267600, 1522576800, 1540717200, 1554631200, 1572166800, 1586080800, 1603616400, 1617530400, 1635670800, 1648980000, 1667120400, 1680429600, 1698570000, 1712484000, 1730019600, 1743933600, 1761469200, 1775383200, 1792918800, 1806832800, 1824973200, 1838282400, 1856422800, 1869732000, 1887872400, 1901786400, 1919322000, 1933236000, 1950771600, 1964685600, 1982826000, 1996135200, 2014275600, 2027584800, 2045725200, 2059034400, 2077174800, 2091088800, 2108624400, 2122538400, 2140074000], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-25200, 1, 0), (-28800, 0, 4)], 'PDT\000PST\000'), 'Canada/Central': ('Canada/Central', 138, 2, [-21484800, -5763600, 9964800, 25686000, 41414400, 57740400, 73468800, 89190000, 104918400, 120639600, 136368000, 152089200, 167817600, 183538800, 199267200, 215593200, 230716800, 247042800, 262771200, 278492400, 294220800, 309942000, 325670400, 341391600, 357120000, 372841200, 388569600, 404895600, 420019200, 436345200, 452073600, 467794800, 483523200, 499244400, 514972800, 530694000, 544608000, 562143600, 576057600, 594198000, 607507200, 625647600, 638956800, 657097200, 671011200, 688546800, 702460800, 719996400, 733910400, 752050800, 765360000, 783500400, 796809600, 814950000, 828864000, 846399600, 860313600, 877849200, 891763200, 909298800, 923212800, 941353200, 954662400, 972802800, 986112000, 1004252400, 1018166400, 1035702000, 1049616000, 1067151600, 1081065600, 1099206000, 1112515200, 1130655600, 1143964800, 1162105200, 1175414400, 1193554800, 1207468800, 1225004400, 1238918400, 1256454000, 1270368000, 1288508400, 1301817600, 1319958000, 1333267200, 1351407600, 1365321600, 1382857200, 1396771200, 1414306800, 1428220800, 1445756400, 1459670400, 1477810800, 1491120000, 1509260400, 1522569600, 1540710000, 1554624000, 1572159600, 1586073600, 1603609200, 1617523200, 1635663600, 1648972800, 1667113200, 1680422400, 1698562800, 1712476800, 1730012400, 1743926400, 1761462000, 1775376000, 1792911600, 1806825600, 1824966000, 1838275200, 1856415600, 1869724800, 1887865200, 1901779200, 1919314800, 1933228800, 1950764400, 1964678400, 1982818800, 1996128000, 2014268400, 2027577600, 2045718000, 2059027200, 2077167600, 2091081600, 2108617200, 2122531200, 2140066800], '\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-18000, 1, 0), (-21600, 0, 4)], 'CDT\000CST\000'), 'US/Michigan': ('US/Michigan', 138, 3, [-1633280400, -1615140000, -1601830800, -1583690400, -880218000, -765396000, -84387600, -68666400, 104914800, 120636000, 126687600, 152085600, 162370800, 183535200, 199263600, 215589600, 230713200, 247039200, 262767600, 278488800, 294217200, 309938400, 325666800, 341388000, 357116400, 372837600, 388566000, 404892000, 420015600, 436341600, 452070000, 467791200, 483519600, 499240800, 514969200, 530690400, 544604400, 562140000, 576054000, 594194400, 607503600, 625644000, 638953200, 657093600, 671007600, 688543200, 702457200, 719992800, 733906800, 752047200, 765356400, 783496800, 796806000, 814946400, 828860400, 846396000, 860310000, 877845600, 891759600, 909295200, 923209200, 941349600, 954658800, 972799200, 986108400, 1004248800, 1018162800, 1035698400, 1049612400, 1067148000, 1081062000, 1099202400, 1112511600, 1130652000, 1143961200, 1162101600, 1175410800, 1193551200, 1207465200, 1225000800, 1238914800, 1256450400, 1270364400, 1288504800, 1301814000, 1319954400, 1333263600, 1351404000, 1365318000, 1382853600, 1396767600, 1414303200, 1428217200, 1445752800, 1459666800, 1477807200, 1491116400, 1509256800, 1522566000, 1540706400, 1554620400, 1572156000, 1586070000, 1603605600, 1617519600, 1635660000, 1648969200, 1667109600, 1680418800, 1698559200, 1712473200, 1730008800, 1743922800, 1761458400, 1775372400, 1792908000, 1806822000, 1824962400, 1838271600, 1856412000, 1869721200, 1887861600, 1901775600, 1919311200, 1933225200, 1950760800, 1964674800, 1982815200, 1996124400, 2014264800, 2027574000, 2045714400, 2059023600, 2077164000, 2091078000, 2108613600, 2122527600, 2140063200], '\000\001\000\001\002\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001', [(-14400, 1, 0), (-18000, 0, 4), (-14400, 1, 8)], 'EDT\000EST\000EWT\000'),
}
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from DateTime import DateTime
from DateTime import Timezones
##############################################################################
#
# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""DateTime interfaces
$Id$
"""
from zope.interface import Interface
class DateTimeError(Exception):
pass
class SyntaxError(DateTimeError):
pass
class DateError(DateTimeError):
pass
class TimeError(DateTimeError):
pass
class IDateTime(Interface):
# Conversion and comparison methods
#TODO determine whether this method really is part of the public API
def localZone(ltm=None):
'''Returns the time zone on the given date. The time zone
can change according to daylight savings.'''
def timeTime():
"""Return the date/time as a floating-point number in UTC, in
the format used by the python time module. Note that it is
possible to create date/time values with DateTime that have no
meaningful value to the time module."""
def toZone(z):
"""Return a DateTime with the value as the current object,
represented in the indicated timezone."""
def isFuture():
"""Return true if this object represents a date/time later
than the time of the call"""
def isPast():
"""Return true if this object represents a date/time earlier
than the time of the call"""
def isCurrentYear():
"""Return true if this object represents a date/time that
falls within the current year, in the context of this
object's timezone representation"""
def isCurrentMonth():
"""Return true if this object represents a date/time that
falls within the current month, in the context of this
object's timezone representation"""
def isCurrentDay():
"""Return true if this object represents a date/time that
falls within the current day, in the context of this object's
timezone representation"""
def isCurrentHour():
"""Return true if this object represents a date/time that
falls within the current hour, in the context of this object's
timezone representation"""
def isCurrentMinute():
"""Return true if this object represents a date/time that
falls within the current minute, in the context of this
object's timezone representation"""
def isLeapYear():
"""Return true if the current year (in the context of the
object's timezone) is a leap year"""
def earliestTime():
"""Return a new DateTime object that represents the earliest
possible time (in whole seconds) that still falls within the
current object's day, in the object's timezone context"""
def latestTime():
"""Return a new DateTime object that represents the latest
possible time (in whole seconds) that still falls within the
current object's day, in the object's timezone context"""
def greaterThan(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time greater than the specified DateTime or time module
style time. Revised to give more correct results through
comparison of long integer milliseconds."""
__gt__ = greaterThan
def greaterThanEqualTo(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time greater than or equal to the specified DateTime or
time module style time. Revised to give more correct results
through comparison of long integer milliseconds."""
__ge__ = greaterThanEqualTo
def equalTo(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time equal to the specified DateTime or time module style
time. Revised to give more correct results through comparison
of long integer milliseconds."""
__eq__ = equalTo
def notEqualTo(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time not equal to the specified DateTime or time module
style time. Revised to give more correct results through
comparison of long integer milliseconds."""
__ne__ = notEqualTo
def lessThan(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time less than the specified DateTime or time module
style time. Revised to give more correct results through
comparison of long integer milliseconds."""
__lt__ = lessThan
def lessThanEqualTo(t):
"""Compare this DateTime object to another DateTime object OR
a floating point number such as that which is returned by the
python time module. Returns true if the object represents a
date/time less than or equal to the specified DateTime or time
module style time. Revised to give more correct results
through comparison of long integer milliseconds."""
__le__ = lessThanEqualTo
# Component access
def parts():
"""Return a tuple containing the calendar year, month, day,
hour, minute second and timezone of the object"""
def timezone():
"""Return the timezone in which the object is represented."""
def tzoffset():
"""Return the timezone offset for the objects timezone."""
def year():
"""Return the calendar year of the object"""
def month():
"""Return the month of the object as an integer"""
def Month():
"""Return the full month name"""
def aMonth():
"""Return the abreviated month name."""
def Mon():
"""Compatibility: see aMonth"""
def pMonth():
"""Return the abreviated (with period) month name."""
def Mon_():
"""Compatibility: see pMonth"""
def day():
"""Return the integer day"""
def Day():
"""Return the full name of the day of the week"""
def DayOfWeek():
"""Compatibility: see Day"""
def dayOfYear():
"""Return the day of the year, in context of the timezone
representation of the object"""
def aDay():
"""Return the abreviated name of the day of the week"""
def pDay():
"""Return the abreviated (with period) name of the day of the
week"""
def Day_():
"""Compatibility: see pDay"""
def dow():
"""Return the integer day of the week, where sunday is 0"""
def dow_1():
"""Return the integer day of the week, where sunday is 1"""
def h_12():
"""Return the 12-hour clock representation of the hour"""
def h_24():
"""Return the 24-hour clock representation of the hour"""
def ampm():
"""Return the appropriate time modifier (am or pm)"""
def hour():
"""Return the 24-hour clock representation of the hour"""
def minute():
"""Return the minute"""
def second():
"""Return the second"""
def millis():
"""Return the millisecond since the epoch in GMT."""
def strftime(format):
"""Format the date/time using the *current timezone representation*."""
# General formats from previous DateTime
def Date():
"""Return the date string for the object."""
def Time():
"""Return the time string for an object to the nearest second."""
def TimeMinutes():
"""Return the time string for an object not showing seconds."""
def AMPM():
"""Return the time string for an object to the nearest second."""
def AMPMMinutes():
"""Return the time string for an object not showing seconds."""
def PreciseTime():
"""Return the time string for the object."""
def PreciseAMPM():
"""Return the time string for the object."""
def yy():
"""Return calendar year as a 2 digit string"""
def mm():
"""Return month as a 2 digit string"""
def dd():
"""Return day as a 2 digit string"""
def rfc822():
"""Return the date in RFC 822 format"""
# New formats
def fCommon():
"""Return a string representing the object's value in the
format: March 1, 1997 1:45 pm"""
def fCommonZ():
"""Return a string representing the object's value in the
format: March 1, 1997 1:45 pm US/Eastern"""
def aCommon():
"""Return a string representing the object's value in the
format: Mar 1, 1997 1:45 pm"""
def aCommonZ():
"""Return a string representing the object's value in the
format: Mar 1, 1997 1:45 pm US/Eastern"""
def pCommon():
"""Return a string representing the object's value in the
format: Mar. 1, 1997 1:45 pm"""
def pCommonZ():
"""Return a string representing the object's value
in the format: Mar. 1, 1997 1:45 pm US/Eastern"""
def ISO():
"""Return the object in ISO standard format. Note: this is
*not* ISO 8601-format! See the ISO8601 and HTML4 methods below
for ISO 8601-compliant output
Dates are output as: YYYY-MM-DD HH:MM:SS
"""
def ISO8601():
"""Return the object in ISO 8601-compatible format containing
the date, time with seconds-precision and the time zone
identifier - see http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSTZD
T is a literal character.
TZD is Time Zone Designator, format +HH:MM or -HH:MM
The HTML4 method below offers the same formatting, but
converts to UTC before returning the value and sets the TZD"Z"
"""
def HTML4():
"""Return the object in the format used in the HTML4.0
specification, one of the standard forms in ISO8601. See
http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSZ
T, Z are literal characters.
The time is in UTC.
"""
def JulianDay():
"""Return the Julian day according to
http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
"""
def week():
"""Return the week number according to ISO
see http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
"""
# Python operator and conversion API
def __add__(other):
"""A DateTime may be added to a number and a number may be
added to a DateTime; two DateTimes cannot be added."""
__radd__ = __add__
def __sub__(other):
"""Either a DateTime or a number may be subtracted from a
DateTime, however, a DateTime may not be subtracted from a
number."""
def __repr__():
"""Convert a DateTime to a string that looks like a Python
expression."""
def __str__():
"""Convert a DateTime to a string."""
def __cmp__(obj):
"""Compare a DateTime with another DateTime object, or a float
such as those returned by time.time().
NOTE: __cmp__ support is provided for backward compatibility
only, and mixing DateTimes with ExtensionClasses could cause
__cmp__ to break. You should use the methods lessThan,
greaterThan, lessThanEqualTo, greaterThanEqualTo, equalTo and
notEqualTo to avoid potential problems later!!"""
def __hash__():
"""Compute a hash value for a DateTime"""
def __int__():
"""Convert to an integer number of seconds since the epoch (gmt)"""
def __long__():
"""Convert to a long-int number of seconds since the epoch (gmt)"""
def __float__():
"""Convert to floating-point number of seconds since the epoch (gmt)"""
Pytz Support
============
Allows the pytz package to be used for time zone information. The
advantage of using pytz is that it has a more complete and up to date
time zone and daylight savings time database.
Usage
-----
You don't have to do anything special to make it work.
>>> from DateTime import DateTime, Timezones
>>> d = DateTime('March 11, 2007 US/Eastern')
Daylight Savings
----------------
In 2007 daylight savings time in the US was changed. The Energy Policy
Act of 2005 mandates that DST will start on the second Sunday in March
and end on the first Sunday in November.
In 2007, the start and stop dates are March 11 and November 4,
respectively. These dates are different from previous DST start and
stop dates. In 2006, the dates were the first Sunday in April (April
2, 2006) and the last Sunday in October (October 29, 2006).
Let's make sure that DateTime can deal with this, since the primary
motivation to use pytz for time zone information is the fact that it
is kept up to date with daylight savings changes.
>>> DateTime('March 11, 2007 US/Eastern').tzoffset()
-18000
>>> DateTime('March 12, 2007 US/Eastern').tzoffset()
-14400
>>> DateTime('November 4, 2007 US/Eastern').tzoffset()
-14400
>>> DateTime('November 5, 2007 US/Eastern').tzoffset()
-18000
Let's compare this to 2006.
>>> DateTime('April 2, 2006 US/Eastern').tzoffset()
-18000
>>> DateTime('April 3, 2006 US/Eastern').tzoffset()
-14400
>>> DateTime('October 29, 2006 US/Eastern').tzoffset()
-14400
>>> DateTime('October 30, 2006 US/Eastern').tzoffset()
-18000
Time Zones
---------
DateTime can use pytz's large database of time zones. Here are some
examples:
>>> d = DateTime('Pacific/Kwajalein')
>>> d = DateTime('America/Shiprock')
>>> d = DateTime('Africa/Ouagadougou')
Of course pytz doesn't know about everything.
>>> d = DateTime('July 21, 1969 Moon/Eastern')
Traceback (most recent call last):
...
SyntaxError: July 21, 1969 Moon/Eastern
You can still use zone names that DateTime defines that aren't part of
the pytz database.
>>> d = DateTime('eet')
>>> d = DateTime('iceland')
These time zones use DateTimes database. So it's preferable to use the
official time zone name.
One trickiness is that DateTime supports some zone name
abbreviations. Some of these map to pytz names, so these abbreviations
will give you time zone date from pytz. Notable among abbreviations
that work this way are 'est', 'cst', 'mst', and 'pst'.
Let's verify that 'est' picks up the 2007 daylight savings time changes.
>>> DateTime('March 11, 2007 est').tzoffset()
-18000
>>> DateTime('March 12, 2007 est').tzoffset()
-14400
>>> DateTime('November 4, 2007 est').tzoffset()
-14400
>>> DateTime('November 5, 2007 est').tzoffset()
-18000
You can get a list of time zones supported by calling the Timezones() function.
>>> Timezones() #doctest: +ELLIPSIS
['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ...]
Note that you can mess with this list without hurting things.
>>> t = Timezones()
>>> t.remove('US/Eastern')
>>> d = DateTime('US/Eastern')
Python Versions
---------------
Both pytz and DateTime should work under Python 2.3 as well as Python 2.4.
Internal Components
-------------------
The following are tests of internal components.
Cache
~~~~~
The DateTime class uses a new time zone cache.
>>> DateTime._tzinfo #doctest: +ELLIPSIS
<DateTime.pytz_support.PytzCache instance at ...>
The cache maps time zone names to time zone instances.
>>> cache = DateTime._tzinfo
>>> tz = cache['GMT+730']
>>> tz = cache['US/Mountain']
The cache also must provide a few attributes for use by the DateTime
class.
The _zlst attribute is a list of supported time zone names.
>>> cache._zlst #doctest: +ELLIPSIS
['Africa/Abidjan'... 'Africa/Accra'... 'IDLE'... 'NZST'... 'NZT'...]
The _zidx attribute is a list of lower-case and possibly abbreviated
time zone names that can be mapped to offical zone names.
>>> cache._zidx #doctest: +ELLIPSIS
[... 'australia/yancowinna'... 'gmt+0500'... 'europe/isle_of_man'...]
Note that there are more items in _zidx than in _zlst since there are
multiple names for some time zones.
>>> len(cache._zidx) > len(cache._zlst)
True
Each entry in _zlst should also be present in _zidx in lower case form.
>>> for name in cache._zlst:
... if not name.lower() in cache._zidx:
... print "Error %s not in _zidx" % name.lower()
The _zmap attribute maps the names in _zidx to official names in _zlst.
>>> cache._zmap['africa/abidjan']
'Africa/Abidjan'
>>> cache._zmap['gmt+1']
'GMT+1'
>>> cache._zmap['gmt+0100']
'GMT+1'
>>> cache._zmap['utc']
'UTC'
Let's make sure that _zmap and _zidx agree.
>>> idx = list(cache._zidx)
>>> idx.sort()
>>> keys = cache._zmap.keys()
>>> keys.sort()
>>> idx == keys
True
Timezone objects
~~~~~~~~~~~~~~~~
The timezone instances have only one public method info(). It returns
a tuple of (offset, is_dst, name). The method takes a timestamp, which
is used to determine dst information.
>>> t1 = DateTime('November 4, 00:00 2007 US/Mountain').timeTime()
>>> t2 = DateTime('November 4, 02:00 2007 US/Mountain').timeTime()
>>> tz.info(t1)
(-21600, 1, 'MDT')
>>> tz.info(t2)
(-25200, 0, 'MST')
If you don't pass any arguments to info it provides daylight savings
time information as of today.
>>> tz.info() in ((-21600, 1, 'MDT'), (-25200, 0, 'MST'))
True
##############################################################################
#
# Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""
Pytz timezone support.
"""
import pytz
import pytz.reference
from pytz.tzinfo import StaticTzInfo, memorized_timedelta
from datetime import datetime, timedelta
import re
from interfaces import DateTimeError
EPOCH = datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc)
_numeric_timezone_data = {
'GMT': ('GMT', 0, 1, [], '', [(0, 0, 0)], 'GMT\000'),
'GMT+0': ('GMT+0', 0, 1, [], '', [(0, 0, 0)], 'GMT+0000\000'),
'GMT+1': ('GMT+1', 0, 1, [], '', [(3600, 0, 0)], 'GMT+0100\000'),
'GMT+2': ('GMT+2', 0, 1, [], '', [(7200, 0, 0)], 'GMT+0200\000'),
'GMT+3': ('GMT+3', 0, 1, [], '', [(10800, 0, 0)], 'GMT+0300\000'),
'GMT+4': ('GMT+4', 0, 1, [], '', [(14400, 0, 0)], 'GMT+0400\000'),
'GMT+5': ('GMT+5', 0, 1, [], '', [(18000, 0, 0)], 'GMT+0500\000'),
'GMT+6': ('GMT+6', 0, 1, [], '', [(21600, 0, 0)], 'GMT+0600\000'),
'GMT+7': ('GMT+7', 0, 1, [], '', [(25200, 0, 0)], 'GMT+0700\000'),
'GMT+8': ('GMT+8', 0, 1, [], '', [(28800, 0, 0)], 'GMT+0800\000'),
'GMT+9': ('GMT+9', 0, 1, [], '', [(32400, 0, 0)], 'GMT+0900\000'),
'GMT+10': ('GMT+10', 0, 1, [], '', [(36000, 0, 0)], 'GMT+1000\000'),
'GMT+11': ('GMT+11', 0, 1, [], '', [(39600, 0, 0)], 'GMT+1100\000'),
'GMT+12': ('GMT+12', 0, 1, [], '', [(43200, 0, 0)], 'GMT+1200\000'),
'GMT+13': ('GMT+13', 0, 1, [], '', [(46800, 0, 0)], 'GMT+1300\000'),
'GMT-1': ('GMT-1', 0, 1, [], '', [(-3600, 0, 0)], 'GMT-0100\000'),
'GMT-2': ('GMT-2', 0, 1, [], '', [(-7200, 0, 0)], 'GMT-0200\000'),
'GMT-3': ('GMT-3', 0, 1, [], '', [(-10800, 0, 0)], 'GMT-0300\000'),
'GMT-4': ('GMT-4', 0, 1, [], '', [(-14400, 0, 0)], 'GMT-0400\000'),
'GMT-5': ('GMT-5', 0, 1, [], '', [(-18000, 0, 0)], 'GMT-0500\000'),
'GMT-6': ('GMT-6', 0, 1, [], '', [(-21600, 0, 0)], 'GMT-0600\000'),
'GMT-7': ('GMT-7', 0, 1, [], '', [(-25200, 0, 0)], 'GMT-0700\000'),
'GMT-8': ('GMT-8', 0, 1, [], '', [(-28800, 0, 0)], 'GMT-0800\000'),
'GMT-9': ('GMT-9', 0, 1, [], '', [(-32400, 0, 0)], 'GMT-0900\000'),
'GMT-10': ('GMT-10', 0, 1, [], '', [(-36000, 0, 0)], 'GMT-1000\000'),
'GMT-11': ('GMT-11', 0, 1, [], '', [(-39600, 0, 0)], 'GMT-1100\000'),
'GMT-12': ('GMT-12', 0, 1, [], '', [(-43200, 0, 0)], 'GMT-1200\000'),
'GMT+0130': ('GMT+0130', 0, 1, [], '', [(5400, 0, 0)], 'GMT+0130\000'),
'GMT+0230': ('GMT+0230', 0, 1, [], '', [(9000, 0, 0)], 'GMT+0230\000'),
'GMT+0330': ('GMT+0330', 0, 1, [], '', [(12600, 0, 0)], 'GMT+0330\000'),
'GMT+0430': ('GMT+0430', 0, 1, [], '', [(16200, 0, 0)], 'GMT+0430\000'),
'GMT+0530': ('GMT+0530', 0, 1, [], '', [(19800, 0, 0)], 'GMT+0530\000'),
'GMT+0630': ('GMT+0630', 0, 1, [], '', [(23400, 0, 0)], 'GMT+0630\000'),
'GMT+0730': ('GMT+0730', 0, 1, [], '', [(27000, 0, 0)], 'GMT+0730\000'),
'GMT+0830': ('GMT+0830', 0, 1, [], '', [(30600, 0, 0)], 'GMT+0830\000'),
'GMT+0930': ('GMT+0930', 0, 1, [], '', [(34200, 0, 0)], 'GMT+0930\000'),
'GMT+1030': ('GMT+1030', 0, 1, [], '', [(37800, 0, 0)], 'GMT+1030\000'),
'GMT+1130': ('GMT+1130', 0, 1, [], '', [(41400, 0, 0)], 'GMT+1130\000'),
'GMT+1230': ('GMT+1230', 0, 1, [], '', [(45000, 0, 0)], 'GMT+1230\000'),
'GMT-0130': ('GMT-0130', 0, 1, [], '', [(-5400, 0, 0)], 'GMT-0130\000'),
'GMT-0230': ('GMT-0230', 0, 1, [], '', [(-9000, 0, 0)], 'GMT-0230\000'),
'GMT-0330': ('GMT-0330', 0, 1, [], '', [(-12600, 0, 0)], 'GMT-0330\000'),
'GMT-0430': ('GMT-0430', 0, 1, [], '', [(-16200, 0, 0)], 'GMT-0430\000'),
'GMT-0530': ('GMT-0530', 0, 1, [], '', [(-19800, 0, 0)], 'GMT-0530\000'),
'GMT-0630': ('GMT-0630', 0, 1, [], '', [(-23400, 0, 0)], 'GMT-0630\000'),
'GMT-0730': ('GMT-0730', 0, 1, [], '', [(-27000, 0, 0)], 'GMT-0730\000'),
'GMT-0830': ('GMT-0830', 0, 1, [], '', [(-30600, 0, 0)], 'GMT-0830\000'),
'GMT-0930': ('GMT-0930', 0, 1, [], '', [(-34200, 0, 0)], 'GMT-0930\000'),
'GMT-1030': ('GMT-1030', 0, 1, [], '', [(-37800, 0, 0)], 'GMT-1030\000'),
'GMT-1130': ('GMT-1130', 0, 1, [], '', [(-41400, 0, 0)], 'GMT-1130\000'),
'GMT-1230': ('GMT-1230', 0, 1, [], '', [(-45000, 0, 0)], 'GMT-1230\000'),
}
# These are the timezones not in pytz.common_timezones
_old_zlst = [
'AST', 'AT', 'BST', 'BT', 'CCT',
'CET', 'CST', 'Cuba', 'EADT', 'EAST',
'EEST', 'EET', 'EST', 'Egypt', 'FST',
'FWT', 'GB-Eire', 'GMT+0100', 'GMT+0130', 'GMT+0200',
'GMT+0230', 'GMT+0300', 'GMT+0330', 'GMT+0400', 'GMT+0430',
'GMT+0500', 'GMT+0530', 'GMT+0600', 'GMT+0630', 'GMT+0700',
'GMT+0730', 'GMT+0800', 'GMT+0830', 'GMT+0900', 'GMT+0930',
'GMT+1', 'GMT+1000', 'GMT+1030', 'GMT+1100', 'GMT+1130',
'GMT+1200', 'GMT+1230', 'GMT+1300', 'GMT-0100', 'GMT-0130',
'GMT-0200', 'GMT-0300', 'GMT-0400', 'GMT-0500', 'GMT-0600',
'GMT-0630', 'GMT-0700', 'GMT-0730', 'GMT-0800', 'GMT-0830',
'GMT-0900', 'GMT-0930', 'GMT-1000', 'GMT-1030', 'GMT-1100',
'GMT-1130', 'GMT-1200', 'GMT-1230', 'GST', 'Greenwich',
'Hongkong', 'IDLE', 'IDLW', 'Iceland', 'Iran',
'Israel', 'JST', 'Jamaica', 'Japan', 'MEST',
'MET', 'MEWT', 'MST', 'NT', 'NZDT',
'NZST', 'NZT', 'PST', 'Poland', 'SST',
'SWT', 'Singapore', 'Turkey', 'UCT', 'UT',
'Universal', 'WADT', 'WAST', 'WAT', 'WET',
'ZP4', 'ZP5', 'ZP6',
]
_old_zmap={
'aest':'GMT+10', 'aedt':'GMT+11',
'aus eastern standard time':'GMT+10',
'sydney standard time':'GMT+10',
'tasmania standard time':'GMT+10',
'e. australia standard time':'GMT+10',
'aus central standard time':'GMT+0930',
'cen. australia standard time':'GMT+0930',
'w. australia standard time':'GMT+8',
'central europe standard time':'GMT+1',
'eastern standard time':'US/Eastern',
'us eastern standard time':'US/Eastern',
'central standard time':'US/Central',
'mountain standard time':'US/Mountain',
'pacific standard time':'US/Pacific',
'mst':'US/Mountain','pst':'US/Pacific',
'cst':'US/Central','est':'US/Eastern',
'gmt+0000':'GMT+0', 'gmt+0':'GMT+0',
'gmt+0100':'GMT+1', 'gmt+0200':'GMT+2', 'gmt+0300':'GMT+3',
'gmt+0400':'GMT+4', 'gmt+0500':'GMT+5', 'gmt+0600':'GMT+6',
'gmt+0700':'GMT+7', 'gmt+0800':'GMT+8', 'gmt+0900':'GMT+9',
'gmt+1000':'GMT+10','gmt+1100':'GMT+11','gmt+1200':'GMT+12',
'gmt+1300':'GMT+13',
'gmt-0100':'GMT-1', 'gmt-0200':'GMT-2', 'gmt-0300':'GMT-3',
'gmt-0400':'GMT-4', 'gmt-0500':'GMT-5', 'gmt-0600':'GMT-6',
'gmt-0700':'GMT-7', 'gmt-0800':'GMT-8', 'gmt-0900':'GMT-9',
'gmt-1000':'GMT-10','gmt-1100':'GMT-11','gmt-1200':'GMT-12',
'gmt+1': 'GMT+1', 'gmt+2': 'GMT+2', 'gmt+3': 'GMT+3',
'gmt+4': 'GMT+4', 'gmt+5': 'GMT+5', 'gmt+6': 'GMT+6',
'gmt+7': 'GMT+7', 'gmt+8': 'GMT+8', 'gmt+9': 'GMT+9',
'gmt+10':'GMT+10','gmt+11':'GMT+11','gmt+12':'GMT+12',
'gmt+13':'GMT+13',
'gmt-1': 'GMT-1', 'gmt-2': 'GMT-2', 'gmt-3': 'GMT-3',
'gmt-4': 'GMT-4', 'gmt-5': 'GMT-5', 'gmt-6': 'GMT-6',
'gmt-7': 'GMT-7', 'gmt-8': 'GMT-8', 'gmt-9': 'GMT-9',
'gmt-10':'GMT-10','gmt-11':'GMT-11','gmt-12':'GMT-12',
'gmt+130':'GMT+0130', 'gmt+0130':'GMT+0130',
'gmt+230':'GMT+0230', 'gmt+0230':'GMT+0230',
'gmt+330':'GMT+0330', 'gmt+0330':'GMT+0330',
'gmt+430':'GMT+0430', 'gmt+0430':'GMT+0430',
'gmt+530':'GMT+0530', 'gmt+0530':'GMT+0530',
'gmt+630':'GMT+0630', 'gmt+0630':'GMT+0630',
'gmt+730':'GMT+0730', 'gmt+0730':'GMT+0730',
'gmt+830':'GMT+0830', 'gmt+0830':'GMT+0830',
'gmt+930':'GMT+0930', 'gmt+0930':'GMT+0930',
'gmt+1030':'GMT+1030',
'gmt+1130':'GMT+1130',
'gmt+1230':'GMT+1230',
'gmt-130':'GMT-0130', 'gmt-0130':'GMT-0130',
'gmt-230':'GMT-0230', 'gmt-0230':'GMT-0230',
'gmt-330':'GMT-0330', 'gmt-0330':'GMT-0330',
'gmt-430':'GMT-0430', 'gmt-0430':'GMT-0430',
'gmt-530':'GMT-0530', 'gmt-0530':'GMT-0530',
'gmt-630':'GMT-0630', 'gmt-0630':'GMT-0630',
'gmt-730':'GMT-0730', 'gmt-0730':'GMT-0730',
'gmt-830':'GMT-0830', 'gmt-0830':'GMT-0830',
'gmt-930':'GMT-0930', 'gmt-0930':'GMT-0930',
'gmt-1030':'GMT-1030',
'gmt-1130':'GMT-1130',
'gmt-1230':'GMT-1230',
'ut':'Universal',
'bst':'GMT+1', 'mest':'GMT+2', 'sst':'GMT+2',
'fst':'GMT+2', 'wadt':'GMT+8', 'eadt':'GMT+11', 'nzdt':'GMT+13',
'wet':'GMT', 'wat':'GMT-1', 'at':'GMT-2', 'ast':'GMT-4',
'nt':'GMT-11', 'idlw':'GMT-12', 'cet':'GMT+1', 'cest':'GMT+2',
'met':'GMT+1',
'mewt':'GMT+1', 'swt':'GMT+1', 'fwt':'GMT+1', 'eet':'GMT+2',
'eest':'GMT+3',
'bt':'GMT+3', 'zp4':'GMT+4', 'zp5':'GMT+5', 'zp6':'GMT+6',
'wast':'GMT+7', 'cct':'GMT+8', 'jst':'GMT+9', 'east':'GMT+10',
'gst':'GMT+10', 'nzt':'GMT+12', 'nzst':'GMT+12', 'idle':'GMT+12',
'ret':'GMT+4', 'ist': 'GMT+0530'
}
def _static_timezone_factory(data):
zone = data[0]
cls = type(zone, (StaticTzInfo,), dict(
zone=zone,
_utcoffset=memorized_timedelta(data[5][0][0]),
_tzname=data[6][:-1] )) # strip the trailing null
return cls()
_numeric_timezones = dict((key, _static_timezone_factory(data))
for key, data in _numeric_timezone_data.items())
class Timezone:
"""
Timezone information returned by PytzCache.__getitem__
Adapts datetime.tzinfo object to DateTime._timezone interface
"""
def __init__(self, tzinfo):
self.tzinfo = tzinfo
def info(self, t=None):
if t is None:
dt = datetime.utcnow().replace(tzinfo=pytz.utc)
else:
dt = EPOCH + timedelta(0, t) # can't use utcfromtimestamp past 2038
# need to normalize tzinfo for the datetime to deal with
# daylight savings time.
normalized_dt = self.tzinfo.normalize(dt.astimezone(self.tzinfo))
normalized_tzinfo = normalized_dt.tzinfo
offset = normalized_tzinfo.utcoffset(dt)
secs = offset.days * 24 * 60 * 60 + offset.seconds
dst = normalized_tzinfo.dst(dt)
if dst == timedelta(0):
is_dst = 0
else:
is_dst = 1
return secs, is_dst, normalized_tzinfo.tzname(dt)
class PytzCache:
"""
Reimplementation of the DateTime._cache class that uses for timezone info
"""
_zlst = pytz.common_timezones + _old_zlst # used by DateTime.TimeZones
_zmap = dict((name.lower(), name) for name in pytz.all_timezones)
_zmap.update(_old_zmap) # These must take priority
_zidx = _zmap.keys()
def __getitem__(self, key):
name = self._zmap.get(key.lower(), key) # fallback to key
try:
return Timezone(pytz.timezone(name))
except pytz.UnknownTimeZoneError:
try:
return Timezone(_numeric_timezones[name])
except KeyError:
raise DateTimeError,'Unrecognized timezone: %s' % key
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
# This file is needed to make this a package.
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
from DateTime.DateTimeZone import _data
from time import time
class _timezone:
def __init__(self,data):
self.name,self.timect,self.typect, \
self.ttrans,self.tindex,self.tinfo,self.az=data
def default_index(self):
if self.timect == 0: return 0
for i in range(self.typect):
if self.tinfo[i][1] == 0: return i
return 0
def index(self,t=None):
t=t or time()
if self.timect==0: idx=(0, 0, 0)
elif t < self.ttrans[0]:
i=self.default_index()
idx=(i, ord(self.tindex[0]),i)
elif t >= self.ttrans[-1]:
if self.timect > 1:
idx=(ord(self.tindex[-1]),ord(self.tindex[-1]),
ord(self.tindex[-2]))
else:
idx=(ord(self.tindex[-1]),ord(self.tindex[-1]),
self.default_index())
else:
for i in range(self.timect-1):
if t < self.ttrans[i+1]:
if i==0: idx=(ord(self.tindex[0]),ord(self.tindex[1]),
self.default_index())
else: idx=(ord(self.tindex[i]),ord(self.tindex[i+1]),
ord(self.tindex[i-1]))
break
return idx
def info(self,t=None):
idx=self.index(t)[0]
zs =self.az[self.tinfo[idx][2]:]
return self.tinfo[idx][0],self.tinfo[idx][1],zs[:zs.find('\000')]
_zlst = ['Brazil/Acre','Brazil/DeNoronha','Brazil/East',
'Brazil/West','Canada/Atlantic','Canada/Central',
'Canada/Eastern','Canada/East-Saskatchewan',
'Canada/Mountain','Canada/Newfoundland',
'Canada/Pacific','Canada/Yukon',
'Chile/Continental','Chile/EasterIsland','CST','Cuba',
'Egypt','EST','GB-Eire','Greenwich','Hongkong','Iceland',
'Iran','Israel','Jamaica','Japan','Mexico/BajaNorte',
'Mexico/BajaSur','Mexico/General','MST','Poland','PST',
'Singapore','Turkey','Universal','US/Alaska','US/Aleutian',
'US/Arizona','US/Central','US/Eastern','US/East-Indiana',
'US/Hawaii','US/Indiana-Starke','US/Michigan',
'US/Mountain','US/Pacific','US/Samoa','UTC','UCT','GMT',
'GMT+0100','GMT+0200','GMT+0300','GMT+0400','GMT+0500',
'GMT+0600','GMT+0700','GMT+0800','GMT+0900','GMT+1000',
'GMT+1100','GMT+1200','GMT+1300','GMT-0100','GMT-0200',
'GMT-0300','GMT-0400','GMT-0500','GMT-0600','GMT-0700',
'GMT-0800','GMT-0900','GMT-1000','GMT-1100','GMT-1200',
'GMT+1',
'GMT+0130', 'GMT+0230', 'GMT+0330', 'GMT+0430', 'GMT+0530',
'GMT+0630', 'GMT+0730', 'GMT+0830', 'GMT+0930', 'GMT+1030',
'GMT+1130', 'GMT+1230',
'GMT-0130', 'GMT-0230', 'GMT-0330', 'GMT-0430', 'GMT-0530',
'GMT-0630', 'GMT-0730', 'GMT-0830', 'GMT-0930', 'GMT-1030',
'GMT-1130', 'GMT-1230',
'UT','BST','MEST','SST','FST','WADT','EADT','NZDT',
'WET','WAT','AT','AST','NT','IDLW','CET','MET',
'MEWT','SWT','FWT','EET','EEST','BT','ZP4','ZP5','ZP6',
'WAST','CCT','JST','EAST','GST','NZT','NZST','IDLE']
_zmap = {'aest':'GMT+1000', 'aedt':'GMT+1100',
'aus eastern standard time':'GMT+1000',
'sydney standard time':'GMT+1000',
'tasmania standard time':'GMT+1000',
'e. australia standard time':'GMT+1000',
'aus central standard time':'GMT+0930',
'cen. australia standard time':'GMT+0930',
'w. australia standard time':'GMT+0800',
'brazil/acre':'Brazil/Acre',
'brazil/denoronha':'Brazil/DeNoronha',
'brazil/east':'Brazil/East','brazil/west':'Brazil/West',
'canada/atlantic':'Canada/Atlantic',
'canada/central':'Canada/Central',
'canada/eastern':'Canada/Eastern',
'canada/east-saskatchewan':'Canada/East-Saskatchewan',
'canada/mountain':'Canada/Mountain',
'canada/newfoundland':'Canada/Newfoundland',
'canada/pacific':'Canada/Pacific','canada/yukon':'Canada/Yukon',
'central europe standard time':'GMT+0100',
'chile/continental':'Chile/Continental',
'chile/easterisland':'Chile/EasterIsland',
'cst':'US/Central','cuba':'Cuba','est':'US/Eastern','egypt':'Egypt',
'eastern standard time':'US/Eastern',
'us eastern standard time':'US/Eastern',
'central standard time':'US/Central',
'mountain standard time':'US/Mountain',
'pacific standard time':'US/Pacific',
'gb-eire':'GB-Eire','gmt':'GMT',
'gmt+0000':'GMT+0', 'gmt+0':'GMT+0',
'gmt+0100':'GMT+1', 'gmt+0200':'GMT+2', 'gmt+0300':'GMT+3',
'gmt+0400':'GMT+4', 'gmt+0500':'GMT+5', 'gmt+0600':'GMT+6',
'gmt+0700':'GMT+7', 'gmt+0800':'GMT+8', 'gmt+0900':'GMT+9',
'gmt+1000':'GMT+10','gmt+1100':'GMT+11','gmt+1200':'GMT+12',
'gmt+1300':'GMT+13',
'gmt-0100':'GMT-1', 'gmt-0200':'GMT-2', 'gmt-0300':'GMT-3',
'gmt-0400':'GMT-4', 'gmt-0500':'GMT-5', 'gmt-0600':'GMT-6',
'gmt-0700':'GMT-7', 'gmt-0800':'GMT-8', 'gmt-0900':'GMT-9',
'gmt-1000':'GMT-10','gmt-1100':'GMT-11','gmt-1200':'GMT-12',
'gmt+1': 'GMT+1', 'gmt+2': 'GMT+2', 'gmt+3': 'GMT+3',
'gmt+4': 'GMT+4', 'gmt+5': 'GMT+5', 'gmt+6': 'GMT+6',
'gmt+7': 'GMT+7', 'gmt+8': 'GMT+8', 'gmt+9': 'GMT+9',
'gmt+10':'GMT+10','gmt+11':'GMT+11','gmt+12':'GMT+12',
'gmt+13':'GMT+13',
'gmt-1': 'GMT-1', 'gmt-2': 'GMT-2', 'gmt-3': 'GMT-3',
'gmt-4': 'GMT-4', 'gmt-5': 'GMT-5', 'gmt-6': 'GMT-6',
'gmt-7': 'GMT-7', 'gmt-8': 'GMT-8', 'gmt-9': 'GMT-9',
'gmt-10':'GMT-10','gmt-11':'GMT-11','gmt-12':'GMT-12',
'gmt+130':'GMT+0130', 'gmt+0130':'GMT+0130',
'gmt+230':'GMT+0230', 'gmt+0230':'GMT+0230',
'gmt+330':'GMT+0330', 'gmt+0330':'GMT+0330',
'gmt+430':'GMT+0430', 'gmt+0430':'GMT+0430',
'gmt+530':'GMT+0530', 'gmt+0530':'GMT+0530',
'gmt+630':'GMT+0630', 'gmt+0630':'GMT+0630',
'gmt+730':'GMT+0730', 'gmt+0730':'GMT+0730',
'gmt+830':'GMT+0830', 'gmt+0830':'GMT+0830',
'gmt+930':'GMT+0930', 'gmt+0930':'GMT+0930',
'gmt+1030':'GMT+1030',
'gmt+1130':'GMT+1130',
'gmt+1230':'GMT+1230',
'gmt-130':'GMT-0130', 'gmt-0130':'GMT-0130',
'gmt-230':'GMT-0230', 'gmt-0230':'GMT-0230',
'gmt-330':'GMT-0330', 'gmt-0330':'GMT-0330',
'gmt-430':'GMT-0430', 'gmt-0430':'GMT-0430',
'gmt-530':'GMT-0530', 'gmt-0530':'GMT-0530',
'gmt-630':'GMT-0630', 'gmt-0630':'GMT-0630',
'gmt-730':'GMT-0730', 'gmt-0730':'GMT-0730',
'gmt-830':'GMT-0830', 'gmt-0830':'GMT-0830',
'gmt-930':'GMT-0930', 'gmt-0930':'GMT-0930',
'gmt-1030':'GMT-1030',
'gmt-1130':'GMT-1130',
'gmt-1230':'GMT-1230',
'greenwich':'Greenwich','hongkong':'Hongkong',
'iceland':'Iceland','iran':'Iran','israel':'Israel',
'jamaica':'Jamaica','japan':'Japan',
'mexico/bajanorte':'Mexico/BajaNorte',
'mexico/bajasur':'Mexico/BajaSur','mexico/general':'Mexico/General',
'mst':'US/Mountain','pst':'US/Pacific','poland':'Poland',
'singapore':'Singapore','turkey':'Turkey','universal':'Universal',
'utc':'Universal','uct':'Universal','us/alaska':'US/Alaska',
'us/aleutian':'US/Aleutian','us/arizona':'US/Arizona',
'us/central':'US/Central','us/eastern':'US/Eastern',
'us/east-indiana':'US/East-Indiana','us/hawaii':'US/Hawaii',
'us/indiana-starke':'US/Indiana-Starke','us/michigan':'US/Michigan',
'us/mountain':'US/Mountain','us/pacific':'US/Pacific',
'us/samoa':'US/Samoa',
'ut':'Universal',
'bst':'GMT+1', 'mest':'GMT+2', 'sst':'GMT+2',
'fst':'GMT+2', 'wadt':'GMT+8', 'eadt':'GMT+11', 'nzdt':'GMT+13',
'wet':'GMT', 'wat':'GMT-1', 'at':'GMT-2', 'ast':'GMT-4',
'nt':'GMT-11', 'idlw':'GMT-12', 'cet':'GMT+1', 'cest':'GMT+2',
'met':'GMT+1',
'mewt':'GMT+1', 'swt':'GMT+1', 'fwt':'GMT+1', 'eet':'GMT+2',
'eest':'GMT+3',
'bt':'GMT+3', 'zp4':'GMT+4', 'zp5':'GMT+5', 'zp6':'GMT+6',
'wast':'GMT+7', 'cct':'GMT+8', 'jst':'GMT+9', 'east':'GMT+10',
'gst':'GMT+10', 'nzt':'GMT+12', 'nzst':'GMT+12', 'idle':'GMT+12',
'ret':'GMT+4', 'ist': 'GMT+0530'
}
timezones = dict((name, _timezone(data)) for name, data in _data.iteritems())
\ No newline at end of file
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import math
import os
import time
import unittest
from DateTime.DateTime import _findLocalTimeZoneName, _cache
from DateTime import DateTime
from datetime import datetime, tzinfo, timedelta
import pytz
import legacy
try:
__file__
except NameError:
import sys
f = sys.argv[0]
else:
f = __file__
DATADIR = os.path.dirname(os.path.abspath(f))
del f
ZERO = timedelta(0)
class FixedOffset(tzinfo):
"""Fixed offset in minutes east from UTC."""
def __init__(self, offset, name):
self.__offset = timedelta(minutes = offset)
self.__name = name
def utcoffset(self, dt):
return self.__offset
def tzname(self, dt):
return self.__name
def dst(self, dt):
return ZERO
class DateTimeTests(unittest.TestCase):
def _compare(self, dt1, dt2, ms=1):
'''Compares the internal representation of dt1 with
the representation in dt2. Allows sub-millisecond variations.
Primarily for testing.'''
if ms:
self.assertEqual(dt1.millis(), dt2.millis())
self.assertEqual(math.floor(dt1._t * 1000.0),
math.floor(dt2._t * 1000.0))
self.assertEqual(math.floor(dt1._d * 86400000.0),
math.floor(dt2._d * 86400000.0))
self.assertEqual(math.floor(dt1.time * 86400000.0),
math.floor(dt2.time * 86400000.0))
def testBug1203(self):
# 01:59:60 occurred in old DateTime
dt = DateTime(7200, 'GMT')
self.assert_(str(dt).find('60') < 0, dt)
def testDSTInEffect(self):
# Checks GMT offset for a DST date in the US/Eastern time zone
dt = DateTime(2000, 5, 9, 15, 0, 0, 'US/Eastern')
self.assertEqual(dt.toZone('GMT').hour(), 19,
(dt, dt.toZone('GMT')))
def testDSTNotInEffect(self):
# Checks GMT offset for a non-DST date in the US/Eastern time zone
dt = DateTime(2000, 11, 9, 15, 0, 0, 'US/Eastern')
self.assertEqual(dt.toZone('GMT').hour(), 20,
(dt, dt.toZone('GMT')))
def testAddPrecision(self):
# Precision of serial additions
dt = DateTime()
self.assertEqual(str(dt + 0.10 + 3.14 + 6.76 - 10), str(dt),
dt)
def testConstructor3(self):
# Constructor from date/time string
dt = DateTime()
dt1s = '%d/%d/%d %d:%d:%f %s' % (
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.timezone())
dt1 = DateTime(dt1s)
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt),repr(dt1))
def testConstructor4(self):
# Constructor from time float
dt = DateTime()
dt1 = DateTime(float(dt))
self._compare(dt,dt1)
def testConstructor5(self):
# Constructor from time float and timezone
dt = DateTime()
dt1 = DateTime(float(dt), dt.timezone())
self.assertEqual(str(dt), str(dt1), (dt, dt1))
def testConstructor6(self):
# Constructor from year and julian date
# This test must normalize the time zone, or it *will* break when
# DST changes!
dt1 = DateTime(2000, 5.500000578705)
dt = DateTime('2000/1/5 12:00:00.050 pm %s' % dt1.localZone())
self._compare(dt, dt1)
def testConstructor7(self):
# Constructor from parts
dt = DateTime()
dt1 = DateTime(
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second(),
dt.timezone())
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self.assertEqual(repr(dt), repr(dt1))
def testDayOfWeek(self):
# strftime() used to always be passed a day of week of 0
dt = DateTime('2000/6/16')
s = dt.strftime('%A')
self.assertEqual(s, 'Friday', (dt, s))
def testOldDate(self):
# Fails when an 1800 date is displayed with negative signs
dt = DateTime('1830/5/6 12:31:46.213 pm')
dt1 = dt.toZone('GMT+6')
self.assert_(str(dt1).find('-') < 0, (dt, dt1))
def testSubtraction(self):
# Reconstruction of a DateTime from its parts, with subtraction
# this also tests the accuracy of addition and reconstruction
dt = DateTime()
dt1 = dt - 3.141592653
dt2 = DateTime(
dt.year(),
dt.month(),
dt.day(),
dt.hour(),
dt.minute(),
dt.second())
dt3 = dt2 - 3.141592653
self.assertEqual(dt1, dt3, (dt, dt1, dt2, dt3))
def testTZ1add(self):
# Time zone manipulation: add to a date
dt = DateTime('1997/3/8 1:45am GMT-4')
dt1 = DateTime('1997/3/9 1:45pm GMT+8')
self.assertEqual(dt + 1.0, dt1, (dt, dt1))
def testTZ1sub(self):
# Time zone manipulation: subtract from a date
dt = DateTime('1997/3/8 1:45am GMT-4')
dt1 = DateTime('1997/3/9 1:45pm GMT+8')
self.assertEqual(dt1 - 1.0, dt, (dt, dt1))
def testTZ1diff(self):
# Time zone manipulation: diff two dates
dt = DateTime('1997/3/8 1:45am GMT-4')
dt1 = DateTime('1997/3/9 1:45pm GMT+8')
self.assertEqual(dt1 - dt, 1.0, (dt, dt1))
def testCompareMethods(self):
# Compare two dates using several methods
dt = DateTime('1997/1/1')
dt1 = DateTime('1997/2/2')
self.failUnless(dt1.greaterThan(dt))
self.failUnless(dt1.greaterThanEqualTo(dt))
self.failUnless(dt.lessThan(dt1))
self.failUnless(dt.lessThanEqualTo(dt1))
self.failUnless(dt.notEqualTo(dt1))
self.failUnless(not dt.equalTo(dt1))
def testCompareOperations(self, dt=None, dt1=None):
# Compare two dates using several operations
if dt is None:
dt = DateTime('1997/1/1')
if dt1 is None:
dt1 = DateTime('1997/2/2')
self.failUnless(dt1 > dt)
self.failUnless(dt1 >= dt)
self.failUnless(dt < dt1)
self.failUnless(dt <= dt1)
self.failUnless(dt != dt1)
self.failUnless(not (dt == dt1))
def testUpgradeOldInstances(self):
# Compare dates that don't have the _micros attribute yet
dt = DateTime('1997/1/1')
dt1 = DateTime('1997/2/2')
del dt._micros
del dt1._micros
self.testCompareOperations(dt, dt1)
def testTZ2(self):
# Time zone manipulation test 2
dt = DateTime()
dt1 = dt.toZone('GMT')
s = dt.second()
s1 = dt1.second()
self.assertEqual(s, s1, (dt, dt1, s, s1))
def testTZDiffDaylight(self):
# Diff dates across daylight savings dates
dt = DateTime('2000/6/8 1:45am US/Eastern')
dt1 = DateTime('2000/12/8 12:45am US/Eastern')
self.assertEqual(dt1 - dt, 183, (dt, dt1, dt1 - dt))
def testY10KDate(self):
# Comparison of a Y10K date and a Y2K date
dt = DateTime('10213/09/21')
dt1 = DateTime(2000, 1, 1)
dsec = (dt.millis() - dt1.millis()) / 1000.0
ddays = math.floor((dsec / 86400.0) + 0.5)
self.assertEqual(ddays, 3000000L, ddays)
def test_tzoffset(self):
# Test time-zone given as an offset
# GMT
dt = DateTime('Tue, 10 Sep 2001 09:41:03 GMT')
self.assertEqual(dt.tzoffset(), 0)
# Timezone by name, a timezone that hasn't got daylightsaving.
dt = DateTime('Tue, 2 Mar 2001 09:41:03 GMT+3')
self.assertEqual(dt.tzoffset(), 10800)
# Timezone by name, has daylightsaving but is not in effect.
dt = DateTime('Tue, 21 Jan 2001 09:41:03 PST')
self.assertEqual(dt.tzoffset(), -28800)
# Timezone by name, with daylightsaving in effect
dt = DateTime('Tue, 24 Aug 2001 09:41:03 PST')
self.assertEqual(dt.tzoffset(), -25200)
# A negative numerical timezone
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0400')
self.assertEqual(dt.tzoffset(), -14400)
# A positive numerical timzone
dt = DateTime('Tue, 6 Dec 1966 01:41:03 +0200')
self.assertEqual(dt.tzoffset(), 7200)
# A negative numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 -0637')
self.assertEqual(dt.tzoffset(), -23820)
# A positive numerical timezone with minutes.
dt = DateTime('Tue, 24 Jul 2001 09:41:03 +0425')
self.assertEqual(dt.tzoffset(), 15900)
def testISO8601(self):
# ISO8601 reference dates
ref0 = DateTime('2002/5/2 8:00am GMT')
ref1 = DateTime('2002/5/2 8:00am US/Eastern')
ref2 = DateTime('2006/11/6 10:30 GMT')
ref3 = DateTime('2004/06/14 14:30:15 GMT-3')
ref4 = DateTime('2006/01/01 GMT')
# Basic tests
# Though this is timezone naive and according to specification should
# be interpreted in the local timezone, to preserve backwards
# compatibility with previously expected behaviour.
isoDt = DateTime('2002-05-02T08:00:00')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-05-02T08:00:00Z')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-05-02T08:00:00+00:00')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-05-02T08:00:00-04:00')
self.assertEqual(ref1, isoDt)
isoDt = DateTime('2002-05-02 08:00:00-04:00')
self.assertEqual(ref1, isoDt)
# Bug 1386: the colon in the timezone offset is optional
isoDt = DateTime('2002-05-02T08:00:00-0400')
self.assertEqual(ref1, isoDt)
# Bug 2191: date reduced formats
isoDt = DateTime('2006-01-01')
self.assertEqual(ref4, isoDt)
isoDt = DateTime('200601-01')
self.assertEqual(ref4, isoDt)
isoDt = DateTime('20060101')
self.assertEqual(ref4, isoDt)
isoDt = DateTime('2006-01')
self.assertEqual(ref4, isoDt)
isoDt = DateTime('200601')
self.assertEqual(ref4, isoDt)
isoDt = DateTime('2006')
self.assertEqual(ref4, isoDt)
# Bug 2191: date/time separators are also optional
isoDt = DateTime('20020502T08:00:00')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-05-02T080000')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('20020502T080000')
self.assertEqual(ref0, isoDt)
# Bug 2191: timezones with only one digit for hour
isoDt = DateTime('20020502T080000+0')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('20020502 080000-4')
self.assertEqual(ref1, isoDt)
isoDt = DateTime('20020502T080000-400')
self.assertEqual(ref1, isoDt)
isoDt = DateTime('20020502T080000-4:00')
self.assertEqual(ref1, isoDt)
# Bug 2191: optional seconds/minutes
isoDt = DateTime('2002-05-02T0800')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-05-02T08')
self.assertEqual(ref0, isoDt)
# Bug 2191: week format
isoDt = DateTime('2002-W18-4T0800')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002-W184T0800')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002W18-4T0800')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002W184T08')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2004-W25-1T14:30:15-03:00')
self.assertEqual(ref3, isoDt)
isoDt = DateTime('2004-W25T14:30:15-03:00')
self.assertEqual(ref3, isoDt)
# Bug 2191: day of year format
isoDt = DateTime('2002-122T0800')
self.assertEqual(ref0, isoDt)
isoDt = DateTime('2002122T0800')
self.assertEqual(ref0, isoDt)
# Bug 2191: hours/minutes fractions
isoDt = DateTime('2006-11-06T10.5')
self.assertEqual(ref2, isoDt)
isoDt = DateTime('2006-11-06T10,5')
self.assertEqual(ref2, isoDt)
isoDt = DateTime('20040614T1430.25-3')
self.assertEqual(ref3, isoDt)
isoDt = DateTime('2004-06-14T1430,25-3')
self.assertEqual(ref3, isoDt)
isoDt = DateTime('2004-06-14T14:30.25-3')
self.assertEqual(ref3, isoDt)
isoDt = DateTime('20040614T14:30,25-3')
self.assertEqual(ref3, isoDt)
# ISO8601 standard format
iso8601_string = '2002-05-02T08:00:00-04:00'
iso8601DT = DateTime(iso8601_string)
self.assertEqual(iso8601_string, iso8601DT.ISO8601())
def testJulianWeek(self):
# Check JulianDayWeek function
try:
import gzip
except ImportError:
print "Warning: testJulianWeek disabled: module gzip not found"
return 0
fn = os.path.join(DATADIR, 'julian_testdata.txt.gz')
lines = gzip.GzipFile(fn).readlines()
for line in lines:
d = DateTime(line[:10])
result_from_mx=tuple(map(int, line[12:-2].split(',')))
self.assertEqual(result_from_mx[1], d.week())
def testCopyConstructor(self):
d = DateTime('2004/04/04')
self.assertEqual(DateTime(d), d)
self.assertEqual(str(DateTime(d)), str(d))
d2 = DateTime('1999/04/12 01:00:00')
self.assertEqual(DateTime(d2), d2)
self.assertEqual(str(DateTime(d2)), str(d2))
def testCopyConstructorPreservesTimezone(self):
# test for https://bugs.launchpad.net/zope2/+bug/200007
# This always worked in the local timezone, so we need at least
# two tests with different zones to be sure at least one of them
# is not local.
d = DateTime('2004/04/04')
self.assertEqual(DateTime(d).timezone(), d.timezone())
d2 = DateTime('2008/04/25 12:00:00 EST')
self.assertEqual(DateTime(d2).timezone(), d2.timezone())
self.assertEqual(str(DateTime(d2)), str(d2))
d3 = DateTime('2008/04/25 12:00:00 PST')
self.assertEqual(DateTime(d3).timezone(), d3.timezone())
self.assertEqual(str(DateTime(d3)), str(d3))
def testRFC822(self):
# rfc822 conversion
dt = DateTime('2002-05-02T08:00:00+00:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0000')
dt = DateTime('2002-05-02T08:00:00+02:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 +0200')
dt = DateTime('2002-05-02T08:00:00-02:00')
self.assertEqual(dt.rfc822(), 'Thu, 02 May 2002 08:00:00 -0200')
# Checking that conversion from local time is working.
dt = DateTime()
dts = dt.rfc822().split(' ')
times = dts[4].split(':')
_isDST = time.localtime(time.time())[8]
if _isDST:
offset = time.altzone
else:
offset = time.timezone
self.assertEqual(dts[0], dt.aDay() + ',')
self.assertEqual(int(dts[1]), dt.day())
self.assertEqual(dts[2], dt.aMonth())
self.assertEqual(int(dts[3]), dt.year())
self.assertEqual(int(times[0]), dt.h_24())
self.assertEqual(int(times[1]), dt.minute())
self.assertEqual(int(times[2]), int(dt.second()))
self.assertEqual(dts[5], "%+03d%02d" % divmod( (-offset/60), 60) )
def testInternationalDateformat(self):
for year in range(1990, 2020):
for month in range (1, 13):
for day in range(1, 32):
try:
d_us = DateTime("%d/%d/%d" % (year,month,day))
except:
continue
d_int = DateTime("%d.%d.%d" % (day,month,year),
datefmt="international")
self.assertEqual(d_us, d_int)
d_int = DateTime("%d/%d/%d" % (day,month,year),
datefmt="international")
self.assertEqual(d_us, d_int)
def test_calcTimezoneName(self):
timezone_dependent_epoch = 2177452800L
try:
DateTime()._calcTimezoneName(timezone_dependent_epoch, 0)
except DateTime.TimeError:
self.fail('Zope Collector issue #484 (negative time bug): '
'TimeError raised')
def testStrftimeTZhandling(self):
# strftime timezone testing
# This is a test for collector issue #1127
format = '%Y-%m-%d %H:%M %Z'
dt = DateTime('Wed, 19 Nov 2003 18:32:07 -0215')
dt_string = dt.strftime(format)
dt_local = dt.toZone(_findLocalTimeZoneName(0))
dt_localstring = dt_local.strftime(format)
self.assertEqual(dt_string, dt_localstring)
def testStrftimeFarDates(self):
# Checks strftime in dates <= 1900 or >= 2038
dt = DateTime('1900/01/30')
self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/1900')
dt = DateTime('2040/01/30')
self.assertEqual(dt.strftime('%d/%m/%Y'), '30/01/2040')
def testZoneInFarDates(self):
# Checks time zone in dates <= 1900 or >= 2038
dt1 = DateTime('2040/01/30 14:33 GMT+1')
dt2 = DateTime('2040/01/30 11:33 GMT-2')
self.assertEqual(dt1.strftime('%d/%m/%Y %H:%M'),
dt2.strftime('%d/%m/%Y %H:%M'))
def testStrftimeUnicode(self):
dt = DateTime('2002-05-02T08:00:00+00:00')
ok = dt.strftime('Le %d/%m/%Y a %Hh%M').replace('a', u'\xe0')
self.assertEqual(dt.strftime(u'Le %d/%m/%Y \xe0 %Hh%M'), ok)
def testTimezoneNaiveHandling(self):
# checks that we assign timezone naivity correctly
dt = DateTime('2007-10-04T08:00:00+00:00')
assert dt.timezoneNaive() is False, 'error with naivity handling in __parse_iso8601'
dt = DateTime('2007-10-04T08:00:00Z')
assert dt.timezoneNaive() is False, 'error with naivity handling in __parse_iso8601'
dt = DateTime('2007-10-04T08:00:00')
assert dt.timezoneNaive() is True, 'error with naivity handling in __parse_iso8601'
dt = DateTime('2007/10/04 15:12:33.487618 GMT+1')
assert dt.timezoneNaive() is False, 'error with naivity handling in _parse'
dt = DateTime('2007/10/04 15:12:33.487618')
assert dt.timezoneNaive() is True, 'error with naivity handling in _parse'
dt = DateTime()
assert dt.timezoneNaive() is False, 'error with naivity for current time'
s = '2007-10-04T08:00:00'
dt = DateTime(s)
self.assertEqual(s, dt.ISO8601())
s = '2007-10-04T08:00:00+00:00'
dt = DateTime(s)
self.assertEqual(s, dt.ISO8601())
def testConversions(self):
sdt0 = datetime.now() # this is a timezone naive datetime
dt0 = DateTime(sdt0)
assert dt0.timezoneNaive() is True, (sdt0, dt0)
sdt1 = datetime(2007, 10, 4, 18, 14, 42, 580, pytz.utc)
dt1 = DateTime(sdt1)
assert dt1.timezoneNaive() is False, (sdt1, dt1)
# convert back
sdt2 = dt0.asdatetime()
self.assertEqual(sdt0, sdt2)
sdt3 = dt1.utcdatetime() # this returns a timezone naive datetime
self.assertEqual(sdt1.hour, sdt3.hour)
dt4 = DateTime('2007-10-04T10:00:00+05:00')
sdt4 = datetime(2007, 10, 4, 5, 0)
self.assertEqual(dt4.utcdatetime(), sdt4)
self.assertEqual(dt4.asdatetime(), sdt4.replace(tzinfo=pytz.utc))
dt5 = DateTime('2007-10-23 10:00:00 US/Eastern')
tz = pytz.timezone('US/Eastern')
sdt5 = datetime(2007, 10, 23, 10, 0, tzinfo=tz)
dt6 = DateTime(sdt5)
self.assertEqual(dt5.asdatetime(), sdt5)
self.assertEqual(dt6.asdatetime(), sdt5)
self.assertEqual(dt5, dt6)
self.assertEqual(dt5.asdatetime().tzinfo, tz)
self.assertEqual(dt6.asdatetime().tzinfo, tz)
def testLegacyTimezones(self):
cache = _cache()
# The year is important here as timezones change over time
t1 = time.mktime(datetime(2002, 1, 1).timetuple())
t2 = time.mktime(datetime(2002, 7, 1).timetuple())
for name in legacy._zlst + legacy._zmap.keys() + legacy._data.keys():
self.failUnless(name.lower() in cache._zidx, 'legacy timezone %s cannot be looked up' % name)
failures = []
for name, zone in legacy.timezones.iteritems():
newzone = cache[name]
# The name of the new zone might change (eg GMT+6 rather than GMT+0600)
if zone.info(t1)[:2] != newzone.info(t1)[:2] or zone.info(t2)[:2] != newzone.info(t2)[:2]:
failures.append(name)
expected_failures = [ # zone.info(t1) newzone.info(t1) zone.info(t2) newzone.info(t2)
'Jamaica', # (-18000, 0, 'EST') (-18000, 0, 'EST') (-14400, 1, 'EDT') (-18000, 0, 'EST')
'Turkey', # (10800, 0, 'EET') (7200, 0, 'EET') (14400, 1, 'EET DST') (10800, 1, 'EEST')
'Mexico/BajaSur', # (-25200, 0, 'MST') (-25200, 0, 'MST') (-25200, 0, 'MST') (-21600, 1, 'MDT')
'Mexico/General', # (-21600, 0, 'CST') (-21600, 0, 'CST') (-21600, 0, 'CST') (-18000, 1, 'CDT')
'Canada/Yukon', # (-32400, 0, 'YST') (-28800, 0, 'PST') (-28800, 1, 'YDT') (-25200, 1, 'PDT')
'Brazil/West', # (-10800, 1, 'WDT') (-14400, 0, 'AMT') (-14400, 0, 'WST') (-14400, 0, 'AMT')
'Brazil/Acre', # (-14400, 1, 'ADT') (-18000, 0, 'ACT') (-18000, 0, 'AST') (-18000, 0, 'ACT')
]
real_failures = list(set(failures).difference(set(expected_failures)))
self.failIf(real_failures, '\n'.join(real_failures))
def testBasicTZ(self):
"""psycopg2 supplies it's own tzinfo instances, with no `zone` attribute
"""
tz = FixedOffset(60, 'GMT+1')
dt1 = datetime(2008, 8, 5, 12, 0, tzinfo=tz)
DT = DateTime(dt1)
dt2 = DT.asdatetime()
offset1 = dt1.tzinfo.utcoffset(dt1)
offset2 = dt2.tzinfo.utcoffset(dt2)
self.assertEqual(offset1, offset2)
def test_suite():
from zope.testing import doctest
return unittest.TestSuite([
unittest.makeSuite(DateTimeTests),
doctest.DocFileSuite('DateTime.txt', package='DateTime'),
doctest.DocFileSuite('pytz.txt', package='DateTime'),
])
if __name__=="__main__":
unittest.main(defaultTest='test_suite')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment