Commits

Jun Omae committed b522533

Support iso8601 with timezone and added a work around to timepicker.

  • Participants
  • Parent commits 36aceb9
  • Branches jquery-ui-datetimepicker-tz

Comments (0)

Files changed (6)

trac/htdocs/js/jquery-ui-addons.js

 				.replace(/m{1,2}/ig, '(\\d?\\d)')
 				.replace(/s{1,2}/ig, '(\\d?\\d)')
 				.replace(/t{1,2}/ig, '(am|pm|a|p)?')
-				.replace(/z{1}/ig, '((\\+|-)\\d\\d\\d\\d)?')
+				.replace(/z{1}/ig, '(z|(\\+|-)\\d\\d:?\\d\\d)?')
 				.replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
 			order = this._getFormatPositions(),
 			treg;

trac/htdocs/js/jquery-ui-i18n.js

     timeText: _("Time"),
     // TRANSLATOR: Time labels in the timepicker
     hourText: _("Hour"), minuteText: _("Minute"), secondText: _("Second"),
+    timezoneText: _("Time Zone"),
     // TRANSLATOR: Link to pick the current time in the timepicker
     currentText: _("Now"),
     // TRANSLATOR: Link that closes the timepicker
     closeText: _("Done"),
     timeFormat: jquery_ui.time_format,
+    separator: jquery_ui.timepicker_separator,
+    timezone: 'Z',
+    showTimezone: jquery_ui.show_timezone,
+    timezoneList: jquery_ui.timezone_list,
     ampm: jquery_ui.ampm,
     showSecond: true
   });

trac/locale/ja/LC_MESSAGES/messages-js.po

 msgstr ""
 "Project-Id-Version: Trac 0.12\n"
 "Report-Msgid-Bugs-To: trac-dev@googlegroups.com\n"
-"POT-Creation-Date: 2011-07-23 19:45+0900\n"
+"POT-Creation-Date: 2011-07-26 20:08+0900\n"
 "PO-Revision-Date: 2010-05-25 18:45+0900\n"
 "Last-Translator: Jun Omae <jun66j5@gmail.com>\n"
 "Language-Team: ja <LL@li.org>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
-"Generated-By: Babel 0.9.6\n"
+"Generated-By: Babel 1.0dev-r607\n"
 
 #: trac/htdocs/js/blame.js:84
 msgid "(no changeset information)"
 
 #. TRANSLATOR: Link that closes the datepicker
 #. TRANSLATOR: Link that closes the timepicker
-#: trac/htdocs/js/jquery-ui-i18n.js:7 trac/htdocs/js/jquery-ui-i18n.js:38
+#: trac/htdocs/js/jquery-ui-i18n.js:7 trac/htdocs/js/jquery-ui-i18n.js:39
 msgid "Done"
 msgstr "閉じる"
 
 msgid "Second"
 msgstr "秒"
 
+#: trac/htdocs/js/jquery-ui-i18n.js:35
+msgid "Time Zone"
+msgstr "タイムゾーン"
+
 #. TRANSLATOR: Link to pick the current time in the timepicker
-#: trac/htdocs/js/jquery-ui-i18n.js:36
+#: trac/htdocs/js/jquery-ui-i18n.js:37
 msgid "Now"
 msgstr "現時刻"
 

trac/locale/messages-js.pot

 msgstr ""
 "Project-Id-Version: Trac 0.13\n"
 "Report-Msgid-Bugs-To: trac-dev@googlegroups.com\n"
-"POT-Creation-Date: 2011-07-23 19:45+0900\n"
+"POT-Creation-Date: 2011-07-26 20:08+0900\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=utf-8\n"
 "Content-Transfer-Encoding: 8bit\n"
-"Generated-By: Babel 0.9.6\n"
+"Generated-By: Babel 1.0dev-r607\n"
 
 #: trac/htdocs/js/blame.js:84
 msgid "(no changeset information)"
 
 #. TRANSLATOR: Link that closes the datepicker
 #. TRANSLATOR: Link that closes the timepicker
