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


Python date.max方法代碼示例

本文整理匯總了Python中datetime.date.max方法的典型用法代碼示例。如果您正苦於以下問題:Python date.max方法的具體用法?Python date.max怎麽用?Python date.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datetime.date的用法示例。


在下文中一共展示了date.max方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cast_date

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def cast_date(value, connection):
    """Cast a date value."""
    # The output format depends on the server setting DateStyle.  The default
    # setting ISO and the setting for German are actually unambiguous.  The
    # order of days and months in the other two settings is however ambiguous,
    # so at least here we need to consult the setting to properly parse values.
    if value == '-infinity':
        return date.min
    if value == 'infinity':
        return date.max
    value = value.split()
    if value[-1] == 'BC':
        return date.min
    value = value[0]
    if len(value) > 10:
        return date.max
    fmt = connection.date_format()
    return datetime.strptime(value, fmt).date() 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:20,代碼來源:pg.py

示例2: cast_timestamp

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def cast_timestamp(value, connection):
    """Cast a timestamp value."""
    if value == '-infinity':
        return datetime.min
    if value == 'infinity':
        return datetime.max
    value = value.split()
    if value[-1] == 'BC':
        return datetime.min
    fmt = connection.date_format()
    if fmt.endswith('-%Y') and len(value) > 2:
        value = value[1:5]
        if len(value[3]) > 4:
            return datetime.max
        fmt = ['%d %b' if fmt.startswith('%d') else '%b %d',
            '%H:%M:%S.%f' if len(value[2]) > 8 else '%H:%M:%S', '%Y']
    else:
        if len(value[0]) > 10:
            return datetime.max
        fmt = [fmt, '%H:%M:%S.%f' if len(value[1]) > 8 else '%H:%M:%S']
    return datetime.strptime(' '.join(value), ' '.join(fmt)) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:23,代碼來源:pg.py

示例3: testTruncateRestart

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def testTruncateRestart(self):
        truncate = self.db.truncate
        self.assertRaises(TypeError, truncate, 'test_table', restart='invalid')
        query = self.db.query
        self.createTable('test_table', 'n serial, t text')
        for n in range(3):
            query("insert into test_table (t) values ('test')")
        q = "select count(n), min(n), max(n) from test_table"
        r = query(q).getresult()[0]
        self.assertEqual(r, (3, 1, 3))
        truncate('test_table')
        r = query(q).getresult()[0]
        self.assertEqual(r, (0, None, None))
        for n in range(3):
            query("insert into test_table (t) values ('test')")
        r = query(q).getresult()[0]
        self.assertEqual(r, (3, 4, 6))
        truncate('test_table', restart=True)
        r = query(q).getresult()[0]
        self.assertEqual(r, (0, None, None))
        for n in range(3):
            query("insert into test_table (t) values ('test')")
        r = query(q).getresult()[0]
        self.assertEqual(r, (3, 1, 3)) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:26,代碼來源:test_classic_dbwrapper.py

示例4: testDate

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def testDate(self):
        query = self.db.query
        for datestyle in ('ISO', 'Postgres, MDY', 'Postgres, DMY',
                'SQL, MDY', 'SQL, DMY', 'German'):
            self.db.set_parameter('datestyle', datestyle)
            d = date(2016, 3, 14)
            q = "select $1::date"
            r = query(q, (d,)).getresult()[0][0]
            self.assertIsInstance(r, date)
            self.assertEqual(r, d)
            q = "select '10000-08-01'::date, '0099-01-08 BC'::date"
            r = query(q).getresult()[0]
            self.assertIsInstance(r[0], date)
            self.assertIsInstance(r[1], date)
            self.assertEqual(r[0], date.max)
            self.assertEqual(r[1], date.min)
        q = "select 'infinity'::date, '-infinity'::date"
        r = query(q).getresult()[0]
        self.assertIsInstance(r[0], date)
        self.assertIsInstance(r[1], date)
        self.assertEqual(r[0], date.max)
        self.assertEqual(r[1], date.min) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:24,代碼來源:test_classic_dbwrapper.py

