本文整理汇总了Python中corehq.util.timezones.conversions.ServerTime.date方法的典型用法代码示例。如果您正苦于以下问题:Python ServerTime.date方法的具体用法?Python ServerTime.date怎么用?Python ServerTime.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.util.timezones.conversions.ServerTime
的用法示例。
在下文中一共展示了ServerTime.date方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: should_sync
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import date [as 别名]
def should_sync(domain, last_sync, utcnow=None):
# definitely sync if we haven't synced before
if not last_sync or not last_sync.date:
return True
# utcnow only used in tests to mock other times
utcnow = utcnow or datetime.utcnow()
try:
timezone = domain.get_default_timezone()
except pytz.UnknownTimeZoneError:
timezone = utc
_assert = soft_assert(to=['droberts' + '@' + 'dimagi.com'])
last_sync_utc = last_sync.date
if not _assert(last_sync_utc.tzinfo is None,
'last_sync.date should be an offset-naive dt'):
last_sync_utc = UserTime(last_sync_utc).server_time().done()
# check if user has already synced today (in local timezone).
# Indicators only change daily.
last_sync_local = ServerTime(last_sync_utc).user_time(timezone).done()
current_date_local = ServerTime(utcnow).user_time(timezone).done()
if current_date_local.date() != last_sync_local.date():
return True
return False
示例2: should_sync
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import date [as 别名]
def should_sync(domain, last_sync, utcnow=None):
# definitely sync if we haven't synced before
if not last_sync or not last_sync.date:
return True
# utcnow only used in tests to mock other times
utcnow = utcnow or datetime.utcnow()
try:
timezone = domain.get_default_timezone()
except pytz.UnknownTimeZoneError:
timezone = utc
last_sync_utc = last_sync.date
# check if user has already synced today (in local timezone).
# Indicators only change daily.
last_sync_local = ServerTime(last_sync_utc).user_time(timezone).done()
current_date_local = ServerTime(utcnow).user_time(timezone).done()
if current_date_local.date() != last_sync_local.date():
return True
return False
示例3: check_obs_props
# 需要导入模块: from corehq.util.timezones.conversions import ServerTime [as 别名]
# 或者: from corehq.util.timezones.conversions.ServerTime import date [as 别名]
def check_obs_props(obs, props):
for k, v in props.items():
if k.endswith("_date"):
# datetime check
obs_datetime = getattr(obs, k)
val_datetime = dateutil.parser.parse(v)
if k in ('completed_date', 'created_date'):
obs_datetime = ServerTime(obs_datetime).user_time(PACT_TIMEZONE).done()
obs_date = obs_datetime.date()
val_date = val_datetime.date()
self.assertEquals(obs_date, val_date)
else:
self.assertEquals(getattr(obs, k), v,
msg="Error, observation %s\n\t%s didn't match: %s != %s" % (
json.dumps(obs.to_json(), indent=4), k, getattr(obs, k),
v))