def value_to_html(self, value, options): if not value or len(value) < 10: return '' lang = self.user_lang() locale = babel.Locale.parse(lang.code) if isinstance(value, basestring): value = fields.Datetime.from_string(value[:10]) if options and 'format' in options: pattern = options['format'] else: strftime_pattern = lang.date_format pattern = posix_to_ldml(strftime_pattern, locale=locale) return babel.dates.format_date(value, format=pattern, locale=locale)
def value_to_html(self, value, field, options=None): if not value or len(value) < 10: return '' lang = self.user_lang() locale = babel.Locale.parse(lang.code) if isinstance(value, basestring): value = fields.Datetime.from_string(value[:10]) if options and 'format' in options: pattern = options['format'] else: strftime_pattern = lang.date_format pattern = posix_to_ldml(strftime_pattern, locale=locale) return babel.dates.format_date(value, format=pattern, locale=locale)
def value_to_html(self, value, field, options=None): if not value: return '' lang = self.user_lang() locale = babel.Locale.parse(lang.code) if isinstance(value, basestring): value = fields.Datetime.from_string(value) value = fields.Datetime.context_timestamp(self, value) if options and 'format' in options: pattern = options['format'] else: strftime_pattern = (u"%s %s" % (lang.date_format, lang.time_format)) pattern = posix_to_ldml(strftime_pattern, locale=locale) if options and options.get('hide_seconds'): pattern = pattern.replace(":ss", "").replace(":s", "") return unicodifier(babel.dates.format_datetime(value, format=pattern, locale=locale))