Previous topic

libearth.subscribe — Subscription list

Next topic

libearth.version — Version data

This Page

libearth.tz — Basic timezone implementations

Almost of this module is from the official documentation of datetime module in Python standard library.

libearth.tz.utc

(Utc, datetime.timezone) The tzinfo instance that represents UTC. It’s an instance of Utc in Python 2 (which provide no built-in fixed-offset tzinfo implementation), and an instance of timezone with zero offset in Python 3.

class libearth.tz.FixedOffset(offset, name=None)

Fixed offset in minutes east from UTC.

>>> kst = FixedOffset(9 * 60, name='Asia/Seoul')  # KST +09:00
>>> current = now()
>>> current
datetime.datetime(2013, 8, 15, 3, 18, 37, 404562, tzinfo=libearth.tz.Utc())
>>> current.astimezone(kst)
datetime.datetime(2013, 8, 15, 12, 18, 37, 404562,
                  tzinfo=<libearth.tz.FixedOffset Asia/Seoul>)
class libearth.tz.Utc

UTC.

In most cases, it doesn’t need to be directly instantiated: there’s already the utc value.

libearth.tz.guess_tzinfo_by_locale(language, country=None)

Guess the most commonly used time zone from the given locale.

Parameters:
  • language (str) – the language code e.g. ko, JA
  • country (str) – optional country code e.g. kr, JP
Returns:

the most commonly used time zone, or None if can’t guess

Return type:

datetime.tzinfo

New in version 0.3.0.

libearth.tz.now()

Return the current datetime with the proper tzinfo setting.

>>> now()
datetime.datetime(2013, 8, 15, 3, 17, 11, 892272, tzinfo=libearth.tz.Utc())
>>> now()
datetime.datetime(2013, 8, 15, 3, 17, 17, 532483, tzinfo=libearth.tz.Utc())
Fork me on GitHub