コード例 #1
0
 def test_strftime_pre_1900(self):
     """tests that we can strftime on times before 1900 (patching 2.7 bug)"""
     # half way through the cannons, on the battle day
     overture_date = datetime_tz.datetime_tz(1812, 9, 10, 12, 7, 30, tzinfo=pytz.timezone("Europe/Moscow"))
     overture_datestr = overture_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert overture_datestr == "1812-09-10 12:07:30+MSK"
     else:
         # Back then, there were no timezones...
         assert overture_datestr == "1812-09-10 12:07:30+LMT"
     overture_timetuple = overture_date.utctimetuple()
     overture_timestr = time.strftime("%Y-%m-%d %H:%M:%S", overture_timetuple)
     assert overture_timestr == "1812-09-10 09:37:30"
     # also test after 1900 to make sure that's as before
     renzetti_date = overture_date.replace(year=1912)
     renzetti_datestr = renzetti_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     assert renzetti_datestr == "1912-09-10 12:07:30+MMT"
     renzetti_timetuple = renzetti_date.utctimetuple()
     renzetti_timestr = time.strftime("%Y-%m-%d %H:%M:%S", renzetti_timetuple)
     assert renzetti_timestr == "1912-09-10 09:37:30"
     # and let's handle the 0-99 and 100-999 cases that are different on different python versions
     rufus_date = overture_date.replace(year=12)
     rufus_datestr = rufus_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert rufus_datestr == "12-09-10 12:07:30+MSK"
     else:
         assert rufus_datestr == "12-09-10 12:07:30+LMT"
     rufus_timetuple = rufus_date.utctimetuple()
     rufus_timestr = time.strftime("%Y-%m-%d %H:%M:%S", rufus_timetuple)
     assert rufus_timestr == "12-09-10 09:37:30"
     ordono_date = overture_date.replace(year=912)
     ordono_datestr = ordono_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert ordono_datestr == "912-09-10 12:07:30+MSK"
     else:
         assert ordono_datestr == "912-09-10 12:07:30+LMT"
     ordono_timetuple = ordono_date.utctimetuple()
     ordono_timestr = time.strftime("%Y-%m-%d %H:%M:%S", ordono_timetuple)
     assert ordono_timestr == "912-09-10 09:37:30"
     # just for fun, and to ensure year matching doesn't match the wrong stuff
     repetitive_date = datetime_tz.datetime_tz(1111,11,11,11,11,11, tzinfo=pytz.UTC)
     repetitive_datestr = repetitive_date.strftime("%d%Y%m%H%Y%M%S1%Y1%y")
     assert repetitive_datestr == "11111111111111111111111111"
     repetitive_timetuple = repetitive_date.utctimetuple()
     repetitive_timestr = time.strftime("1%Y1%d%m%H%Y%M%S%Y%y", repetitive_timetuple)
     assert repetitive_timestr == "11111111111111111111111111"
     # broken with 4-char skip
     broken_date = datetime_tz.datetime_tz(1119,11,19)
     broken_datestr = broken_date.strftime("%d%Y")
     assert broken_datestr == "191119"
     broken_timetuple = broken_date.utctimetuple()
     broken_timestr = time.strftime("%y%Y", broken_timetuple)
     assert broken_timestr == "191119"
コード例 #2
0
def test_compare_less():
    a = datetime.datetime(2012,3,4,3,2,3)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert b < a
    assert b <= a
    a = datetime.datetime(2012,3,3,3,2,3)
    assert a < b
    assert a <= b
コード例 #3
0
def test_compare_greater():
    a = datetime.datetime(2012,3,4,3,2,3)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert a > b
    assert a >= b
    a = datetime.datetime(2012,3,3,3,2,3)
    assert b > a
    assert b >= a
コード例 #4
0
def test_instantiation():
    a = datetime.datetime(2012, 3, 4, 3, 2, 3)
    c = None
    try:
        c = datetime_tz.datetime_tz(a)
    except TypeError as e:
        if not e.message == "Must specify a timezone!":
            c = False
    assert c is None
コード例 #5
0
ファイル: test_datetime_tz.py プロジェクト: dee42/virtualtime
def test_compare_less():
    a = datetime.datetime(2012,3,4,3,2,3)
    if not PY2:
        a = localize(a)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert b < a
    assert b <= a
    a = datetime.datetime(2012,3,3,3,2,3)
    if not PY2:
        a = localize(a)
    assert a < b
    assert a <= b
コード例 #6
0
ファイル: test_datetime_tz.py プロジェクト: dee42/virtualtime
def test_compare_greater():
    a = datetime.datetime(2012,3,4,3,2,3)
    if not PY2:
        a = localize(a)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert a > b
    assert a >= b
    a = datetime.datetime(2012,3,3,3,2,3)
    if not PY2:
        a = localize(a)
    assert b > a
    assert b >= a
