Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from uuid import UUID
- import time
- import datetime
- def shogal_uuid1(node, nanoseconds, clock_seq=None):
- """Generate a UUID from a host ID, sequence number, and the current time.
- If 'node' is not given, getnode() is used to obtain the hardware
- address. If 'clock_seq' is given, it is used as the sequence number;
- otherwise a random 14-bit sequence number is chosen."""
- # 0x01b21dd213814000 is the number of 100-ns intervals between the
- # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
- timestamp = nanoseconds // 100 + 0x01b21dd213814000
- _last_timestamp = timestamp
- if clock_seq is None:
- import random
- clock_seq = random.getrandbits(14) # instead of stable storage
- time_low = timestamp & 0xffffffff
- time_mid = (timestamp >> 32) & 0xffff
- time_hi_version = (timestamp >> 48) & 0x0fff
- clock_seq_low = clock_seq & 0xff
- clock_seq_hi_variant = (clock_seq >> 8) & 0x3f
- return UUID(fields=(time_low, time_mid, time_hi_version,
- clock_seq_hi_variant, clock_seq_low, node), version=1)
- def main():
- def parse_date(s):
- _date, _time = s.split(' ')
- year, month, day = map(int, _date.split('-'))
- hours, minutes, seconds = map(int, _time.split('.')[0].split(':'))
- subsecs = _time.split('.')[1]
- if len(subsecs) < 9:
- subsecs += '0' * (9 - len(subsecs))
- subsecs = int(subsecs[:9])
- secs_timestamp = int(datetime.datetime(year, month, day, hours, minutes, seconds).timestamp())
- secs_timestamp *= 10 ** 9 # Set resolution to 100nanos
- secs_timestamp += subsecs
- return secs_timestamp
- s= parse_date('2020-04-06 10:53:39.364780700')
- print(s, type(s))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement