本文整理汇总了Python中DateTime.DateTime.DateTime.timezoneNaive方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime.timezoneNaive方法的具体用法?Python DateTime.timezoneNaive怎么用?Python DateTime.timezoneNaive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTime.DateTime.DateTime
的用法示例。
在下文中一共展示了DateTime.timezoneNaive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: strptime
# 需要导入模块: from DateTime.DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime.DateTime import timezoneNaive [as 别名]
def strptime(context, value):
"""given a string, this function tries to return a DateTime.DateTime object
with the date formats from i18n translations
"""
val = ""
for fmt in ['date_format_long', 'date_format_short']:
fmtstr = context.translate(fmt, domain='bika', mapping={})
fmtstr = fmtstr.replace(r"${", '%').replace('}', '')
try:
val = _strptime(value, fmtstr)
except ValueError:
continue
try:
val = DateTime(*list(val)[:-6])
except DateTimeError:
val = ""
if val.timezoneNaive():
# Use local timezone for tz naive strings
# see http://dev.plone.org/plone/ticket/10141
zone = val.localZone(safelocaltime(val.timeTime()))
parts = val.parts()[:-1] + (zone,)
val = DateTime(*parts)
break
else:
try:
# The following will handle an rfc822 string.
value = value.split(" +", 1)[0]
val = DateTime(value)
except:
logger.warning("DateTimeField failed to format date "
"string '%s' with '%s'" % (value, fmtstr))
return val
示例2: set
# 需要导入模块: from DateTime.DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime.DateTime import timezoneNaive [as 别名]
def set(self, instance, value, **kwargs):
"""
Check if value is an actual date/time value. If not, attempt
to convert it to one; otherwise, set to None. Assign all
properties passed as kwargs to object.
"""
val = value
if not value:
val = None
elif not isinstance(value, DateTime):
for fmt in ['date_format_long', 'date_format_short']:
fmtstr = instance.translate(fmt, domain='bika', mapping={})
fmtstr = fmtstr.replace(r"${", '%').replace('}', '')
try:
val = strptime(value, fmtstr)
except ValueError:
continue
try:
val = DateTime(*list(val)[:-6])
except DateTimeError:
val = None
if val.timezoneNaive():
# Use local timezone for tz naive strings
# see http://dev.plone.org/plone/ticket/10141
zone = val.localZone(safelocaltime(val.timeTime()))
parts = val.parts()[:-1] + (zone,)
val = DateTime(*parts)
break
else:
logger.warning("DateTimeField failed to format date "
"string '%s' with '%s'" % (value, fmtstr))
super(DateTimeField, self).set(instance, val, **kwargs)