On Tuesday 28 June 2005 01:11, Alen Stanisic wrote: > I have a Date schema field and I would like to control the formatting of > the Date widget input field. The default format seems to be something > like yyyy/mm/dd but I need the Australian format dd/mm/yyyy. Could I > maybe set the format in a page template or the configure.zcml (I tried > the widget zcml directive without much luck). I understand that this > should somehow be handled using locale settings but my understanding of > this stuff is still very basic.
You need to write your own custom widget and register it as the Date widget. The current date widget is not really smart and should be more or less treated as a demo instead of a class ready for production. In your custom widget you could easily use the locale's date parser. >>> from zope.i18n import locales >>> l = zope.i18n.locales.locales.getLocale('en', 'AU') >>> f = l.dates.getFormatter('date', 'medium') >>> f.parse('25/01/1980') datetime.date(1980, 1, 25) Note that the locale object is located in the request: self.request.locale If you want to specify your own format: >>> import zope.i18n.format >>> f = zope.i18n.format.DateTimeFormat('yyyy, dd/MM', ... l.dates.calendars['gregorian']) >>> f.parse('1980, 25/01') datetime.date(1980, 1, 25) > I also noticed that my dc datetime (eg. created) fields are stored in > UTC. I guess this is how it should be in which case any time I need to > display the fields I need to convert to appropriate time zone. Is this > thinking correct or is there maybe a way to tell the zope server what > it's time zone is? Correct. The date should always be stored in UTC or have an assumed timezone as seen below. It is the responsibility of the display code to convert the datetime to a locale and then format it correctly. >>> d = datetime.datetime(2005, 1, 25, 3, 24) >>> import pytz >>> tz = pytz.timezone('Australia/West') >>> dt = d.replace(tzinfo=tz) >>> l.dates.getFormatter('dateTime', 'full').format(dt) u'Tuesday, 25 January 2005 3:24:00 AM +800' Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training _______________________________________________ Zope3-users mailing list Zope3email@example.com http://mail.zope.org/mailman/listinfo/zope3-users