Package trac :: Package util :: Module datefmt

Module datefmt

source code

Classes
  FixedOffset
Fixed offset in minutes east from UTC.
  LocalTimezone
A 'local' time zone implementation
Functions
 
get_period_names(locale=None) source code
 
to_datetime(t, tzinfo=None)
Convert t into a datetime object in the tzinfo timezone.
source code
 
to_timestamp(dt)
Return the corresponding POSIX timestamp
source code
 
to_utimestamp(dt)
Return a microsecond POSIX timestamp for the given datetime.
source code
 
from_utimestamp(ts)
Return the datetime for the given microsecond POSIX timestamp.
source code
 
pretty_timedelta(time1, time2=None, resolution=None)
Calculate time delta between two datetime objects.
source code
 
format_datetime(t=None, format='%x %X', tzinfo=None, locale=None)
Format the datetime object t into an unicode string
source code
 
format_date(t=None, format='%x', tzinfo=None, locale=None)
Convenience method for formatting the date part of a datetime object.
source code
 
format_time(t=None, format='%X', tzinfo=None, locale=None)
Convenience method for formatting the time part of a datetime object.
source code
 
get_date_format_hint(locale=None)
Present the default format used by format_date in a human readable form.
source code
 
get_datetime_format_hint(locale=None)
Present the default format used by format_datetime in a human readable form.
source code
 
get_month_names_jquery_ui(req)
Get the month names for the jQuery UI datepicker library
source code
 
get_day_names_jquery_ui(req)
Get the day names for the jQuery UI datepicker library
source code
 
get_date_format_jquery_ui(locale)
Get the date format for the jQuery UI datepicker library.
source code
 
get_time_format_jquery_ui(locale)
Get the time format for the jQuery UI timepicker addon.
source code
 
get_timezone_list_jquery_ui(t=None)
Get timezone list for jQuery timepicker addon
source code
 
get_first_week_day_jquery_ui(req)
Get first week day for jQuery date picker
source code
 
get_timepicker_separator_jquery_ui(req) source code
 
get_period_names_jquery_ui(req) source code
 
is_24_hours(locale)
Returns True for 24 hour time formats.
source code
 
http_date(t=None)
Format datetime object t as a rfc822 timestamp
source code
 
parse_date(text, tzinfo=None, locale=None, hint='date') source code
 
user_time(req, func, *args, **kwargs)
A helper function which passes to tzinfo and locale keyword arguments of func using req parameter.
source code
 
timezone(tzname)
Fetch timezone instance by name or raise KeyError
source code
 
get_timezone(tzname)
Fetch timezone instance by name or return None
source code
 
datetime_now(...)
[tz] -> new datetime with tz's local day and time.
source code
Variables
  utc = <FixedOffset "UTC" 0:00:00>
  utcmin = datetime.datetime(1, 1, 1, 0, 0, tzinfo=<FixedOffset ...
  utcmax = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, t...
  localtz = <LocalTimezone "CET" 1:00:00 "CEST" 2:00:00>
  STDOFFSET = datetime.timedelta(0, 3600)
  DSTOFFSET = datetime.timedelta(0, 7200)
  DSTDIFF = datetime.timedelta(0, 3600)
  all_timezones = ['Africa/Abidjan', 'Africa/Accra', 'Africa/Add...
  __package__ = 'trac.util'
  tz = <FixedOffset "GMT +14:00" 14:00:00>
  tzname = 'UTC'
  z = <FixedOffset "GMT +14:00" 14:00:00>

Imports: inspect, math, os, re, sys, time, tzinfo, timedelta, datetime, date, getlocale, LC_TIME, babel, Locale, LOCALE_ALIASES, UnknownLocaleError, babel_format_datetime, babel_format_date, babel_format_time, get_datetime_format, get_date_format, get_time_format, get_month_names, babel_get_period_names, get_day_names, TracError, to_unicode, getpreferredencoding, _, ngettext, bisect, pytz, time_now


Function Details

to_datetime(t, tzinfo=None)

source code 

Convert t into a datetime object in the tzinfo timezone.

If no tzinfo is given, the local timezone localtz will be used.

t is converted using the following rules:

  • If t is already a datetime object,
  • if it is timezone-"naive", it is localized to tzinfo
  • if it is already timezone-aware, t is mapped to the given timezone (datetime.datetime.astimezone)
  • If t is None, the current time will be used.
  • If t is a number, it is interpreted as a timestamp.

Any other input will trigger a TypeError.

All returned datetime instances are timezone aware and normalized.

pretty_timedelta(time1, time2=None, resolution=None)

source code 

Calculate time delta between two datetime objects. (the result is somewhat imprecise, only use for prettyprinting).

If either time1 or time2 is None, the current time will be used instead.

format_datetime(t=None, format='%x %X', tzinfo=None, locale=None)

source code 

Format the datetime object t into an unicode string

If t is None, the current time will be used.

The formatting will be done using the given format, which consist of conventional strftime keys. In addition the format can be 'iso8601' to specify the international date format (compliant with RFC 3339).

tzinfo will default to the local timezone if left to None.

format_date(t=None, format='%x', tzinfo=None, locale=None)

source code 
Convenience method for formatting the date part of a datetime object. See format_datetime for more details.

format_time(t=None, format='%X', tzinfo=None, locale=None)

source code 
Convenience method for formatting the time part of a datetime object. See format_datetime for more details.

get_date_format_hint(locale=None)

source code 
Present the default format used by format_date in a human readable form. This is a format that will be recognized by parse_date when reading a date.

get_datetime_format_hint(locale=None)

source code 
Present the default format used by format_datetime in a human readable form. This is a format that will be recognized by parse_date when reading a date.

user_time(req, func, *args, **kwargs)

source code 
A helper function which passes to tzinfo and locale keyword arguments of func using req parameter. It is expected to be used with format_* and parse_date methods in trac.util.datefmt package.
Parameters:
  • req - a instance of Request
  • func - a function which must accept tzinfo and locale keyword arguments
  • args - arguments which pass to func function
  • kwargs - keyword arguments which pass to func function

Variables Details

utcmin

Value:
datetime.datetime(1, 1, 1, 0, 0, tzinfo=<FixedOffset "UTC" 0:00:00>)

utcmax

Value:
datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=<FixedOffse\
t "UTC" 0:00:00>)

all_timezones

Value:
['Africa/Abidjan',
 'Africa/Accra',
 'Africa/Addis_Ababa',
 'Africa/Algiers',
 'Africa/Asmara',
 'Africa/Bamako',
 'Africa/Bangui',
 'Africa/Banjul',
...