本文整理匯總了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))