Ejemplo n.º 1
0
    def test_parse_timestamp(self):
        utc = build_utcoffset("UTC", timedelta(hours=0))
        result = Ask._parse_timestamp("2017-07-08T07:38:00Z")
        self.assertEqual(datetime(2017, 7, 8, 7, 38, 0, 0, utc), result)

        result = Ask._parse_timestamp(1234567890)
        self.assertEqual(datetime(2009, 2, 13, 23, 31, 30), result)

        with self.assertRaises(ValueError):
            Ask._parse_timestamp(None)
Ejemplo n.º 2
0
    def test_pickle(self):
        #Make sure timezone objects are pickleable
        testutcoffset = build_utcoffset('UTC', datetime.timedelta(0))

        utcoffsetpickle = pickle.dumps(testutcoffset)

        resultutcoffset = pickle.loads(utcoffsetpickle)

        self.assertEqual(resultutcoffset._name, testutcoffset._name)
        self.assertEqual(resultutcoffset._utcdelta, testutcoffset._utcdelta)
Ejemplo n.º 3
0
    def test_parse_timestamp(self):
        utc = build_utcoffset('UTC', timedelta(hours=0))
        result = Ask._parse_timestamp('2017-07-08T07:38:00Z')
        self.assertEqual(datetime(2017, 7, 8, 7, 38, 0, 0, utc), result)

        result = Ask._parse_timestamp(1234567890)
        self.assertEqual(datetime(2009, 2, 13, 23, 31, 30), result)

        with self.assertRaises(ValueError):
            Ask._parse_timestamp(None)
Ejemplo n.º 4
0
def parse_time(isotimestr):
    #Given a string in any ISO8601 time format, return a datetime.time object
    #that corresponds to the given time. Fixed offset tzdata will be included
    #if UTC offset is given in the input string. Valid time formats are:
    #
    #hh:mm:ss
    #hhmmss
    #hh:mm
    #hhmm
    #hh
    #hh:mm:ssZ
    #hhmmssZ
    #hh:mmZ
    #hhmmZ
    #hhZ
    #hh:mm:ss±hh:mm
    #hhmmss±hh:mm
    #hh:mm±hh:mm
    #hhmm±hh:mm
    #hh±hh:mm
    #hh:mm:ss±hhmm
    #hhmmss±hhmm
    #hh:mm±hhmm
    #hhmm±hhmm
    #hh±hhmm
    #hh:mm:ss±hh
    #hhmmss±hh
    #hh:mm±hh
    #hhmm±hh
    #hh±hh

    (timestr, tzstr) = _split_tz(isotimestr)

    if tzstr == None:
        return _parse_time_naive(timestr)
    elif tzstr == 'Z':
        return _parse_time_naive(timestr).replace(
            tzinfo=build_utcoffset('UTC', datetime.timedelta(hours=0)))
    else:
        return _parse_time_naive(timestr).replace(tzinfo=parse_timezone(tzstr))
Ejemplo n.º 5
0
def parse_time(isotimestr):
    #Given a string in any ISO 8601 time format, return a datetime.time object
    #that corresponds to the given time. Fixed offset tzdata will be included
    #if UTC offset is given in the input string. Valid time formats are:
    #
    #hh:mm:ss
    #hhmmss
    #hh:mm
    #hhmm
    #hh
    #hh:mm:ssZ
    #hhmmssZ
    #hh:mmZ
    #hhmmZ
    #hhZ
    #hh:mm:ss±hh:mm
    #hhmmss±hh:mm
    #hh:mm±hh:mm
    #hhmm±hh:mm
    #hh±hh:mm
    #hh:mm:ss±hhmm
    #hhmmss±hhmm
    #hh:mm±hhmm
    #hhmm±hhmm
    #hh±hhmm
    #hh:mm:ss±hh
    #hhmmss±hh
    #hh:mm±hh
    #hhmm±hh
    #hh±hh

    (timestr, tzstr) = _split_tz(isotimestr)

    if tzstr is None:
        return _parse_time_naive(timestr)
    elif tzstr == 'Z':
        return _parse_time_naive(timestr).replace(tzinfo=build_utcoffset('UTC', datetime.timedelta(hours=0)))
    else:
        return _parse_time_naive(timestr).replace(tzinfo=parse_timezone(tzstr))