-#: trac/htdocs/js/jquery-ui-i18n.js:7 trac/htdocs/js/jquery-ui-i18n.js:38
+#: trac/htdocs/js/jquery-ui-i18n.js:7 trac/htdocs/js/jquery-ui-i18n.js:39
 msgid "Done"
 msgstr ""
 
 msgid "Second"
 msgstr ""
 
+#: trac/htdocs/js/jquery-ui-i18n.js:35
+msgid "Time Zone"
+msgstr ""
+
 #. TRANSLATOR: Link to pick the current time in the timepicker
-#: trac/htdocs/js/jquery-ui-i18n.js:36
+#: trac/htdocs/js/jquery-ui-i18n.js:37
 msgid "Now"
 msgstr ""
 

trac/util/datefmt.py

 def get_time_format_jquery_ui(locale):
     """Get the time format for the jQuery UI timepicker addon."""
     if locale == 'iso8601':
-        return 'hh:mm:ss'   # XXX timepicker doesn't support 'ISO_8601'
+        return 'hh:mm:ssz'  # XXX timepicker doesn't support 'ISO_8601'
     if babel and locale:
         values = {'h': 'h', 'hh': 'hh', 'H': 'h', 'HH': 'hh',
                   'm': 'm', 'mm': 'mm', 's': 's', 'ss': 'ss',
     return tmpl.replace('23', 'hh', 1).replace('11', 'hh', 1) \
                .replace('59', 'mm', 1).replace('58', 'ss', 1)
 
+def get_timezone_list_jquery_ui(t=None):
+    """Get timezone list for jQuery timepicker addon"""
+    t = datetime.now(utc) if t is None else utc.localize(t)
+    zones = set(t.astimezone(get_timezone(tz)).strftime('%z')
+                for tz in all_timezones)
+    return [{'value': 'Z', 'label': '+00:00'} \
+            if zone == '+0000' else zone[:-2] + ':' + zone[-2:]
+            for zone in sorted(zones, key=lambda tz: int(tz))]
+
 def is_24_hours(locale):
     """Returns `True` for 24 hour time formats."""
     if locale == 'iso8601':
     def get_timezone(tzname):
         """Fetch timezone instance by name or return `None`"""
         return _tzmap.get(tzname)
-

trac/web/chrome.py

                               get_date_format_jquery_ui, is_24_hours, \
                               get_time_format_jquery_ui, user_time, \
                               get_month_names_jquery_ui, \
-                              get_day_names_jquery_ui
+                              get_day_names_jquery_ui, \
+                              get_timezone_list_jquery_ui
 from trac.util.translation import _, get_available_locales
 from trac.web.api import IRequestHandler, ITemplateStreamFilter, HTTPNotFound
 from trac.web.href import Href
         add_stylesheet(req, 'common/css/jquery-ui-addons.css')
         first_day = (req.locale.first_week_day + 1) % 7 \
                     if req.locale and req.locale.territory else 0
+        is_iso8601 = req.lc_time == 'iso8601'
         add_script_data(req, jquery_ui={
             'month_names': get_month_names_jquery_ui(req),
             'day_names': get_day_names_jquery_ui(req),
             'date_format': get_date_format_jquery_ui(req.lc_time),
             'time_format': get_time_format_jquery_ui(req.lc_time),
             'ampm': not is_24_hours(req.lc_time),
-            'first_week_day': first_day})
+            'first_week_day': first_day,
+            'timepicker_separator': 'T' if is_iso8601 else ' ',
+            'show_timezone': is_iso8601,
+            'timezone_list': get_timezone_list_jquery_ui() \
+                             if is_iso8601 else [],
+        })
         add_script(req, 'common/js/jquery-ui-i18n.js')
 
     # Template filters