Beispiel #1
0
    def test_format(self):

        dt = timeutil.ts_to_datetime(test_case['ts']['second_accuracy'])

        for fmt_key, tm_str in test_case['format'].items():

            convert_tm_str = timeutil.format(dt, fmt_key)

            self.assertEqual(tm_str, convert_tm_str)
    def test_format(self):

        dt = timeutil.ts_to_datetime(test_case['ts']['second_accuracy'])

        for fmt_key, tm_str in test_case['format'].items():

            convert_tm_str = timeutil.format(dt, fmt_key)

            self.assertEqual(tm_str, convert_tm_str)
Beispiel #3
0
    def test_direct_format(self):

        for fmt_key, tm_str in test_case['format'].items():

            # parse
            dt_key = timeutil.parse(tm_str, fmt_key)
            dt_direct = timeutil.parse(tm_str, timeutil.formats[fmt_key])

            self.assertTrue(dt_key == dt_direct)

            # format
            self.assertEqual(tm_str, timeutil.format(dt_key, fmt_key))
            self.assertEqual(
                tm_str, timeutil.format(dt_key, timeutil.formats[fmt_key]))

            # format_ts
            now = int(time.time())
            self.assertEqual(
                timeutil.format_ts(now, fmt_key),
                timeutil.format_ts(now, timeutil.formats[fmt_key]))
    def test_direct_format(self):

        for fmt_key, tm_str in test_case['format'].items():

            # parse
            dt_key = timeutil.parse(tm_str, fmt_key)
            dt_direct = timeutil.parse(tm_str, timeutil.formats[fmt_key])

            self.assertTrue(dt_key == dt_direct)

            # format
            self.assertEqual(tm_str, timeutil.format(dt_key, fmt_key))
            self.assertEqual(tm_str,
                             timeutil.format(dt_key,
                                             timeutil.formats[fmt_key]))

            # format_ts
            now = int(time.time())
            self.assertEqual(timeutil.format_ts(now, fmt_key),
                             timeutil.format_ts(now, timeutil.formats[fmt_key]))
Beispiel #5
0

if __name__ == '__main__':
    time_utc = 'Tue, 24 Jan 2017 07:51:59 UTC'
    dt = timeutil.parse(time_utc, 'default')
    print dt
    dt = timeutil.parse(time_utc, 'utc')
    print dt
    print 

    time_mysql = '2018-12-1 11:20:30'
    dt = timeutil.parse(time_mysql, 'mysql')
    print dt
    print 

    print timeutil.format(dt, 'utc')
    print timeutil.format(dt, 'iso')
    print timeutil.format(dt, 'daily')
    print

    ts = timeutil.utc_datetime_to_ts(dt)
    print ts
    print

    time_mysql = timeutil.format_ts(ts, 'mysql')
    print time_mysql
    time_iso = timeutil.format_ts(ts, 'iso')
    print time_iso
    print

    ts = timeutil.ts()