コード例 #1
0
    def index(self, timestamp):
        unix_timestamp = to_unix_timestamp(timestamp)
        index, remainder = divmod(unix_timestamp, self.size)

        if remainder > 0:
            return index
        else:
            return index - 1
コード例 #2
0
def test_to_unix_timestamp():
    tzinfo = pytz.timezone(TIMEZONE)

    naive_timestamp = datetime(2013, 5, 16, 9, 30)
    timestamp = tzinfo.localize(naive_timestamp)

    unix_timestamp = to_unix_timestamp(timestamp)

    expected_unix_timestamp = 1368689400

    delta = unix_timestamp - expected_unix_timestamp

    eq_(delta, 0)

    eq_(unix_timestamp, expected_unix_timestamp)

    timestamp = pytz.utc.localize(datetime(1970, 1, 5, 8, 0))
    unix_timestamp = to_unix_timestamp(timestamp)

    eq_(unix_timestamp, 4 * 86400 + 8 * 3600)