Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:36:49

0001 """
0002 File that contains utility functions used by various modules, but that do not fit into any single module.
0003 """
0004 import datetime
0005 
0006 def to_timestamp(obj):
0007     """
0008     Takes a datetime object and outputs a timestamp string with the format Y-m-d H:m:S.f
0009     """
0010     return obj.strftime('%d-%b-%y %I:%M:%S.%f %p') if isinstance(obj, datetime.datetime) else obj
0011 
0012 def to_datetime(date_string):
0013     """
0014     Takes a date string with the format Y-m-d H:m:S.f and gives back a datetime.datetime object
0015     """
0016     return datetime.datetime.strptime(date_string.replace(",", "."), "%d-%b-%y %I:%M:%S.%f %p")
0017 
0018 def friendly_since(time_type, since):
0019     """
0020     Takes a since and, if it is Run-based expressed as Lumi-based,
0021     returns the run number.
0022     Otherwise, returns the since without transformations.
0023     """
0024     if time_type == "Run" and (since & 0xffffff) == 0:
0025         return since >> 32
0026     else:
0027         return since