當前位置: 首頁>>代碼示例>>Python>>正文


Python ServerTime.date方法代碼示例

本文整理匯總了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
開發者ID:LifeCoaching,項目名稱:commcare-hq,代碼行數:32,代碼來源:fixturegenerators.py

示例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
開發者ID:dimagi,項目名稱:commcare-hq,代碼行數:26,代碼來源:fixturegenerators.py

示例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))
開發者ID:ansarbek,項目名稱:commcare-hq,代碼行數:18,代碼來源:dot_submission.py


注:本文中的corehq.util.timezones.conversions.ServerTime.date方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。