def test_format_ts(self):

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

            convert_tm_str = \
                timeutil.format_ts(test_case['ts']['second_accuracy'], fmt_key)

            self.assertEqual(tm_str, convert_tm_str)
Exemple #2
0
    def test_format_ts(self):

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

            convert_tm_str = \
                timeutil.format_ts(test_case['ts']['second_accuracy'], fmt_key)

            self.assertEqual(tm_str, convert_tm_str)
    def clean_binlog(self, before_days=5):

        ts = timeutil.ts()
        ts = ts - 86400 * before_days
        dt = timeutil.format_ts(ts, 'daily')

        pool = mysqlconnpool.make(self.mysql_addr)

        self.mysql_pool_query(
            pool, 'PURGE BINARY LOGS BEFORE "{dt} 00:00:00"'.format(dt=dt))
Exemple #4
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]))
    def make_arc_dir(self):

        now_ts = timeutil.ts() - time.timezone - self.time_toleration
        date_str = timeutil.format_ts(now_ts, 'daily')

        arc_dir = os.path.join(self.arc_base, date_str )
        fsutil.makedirs(arc_dir)

        symlink_path = os.path.join(self.arc_base, 'current')

        while True:
            try:
                os.symlink(arc_dir, symlink_path)
                break
            except OSError as e:
                if e[0] == errno.EEXIST:
                    os.unlink(symlink_path)
                else:
                    raise

        return arc_dir
Exemple #7
0
    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()
    print ts
    time_mysql = timeutil.format_ts(ts, 'mysql')
    print time_mysql
    print

    ms = timeutil.ms()
    us = timeutil.us()
    ns = timeutil.ns()
    print ms