コード例 #7
0
ファイル: TimeUtils.py プロジェクト: matthewhampton/j5basic
def timetuple_to_datetime(t):
    """Convert a timetuple to a datetime object.
       """
    return datetime_tz.datetime_tz(*(t[:6]))
コード例 #8
0
def timetuple_to_datetime(t):
    """Convert a timetuple to a datetime object.
       """
    return datetime_tz.datetime_tz(*(t[:6]))
コード例 #9
0
def test_compare_notequal():
    a = datetime.datetime(2012,3,4,3,2,3)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert a != b
    assert b != a
コード例 #10
0
def test_compare_tz_second():
    a = datetime.datetime(2012,3,4,1,2,3)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert b == a
コード例 #11
0
def test_compare_tz_first():
    a = datetime.datetime(2012,3,4,1,2,3)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert a == b
コード例 #12
0
ファイル: test_datetime_tz.py プロジェクト: dee42/virtualtime
def test_compare_tz_second():
    a = datetime.datetime(2012,3,4,1,2,3)
    if not PY2:
        a = localize(a)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert b == a
コード例 #13
0
ファイル: test_datetime_tz.py プロジェクト: dee42/virtualtime
def test_compare_tz_first():
    a = datetime.datetime(2012,3,4,1,2,3)
    if not PY2:
        a = localize(a)
    b = datetime_tz.datetime_tz(2012,3,4,1,2,3)
    assert a == b
コード例 #14
0
 def test_strftime_pre_1900(self):
     """tests that we can strftime on times before 1900 (patching 2.7 bug)"""
     # half way through the cannons, on the battle day
     overture_date = datetime_tz.datetime_tz(
         1812, 9, 10, 12, 7, 30, tzinfo=pytz.timezone("Europe/Moscow"))
     overture_datestr = overture_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert overture_datestr == "1812-09-10 12:07:30+MSK"
     else:
         # Back then, there were no timezones...
         assert overture_datestr == "1812-09-10 12:07:30+LMT"
     overture_timetuple = overture_date.utctimetuple()
     overture_timestr = time.strftime("%Y-%m-%d %H:%M:%S",
                                      overture_timetuple)
     assert overture_timestr == "1812-09-10 09:37:30"
     # also test after 1900 to make sure that's as before
     renzetti_date = overture_date.replace(year=1912)
     renzetti_datestr = renzetti_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     assert renzetti_datestr == "1912-09-10 12:07:30+MMT"
     renzetti_timetuple = renzetti_date.utctimetuple()
     renzetti_timestr = time.strftime("%Y-%m-%d %H:%M:%S",
                                      renzetti_timetuple)
     assert renzetti_timestr == "1912-09-10 09:37:30"
     # and let's handle the 0-99 and 100-999 cases that are different on different python versions
     rufus_date = overture_date.replace(year=12)
     rufus_datestr = rufus_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert rufus_datestr == "12-09-10 12:07:30+MSK"
     else:
         assert rufus_datestr == "12-09-10 12:07:30+LMT"
     rufus_timetuple = rufus_date.utctimetuple()
     rufus_timestr = time.strftime("%Y-%m-%d %H:%M:%S", rufus_timetuple)
     assert rufus_timestr == "12-09-10 09:37:30"
     ordono_date = overture_date.replace(year=912)
     ordono_datestr = ordono_date.strftime("%Y-%m-%d %H:%M:%S+%Z")
     if sys.version_info.major < 3:
         assert ordono_datestr == "912-09-10 12:07:30+MSK"
     else:
         assert ordono_datestr == "912-09-10 12:07:30+LMT"
     ordono_timetuple = ordono_date.utctimetuple()
     ordono_timestr = time.strftime("%Y-%m-%d %H:%M:%S", ordono_timetuple)
     assert ordono_timestr == "912-09-10 09:37:30"
     # just for fun, and to ensure year matching doesn't match the wrong stuff
     repetitive_date = datetime_tz.datetime_tz(1111,
                                               11,
                                               11,
                                               11,
                                               11,
                                               11,
                                               tzinfo=pytz.UTC)
     repetitive_datestr = repetitive_date.strftime("%d%Y%m%H%Y%M%S1%Y1%y")
     assert repetitive_datestr == "11111111111111111111111111"
     repetitive_timetuple = repetitive_date.utctimetuple()
     repetitive_timestr = time.strftime("1%Y1%d%m%H%Y%M%S%Y%y",
                                        repetitive_timetuple)
     assert repetitive_timestr == "11111111111111111111111111"
     # broken with 4-char skip
     broken_date = datetime_tz.datetime_tz(1119, 11, 19)
     broken_datestr = broken_date.strftime("%d%Y")
     assert broken_datestr == "191119"
     broken_timetuple = broken_date.utctimetuple()
     broken_timestr = time.strftime("%y%Y", broken_timetuple)
     assert broken_timestr == "191119"