rattail.time

Time Utilities

rattail.time.localtime(config, time=None, key=u'default', tzinfo=True)[source]

Return a datetime which has been localized to a particular timezone. The timezone() function will be used to obtain the timezone to which the time value will be localized.

Parameters:
  • config – Reference to a config object.
  • time – Optional datetime.datetime instance to be localized. If not provided, the current time (“now”) is assumed.
  • tzinfo – Boolean indicating whether the result should contain tzinfo or not, i.e. whether it should be time zone “aware” (True) or “naive” (False).
  • key – Config key to be used in determining to which timezone the time should be localized.
rattail.time.make_utc(time)[source]

Convert a timezone-aware time back to a naive UTC equivalent.

rattail.time.timezone(config, key=u'default')[source]

Return a timezone object based on the definition found in config.

Parameters:
  • config – Reference to a config object.
  • key – Config key used to determine which timezone should be returned.
Returns:

A pytz.tzinfo instance, created using the Olson time zone name found in the config file.

An example of the configuration syntax which is assumed by this function:

[rattail]

# retrieve with: timezone(config)
timezone.default = America/Los_Angeles

# retrieve with: timezone(config, 'headoffice')
timezone.headoffice = America/Chicago

# retrieve with: timezone(config, 'satellite')
timezone.satellite = America/New_York

See Wikipedia for the full list of Olson time zone names.