示例5: test_timespan_list

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def test_timespan_list():
    x = N([])
    assert x._t == _k.KN
    d = timedelta(1, 2, 3)
    x = N([None, d, timedelta.max, timedelta.min])
    assert eq(x, q('0N 1D00:00:02.000003 0W -0Wn')) 
開發者ID:KxSystems,項目名稱:pyq,代碼行數:8,代碼來源:test_k.py

示例6: test_date_and_month_extremes

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def test_date_and_month_extremes():
    dates = [date.min, date.max]
    assert eq(M(dates), q('0001.01 9999.12m'))
    assert eq(D(dates), q('0001.01.01 9999.12.31')) 
開發者ID:KxSystems,項目名稱:pyq,代碼行數:6,代碼來源:test_k.py

示例7: __setitem__

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def __setitem__(self, key, value):
        try:
            self.cache.pop(key)
        except KeyError:
            if len(self.cache) >= self.capacity:
                self.cache.popitem(last=False)
        self.cache[key] = value


# Conceptually if date.max is infinity, then DateWithFuture.future() is "right before" infinity.
# In practice, date.max is year 9999 and DateWithFuture.future() is year 5000 -
# we then manipulate the comparison operators to make DateWithFuture.future() behave
# as though date.max - epsilon < DateWithFuture.future() < date.max. 
開發者ID:codeforpdx,項目名稱:recordexpungPDX,代碼行數:15,代碼來源:util.py

示例8: max

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def max():
        return DateWithFuture(9999, 12, 31) 
開發者ID:codeforpdx,項目名稱:recordexpungPDX,代碼行數:4,代碼來源:util.py

示例9: __lt__

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def __lt__(self, other):
        if isinstance(other, DateWithFuture):
            if self.date == other.date == DateWithFuture.FUTURE:
                today = date_class.today()
                return today + self.relative < today + other.relative
            elif self.date == DateWithFuture.FUTURE:
                return other.date == date_class.max
            elif other.date == DateWithFuture.FUTURE:
                return self.date != date_class.max
            else:
                return self.date < other.date
        return NotImplemented 
開發者ID:codeforpdx,項目名稱:recordexpungPDX,代碼行數:14,代碼來源:util.py

示例10: cast_timestamptz

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def cast_timestamptz(value, connection):
    """Cast a timestamptz value."""
    if value == '-infinity':
        return datetime.min
    if value == 'infinity':
        return datetime.max
    value = value.split()
    if value[-1] == 'BC':
        return datetime.min
    fmt = connection.date_format()
    if fmt.endswith('-%Y') and len(value) > 2:
        value = value[1:]
        if len(value[3]) > 4:
            return datetime.max
        fmt = ['%d %b' if fmt.startswith('%d') else '%b %d',
            '%H:%M:%S.%f' if len(value[2]) > 8 else '%H:%M:%S', '%Y']
        value, tz = value[:-1], value[-1]
    else:
        if fmt.startswith('%Y-'):
            tz = _re_timezone.match(value[1])
            if tz:
                value[1], tz = tz.groups()
            else:
                tz = '+0000'
        else:
            value, tz = value[:-1], value[-1]
        if len(value[0]) > 10:
            return datetime.max
        fmt = [fmt, '%H:%M:%S.%f' if len(value[1]) > 8 else '%H:%M:%S']
    if _has_timezone:
        value.append(_timezone_as_offset(tz))
        fmt.append('%z')
        return datetime.strptime(' '.join(value), ' '.join(fmt))
    return datetime.strptime(' '.join(value), ' '.join(fmt)).replace(
        tzinfo=_get_timezone(tz)) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:37,代碼來源:pg.py

