[CalendarServer-changes] [3225] CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/ localization.py
source_changes at macosforge.org
source_changes at macosforge.org
Fri Oct 24 12:34:57 PDT 2008
Revision: 3225
http://trac.macosforge.org/projects/calendarserver/changeset/3225
Author: sagen at apple.com
Date: 2008-10-24 12:34:56 -0700 (Fri, 24 Oct 2008)
Log Message:
-----------
Checkpoint -- now generates localized date and time descriptions from calendar components
Modified Paths:
--------------
CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/localization.py
Modified: CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/localization.py
===================================================================
--- CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/localization.py 2008-10-24 02:59:11 UTC (rev 3224)
+++ CalendarServer/branches/users/sagen/localization-3218/twistedcaldav/localization.py 2008-10-24 19:34:56 UTC (rev 3225)
@@ -85,10 +85,9 @@
import gettext
import inspect
+import datetime
-
-
class translationTo(object):
translations = {}
@@ -125,9 +124,64 @@
# Don't swallow exceptions
return False
- def date(self, val):
- # val is either a date (allday) or datetime
+ def date(self, component):
+ dtStart = component.propertyNativeValue("DTSTART")
+ return self.dtDate(dtStart)
+ def time(self, component):
+ """
+ Examples:
+
+ 3:30 PM to 4:30 PM PDT
+ All day
+ 3:30 PM PDT
+ 3:30 PM PDT to 7:30 PM EDT
+ """
+
+ dtStart = component.propertyNativeValue("DTSTART")
+ if isinstance(dtStart, datetime.datetime):
+ tzStart = dtStart.tzname()
+ else:
+ tzStart = None
+ # tzStart = component.getProperty("DTSTART").params().get("TZID", "UTC")
+
+ dtEnd = component.propertyNativeValue("DTEND")
+ if dtEnd:
+ if isinstance(dtEnd, datetime.datetime):
+ tzEnd = dtEnd.tzname()
+ # tzEnd = component.getProperty("DTEND").params().get("TZID", "UTC")
+ duration = dtEnd - dtStart
+ else:
+ tzEnd = tzStart
+ duration = component.propertyNativeValue("DURATION")
+ if duration:
+ dtEnd = dtStart + duration
+ else:
+ if isinstance(dtStart, datetime.date):
+ dtEnd = None
+ duration = datetime.timedelta(days=1)
+ else:
+ dtEnd = dtStart + datetime.timedelta(days=1)
+ dtEnd.hour = dtEnd.minute = dtEnd.second = 0
+ duration = dtEnd - dtStart
+
+ if dtEnd is None:
+ return _("All day")
+
+ if dtStart == dtEnd:
+ return self.dtTime(dtStart)
+
+ return (
+ _("%(startTime)s to %(endTime)s")
+ % {
+ 'startTime' : self.dtTime(dtStart,
+ includeTimezone=(tzStart != tzEnd)),
+ 'endTime' : self.dtTime(dtEnd),
+ }
+ )
+
+
+ def dtDate(self, val):
# Bind to '_' so pygettext.py will pick this up for translation
_ = self.translation.gettext
@@ -141,7 +195,36 @@
}
)
+ def dtTime(self, val, includeTimezone=True):
+ if not isinstance(val, (datetime.datetime, datetime.time)):
+ return None
+ # Bind to '_' so pygettext.py will pick this up for translation
+ _ = self.translation.gettext
+
+ ampm = _("AM") if val.hour < 12 else _("PM")
+ hour12 = val.hour % 12
+ if hour12 == 0:
+ hour12 = 12
+
+ result = (
+ _("%(hour12Number)d:%(minuteNumber)02d %(ampm)s")
+ % {
+ 'hour24Number' : val.hour, # 0-23
+ 'hour12Number' : hour12, # 1-12
+ 'minuteNumber' : val.minute, # 0-59
+ 'ampm' : _(ampm),
+ }
+ )
+
+ if includeTimezone:
+ result += " %s" % (val.tzname())
+
+ return result
+
+
+
+
# The strings below are wrapped in _( ) for the benefit of pygettext. We don't
# actually want them translated until they're used.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081024/8d057ccb/attachment.html>
More information about the calendarserver-changes
mailing list