From a02ba74c1284a736750f510a001638da1a065349 Mon Sep 17 00:00:00 2001 From: "[ACC] Elena Operation" <elenaop@cwo-193-ad5.cern.ch> Date: Wed, 23 Feb 2022 17:52:07 +0100 Subject: [PATCH] added some docs --- datascout/_timescout.py | 11 ++++++++++- docs/source/usage.rst | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/datascout/_timescout.py b/datascout/_timescout.py index 1d0c287..ffecc5f 100644 --- a/datascout/_timescout.py +++ b/datascout/_timescout.py @@ -4,7 +4,16 @@ Implementation of sweet functions to convert time data from one format to anothe import pytz import datetime -def unixtime_to_datetime(unixtime_ns, time_zone = 'utc'): +def unixtime_to_datetime(unixtime_ns, time_zone = 'CERN'): + ''' + Converts a timestamp in ns from epoch (UTC) to a datetime on the given time_zone + + Note, a timezone called "CERN" (default) can be used as timezone of Geneva area. + + :param unixtime_ns: ns from epoch + :param time_zone: desired timezone for the output (default='CERN') + :return: + ''' if isinstance(time_zone, str): if time_zone.upper() == 'UTC': time_zone = pytz.utc diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 11689a7..ad4f8e1 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -3,7 +3,7 @@ Usage ===== -Datascout provides a set of self-explained functions for data conversion, saving, loading. +Datascout provides a set of self-explained functions for data conversion, saving, loading, as well as timestamp conversion. A simple example of use could be the following: @@ -64,3 +64,27 @@ The loss of precision is due to the JSON data format, and not to data conversion # This will return no output if the two dictionaries contain the same data ds._compare_data(my_dict, my_dict_from_pandas) +It also provides some sweet functions to deal with timestamps (typically in ns from epoch) + +.. testcode:: + + import datascout as ds + import datetime + + reference_stamp = 1645617457640238425 + reference_time = datetime.datetime(2022, 2, 23, 12, 57, 37, 640238) + + myDateTime_utc = ds.unixtime_to_datetime(reference_stamp, time_zone = 'utc') + myDateTime_local = ds.unixtime_to_datetime(reference_stamp, time_zone = 'local') + myDateTime_cern = ds.unixtime_to_datetime(reference_stamp, time_zone = 'CERN') + myDateTime_unaware = ds.unixtime_to_datetime(reference_stamp, time_zone = None) + + reference_time_str = ds.unixtime_to_string(reference_stamp, time_zone = 'CERN') + print(reference_time_str) + +.. parsed-literal:: + + 2022-02-23 12:57:37.640238 + + + -- GitLab