当前位置: 首页>>代码示例>>Python>>正文


Python DateTime._tz方法代码示例

本文整理汇总了Python中DateTime.DateTime._tz方法的典型用法代码示例。如果您正苦于以下问题:Python DateTime._tz方法的具体用法?Python DateTime._tz怎么用?Python DateTime._tz使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime.DateTime的用法示例。


在下文中一共展示了DateTime._tz方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getClosestDate

# 需要导入模块: from DateTime import DateTime [as 别名]
# 或者: from DateTime.DateTime import _tz [as 别名]
def getClosestDate(date=None, target_date=None, 
                   precision='month', before=1, strict=1):
  """
  Return the closest date from target_date, at the given precision.
  If date is set, the search is made by making steps of 'precision' duration.
  If target_date is None, it is replaced by current time.
  Precision can be year, month or day
  If before is set to 1, return the closest date before target_date,
  unless the closest date after target_date

  Example :

  date=None, target_date=DateTime('2004/03/12'), precision='month', before=1
    -> return DateTime('2004/03/01')

  date=DateTime('2002/12/14'), target_date=DateTime('2004/03/12'), precision='month', before=1
    -> return DateTime('2004/02/14')

  """
  if target_date is None:
    target_date = DateTime()
  if date is None:
    date = DateTime('2000/01/01')
    date._tz = target_date._tz

  earlier_target_date = target_date - millis

  to_check = { 'day':{'year':1, 'month':1, 'day':1}, 'month':{'year':1, 'month':1}, 'year':{'year':1} }
  diff_value = {}
  diff_value = getIntervalBetweenDates(from_date = date, to_date = target_date, keys=to_check[precision])
  return_date = addToDate(date = date, to_add = diff_value)

  while (strict and return_date - target_date < 0) or \
                      (not strict and \
                      getIntervalBetweenDates(from_date=return_date, to_date=target_date, keys={'day':1})['day'] > 0):
    return_date = addToDate(date = return_date, to_add = { precision:1 })
  if before and DateTime(return_date.Date()) != DateTime(target_date.Date()) :
    return_date = addToDate(date = return_date, to_add = { precision:-1 })

  return return_date
开发者ID:MarkTang,项目名称:erp5,代码行数:42,代码来源:DateUtils.py


注:本文中的DateTime.DateTime._tz方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。