from datetime import datetime from trac.util.datefmt import format_date, parse_date, timezone from trac.wiki.macros import WikiMacroBase from trac.web.api import Request from trac.util.text import to_unicode class DateMacro(WikiMacroBase): """Displays the date/time in the format selected by the user The date or date/time must be in ISO8601 format """ revision = "$Rev$" url = "$URL$" def expand_macro(self, formatter, name, args): t = parse_date(args) fmt = formatter.req.session.get('format') or 'iso8601' fmt = to_unicode(fmt).encode('ascii', 'replace') tz = timezone(formatter.req.session['tz']) return format_date(t, fmt, tz)