CMS 3D CMS Logo

conddb_time.py
Go to the documentation of this file.
1 import datetime
2 
3 datetime_string_fmt = '%Y-%m-%d %H:%M:%S.%f'
4 
5 def to_lumi_time( runNumber, lumiSectionId ):
6  return (runNumber<<32) + lumiSectionId
7 
8 def from_lumi_time( lumiTime ):
9  run = lumiTime>>32
10  lumisection_id = lumiTime-( run << 32 )
11  return run, lumisection_id
12 
13 def to_timestamp( dt ):
14  timespan_from_epoch = dt - datetime.datetime(1970,1,1)
15  seconds_from_epoch = int( timespan_from_epoch.total_seconds() )
16  nanoseconds_from_epoch = timespan_from_epoch.microseconds * 1000
17  return ( seconds_from_epoch << 32 ) + nanoseconds_from_epoch
18 
19 def from_timestamp( ts ):
20  seconds_from_epoch = ts >> 32
21  nanoseconds_from_epoch = ts - ( seconds_from_epoch << 32 )
22  dt = datetime.datetime.utcfromtimestamp(seconds_from_epoch)
23  return dt + datetime.timedelta( microseconds=int(nanoseconds_from_epoch/1000) )
24 
26  dt = datetime.datetime.strptime( sdt, datetime_string_fmt )
27  return to_timestamp( dt )
28 
30  dt = from_timestamp( ts )
31  return dt.strftime( datetime_string_fmt )
32 
33 
def string_from_timestamp(ts)
Definition: conddb_time.py:29
def string_to_timestamp(sdt)
Definition: conddb_time.py:25
def from_lumi_time(lumiTime)
Definition: conddb_time.py:8
def to_timestamp(dt)
Definition: conddb_time.py:13
def from_timestamp(ts)
Definition: conddb_time.py:19
def to_lumi_time(runNumber, lumiSectionId)
Definition: conddb_time.py:5