Since version 0.10, Trac mainly uses datetime.datetime objects for handling date and time values. This enables us to properly deal with timezones so that time can be shown in the user’s own local time.
From “anything” to a datetime:
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 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)
Any other input will trigger a TypeError.
All returned datetime instances are timezone aware and normalized.
A datetime can be converted to milliseconds and microseconds timestamps. The latter is the preferred representation for dates and times values for storing them in the database, since Trac 0.12.
Return the corresponding POSIX timestamp
Besides to_datetime, there’s a specialized conversion from microseconds timestamps to datetime:
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 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.
Derivatives:
Convenience method for formatting the date part of a datetime object. See format_datetime for more details.
Convenience method for formatting the time part of a datetime object. See format_datetime for more details.
Propose suggestion for date/time input format:
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.
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.
Formatting and parsing according to user preferences:
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: |
|
---|
Get the date format for the jQuery UI datepicker library.
Get the time format for the jQuery UI timepicker addon.
Get the day names for the jQuery UI datepicker library
Get first week day for jQuery date picker
Get the month names for the jQuery UI datepicker library
Get timezone list for jQuery timepicker addon
A global LocalTimezone instance.
A ‘local’ time zone implementation
List of all available timezones. If pytz is installed, this corresponds to a rich variety of “official” timezones, otherwise this corresponds to FixedOffset instances, ranging from GMT -12:00 to GMT +13:00.
Fetch timezone instance by name or raise KeyError
Fixed offset in minutes east from UTC.