示例11: testTimestamp

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def testTimestamp(self):
        query = self.db.query
        for datestyle in ('ISO', 'Postgres, MDY', 'Postgres, DMY',
                'SQL, MDY', 'SQL, DMY', 'German'):
            self.db.set_parameter('datestyle', datestyle)
            d = datetime(2016, 3, 14)
            q = "select $1::timestamp"
            r = query(q, (d,)).getresult()[0][0]
            self.assertIsInstance(r, datetime)
            self.assertEqual(r, d)
            d = datetime(2016, 3, 14, 15, 9, 26)
            q = "select $1::timestamp"
            r = query(q, (d,)).getresult()[0][0]
            self.assertIsInstance(r, datetime)
            self.assertEqual(r, d)
            d = datetime(2016, 3, 14, 15, 9, 26, 535897)
            q = "select $1::timestamp"
            r = query(q, (d,)).getresult()[0][0]
            self.assertIsInstance(r, datetime)
            self.assertEqual(r, d)
            q = ("select '10000-08-01 AD'::timestamp,"
                " '0099-01-08 BC'::timestamp")
            r = query(q).getresult()[0]
            self.assertIsInstance(r[0], datetime)
            self.assertIsInstance(r[1], datetime)
            self.assertEqual(r[0], datetime.max)
            self.assertEqual(r[1], datetime.min)
        q = "select 'infinity'::timestamp, '-infinity'::timestamp"
        r = query(q).getresult()[0]
        self.assertIsInstance(r[0], datetime)
        self.assertIsInstance(r[1], datetime)
        self.assertEqual(r[0], datetime.max)
        self.assertEqual(r[1], datetime.min) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:35,代碼來源:test_classic_dbwrapper.py

示例12: testTimestamptz

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def testTimestamptz(self):
        query = self.db.query
        timezones = dict(CET=1, EET=2, EST=-5, UTC=0)
        for timezone in sorted(timezones):
            tz = '%+03d00' % timezones[timezone]
            try:
                tzinfo = datetime.strptime(tz, '%z').tzinfo
            except ValueError:  # Python < 3.2
                tzinfo = pg._get_timezone(tz)
            self.db.set_parameter('timezone', timezone)
            for datestyle in ('ISO', 'Postgres, MDY', 'Postgres, DMY',
                    'SQL, MDY', 'SQL, DMY', 'German'):
                self.db.set_parameter('datestyle', datestyle)
                d = datetime(2016, 3, 14, tzinfo=tzinfo)
                q = "select $1::timestamptz"
                r = query(q, (d,)).getresult()[0][0]
                self.assertIsInstance(r, datetime)
                self.assertEqual(r, d)
                d = datetime(2016, 3, 14, 15, 9, 26, tzinfo=tzinfo)
                q = "select $1::timestamptz"
                r = query(q, (d,)).getresult()[0][0]
                self.assertIsInstance(r, datetime)
                self.assertEqual(r, d)
                d = datetime(2016, 3, 14, 15, 9, 26, 535897, tzinfo)
                q = "select $1::timestamptz"
                r = query(q, (d,)).getresult()[0][0]
                self.assertIsInstance(r, datetime)
                self.assertEqual(r, d)
                q = ("select '10000-08-01 AD'::timestamptz,"
                    " '0099-01-08 BC'::timestamptz")
                r = query(q).getresult()[0]
                self.assertIsInstance(r[0], datetime)
                self.assertIsInstance(r[1], datetime)
                self.assertEqual(r[0], datetime.max)
                self.assertEqual(r[1], datetime.min)
        q = "select 'infinity'::timestamptz, '-infinity'::timestamptz"
        r = query(q).getresult()[0]
        self.assertIsInstance(r[0], datetime)
        self.assertIsInstance(r[1], datetime)
        self.assertEqual(r[0], datetime.max)
        self.assertEqual(r[1], datetime.min) 
開發者ID:wang502,項目名稱:slack-sql,代碼行數:43,代碼來源:test_classic_dbwrapper.py

示例13: isoformat

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def isoformat(self, default=date.max):
        return "%s-%02d-%02d" % (
            self.year,
            int(self.month or default.month),
            int(self.day or default.day),
        ) 
開發者ID:ixc,項目名稱:python-edtf,代碼行數:8,代碼來源:parser_classes.py

示例14: _strict_date

# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import max [as 別名]
def _strict_date(self, lean):
        if lean == LATEST:
            return max([x._strict_date(lean) for x in self.objects])
        else:
            return min([x._strict_date(lean) for x in self.objects]) 
開發者ID:ixc,項目名稱:python-edtf,代碼行數:7,代碼來源:parser_classes.py


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