Python Datetime TZ Documentation: Release 0.2
Python Datetime TZ Documentation: Release 0.2
Release 0.2
1 pytz_abbr 5
i
ii
Python Datetime TZ Documentation, Release 0.2
Contents 1
Python Datetime TZ Documentation, Release 0.2
class datetime_tz.iterate
Helpful iterators for working with datetime_tz objects.
static between(start, delta, end=None)
Return an iterator between this date till given end point.
Example usage:
2 Contents
Python Datetime TZ Documentation, Release 0.2
2008/05/15 11:45
2008/05/16 11:45
Args: start: The date to start at. delta: The interval to iterate with. end: (Optional) Date to end at. If not
given the iterator will never
terminate.
Yields: datetime_tz objects.
static days(start, end=None)
Iterate over the days between the given datetime_tzs.
Args: start: datetime_tz to start from. end: (Optional) Date to end at, if not given the iterator will never
terminate.
Returns: An iterator which generates datetime_tz objects a day apart.
static hours(start, end=None)
Iterate over the hours between the given datetime_tzs.
Args: start: datetime_tz to start from. end: (Optional) Date to end at, if not given the iterator will never
terminate.
Returns: An iterator which generates datetime_tz objects a hour apart.
static minutes(start, end=None)
Iterate over the minutes between the given datetime_tzs.
Args: start: datetime_tz to start from. end: (Optional) Date to end at, if not given the iterator will never
terminate.
Returns: An iterator which generates datetime_tz objects a minute apart.
static seconds(start, end=None)
Iterate over the seconds between the given datetime_tzs.
Args: start: datetime_tz to start from. end: (Optional) Date to end at, if not given the iterator will never
terminate.
Returns: An iterator which generates datetime_tz objects a second apart.
static weeks(start, end=None)
Iterate over the weeks between the given datetime_tzs.
Args: start: datetime_tz to start from. end: (Optional) Date to end at, if not given the iterator will never
terminate.
Returns: An iterator which generates datetime_tz objects a week apart.
datetime_tz.localtz()
Get the local timezone.
Returns: The localtime timezone as a tzinfo object.
datetime_tz.localtz_set(timezone)
Set the local timezone.
class datetime_tz.timedelta
Difference between two datetime values.
Contents 3
Python Datetime TZ Documentation, Release 0.2
days
Number of days.
microseconds
Number of microseconds (>= 0 and less than 1 second).
seconds
Number of seconds (>= 0 and less than 1 day).
total_seconds()
Total seconds in the duration.
datetime_tz.localize(dt, force_to_local=True)
Localize a datetime to the local timezone.
If dt is naive, returns the same datetime with the local timezone, otherwise uses astimezone to convert.
Args: dt: datetime object. force_to_local: Force all results to be in local time.
Returns: A datetime_tz object.
datetime_tz.get_naive(dt)
Gets a naive datetime from a datetime.
datetime_tz objects can’t just have tzinfo replaced with None, you need to call asdatetime.
Args: dt: datetime object.
Returns: datetime object without any timezone information.
datetime_tz.localtz_name()
Returns the name of the local timezone.
datetime_tz.require_timezone(zone)
Raises an AssertionError if we are not in the correct timezone.
4 Contents
CHAPTER 1
pytz_abbr
Common time zone acronyms/abbreviations for use with the datetime_tz module.
WARNING: There are lots of caveats when using this module which are listed below.
CAVEAT 1: The acronyms/abbreviations are not globally unique, they are not even unique within a region. For
example, EST can mean any of,
Eastern Standard Time in Australia (which is 10 hour ahead of UTC) Eastern Standard Time in North
America (which is 5 hours behind UTC)
Where there are two abbreviations the more popular one will appear in the all dictionary, while the less common one
will only appear in that countries region dictionary. IE If using all, EST will be mapped to Eastern Standard Time in
North America.
CAVEAT 2: Many of the acronyms don’t map to a neat Oslon timezones. For example, Eastern European Summer
Time (EEDT) is used by many different countries in Europe at different times! If the acronym does not map neatly
to one zone it is mapped to the Etc/GMT+-XX Oslon zone. This means that any date manipulations can end up with
idiot things like summer time in the middle of winter.
CAVEAT 3: The Summer/Standard time difference is really important! For an hour each year it is needed to determine
which time you are actually talking about.
2002-10-27 01:20:00 EST != 2002-10-27 01:20:00 EDT
class datetime_tz.pytz_abbr.tzabbr
A timezone abbreviation.
WARNING: This is not a tzinfo implementation! Trying to use this as tzinfo object will result in failure. We
inherit from datetime.tzinfo so we can get through the dateutil checks.
datetime_tz.pytz_abbr.tzabbr_register(abbr, name, region, zone, dst)
Register a new timezone abbreviation in the global registry.
If another abbreviation with the same name has already been registered it new abbreviation will only be regis-
tered in region specific dictionary.
5
Python Datetime TZ Documentation, Release 0.2
6 Chapter 1. pytz_abbr
Python Module Index
d
datetime_tz, 5
datetime_tz.pytz_abbr, 5
7
Python Datetime TZ Documentation, Release 0.2
B R
between() (datetime_tz.iterate static method), 2 replace() (datetime_tz.datetime_tz method), 1
require_timezone() (in module datetime_tz), 4
C
combine() (datetime_tz.datetime_tz class method), 1 S
seconds (datetime_tz.timedelta attribute), 4
D seconds() (datetime_tz.iterate static method), 3
datetime_tz (class in datetime_tz), 1 smartparse() (datetime_tz.datetime_tz class method), 1
datetime_tz (module), 1
datetime_tz.pytz_abbr (module), 5 T
days (datetime_tz.timedelta attribute), 3 timedelta (class in datetime_tz), 3
days() (datetime_tz.iterate static method), 3 today() (datetime_tz.datetime_tz class method), 2
detect_timezone() (in module datetime_tz), 2 total_seconds() (datetime_tz.timedelta method), 4
totimestamp() (datetime_tz.datetime_tz method), 2
F tzabbr (class in datetime_tz.pytz_abbr), 5
fromtimestamp() (datetime_tz.datetime_tz class method), tzabbr_register() (in module datetime_tz.pytz_abbr), 5
1
U
G utcfromtimestamp() (datetime_tz.datetime_tz class
get_naive() (in module datetime_tz), 4 method), 2
utcnow() (datetime_tz.datetime_tz class method), 2
H
hours() (datetime_tz.iterate static method), 3 W
weeks() (datetime_tz.iterate static method), 3
I
iterate (class in datetime_tz), 2
L
localize() (in module datetime_tz), 4
localtz() (in module datetime_tz), 3
localtz_name() (in module datetime_tz), 4
localtz_set() (in module datetime_tz), 3
M
microseconds (datetime_tz.timedelta attribute), 4