sample_iso_8601 - bruno-beloff/scs_analysis GitHub Wiki

docs > software repositories > scs_analysis > commands > time


DESCRIPTION

The sample_iso_8601 utility is used to replace non-localised datetime fields with an ISO 8601 localised datetime field for JSON documents of any schema.

Dates may be in the format:

  • DD-MM-YYYY
  • DD/MM/YYYY
  • DD/MM/YY
  • DD_MMM_YYYY
  • MM-DD-YYYY
  • MM/DD/YYYY
  • MM/DD/YY
  • YYYY-MM-DD
  • YYYY/MM/DD
  • OLE Automation date

Times in the 24-hour format HH:MM or HH:MM:SS. For datetime fields, the format may be YYYY-MM-DD HH:MM or YYYY-MM-DD HH:MM:SS. Hour values may exceed the range 0-23. If fields are missing from the input document or are malformed, execution will terminate.

The --no-time flag should be used where the input document contains a date but no time indicator. In this case, the the data is interpreted as being an aggregate of the whole date period. For example, if the input date is 31/01/2022 then the output datetime will be 2022-02-01T00:00:00 (the date is moved on by one day because the datetime field indicates the end of the sample period).

If the input datetimes are not UTC, then the timezone of the input data should be specified. In this case, the datetime may optionally be shifted to UTC.

All fields in the input document are presented in the output document, with the exception of the selected date, time or datetime fields. The default name for the ISO 8601 datetime output field is 'rec' but an alternate name may be specified.

SYNOPSIS

sample_iso_8601.py { -z | { -o | -f DATE_FORMAT } [-t TIMEZONE_NAME [-u]] [-i ISO_PATH] { DATETIME_PATH [-n] | DATE_PATH TIME_PATH } } [-s] [-v]

Options
--version show program's version number and exit
-h, --help show this help message and exit
-z, --zones list the available timezone names to stderr
-o, --oad datetime format is OLE Automation date
-f FORMAT, --format=FORMAT format of input date string, e.g. YYYY-MM-DD
-n, --no-time no time is input (use 24:00:00)
-t TIMEZONE, --timezone=TIMEZONE source timezone (default 'UTC')
-u, --utc shift timezone to UTC
-i ISO, --iso-path=ISO path for ISO 8601 datetime output (default 'rec')
-v, --verbose report narrative to stderr

EXAMPLES

csv_reader.py 15_min_Praxis_LHR2.csv -l10 | sample_iso_8601.py -v -f DD/MM/YYYY "Max of Time" -t Europe/Athens -u

DOCUMENT EXAMPLE - INPUT

{"Max of Time": "08/02/2019 00:00", "Average of praxis-431": {"val": {"NO2": {"cnc": 24}, "NO": {"cnc": 67.54666667}}}, "Average of ref": {"NOCNC1 (Processed)": 1.606666667, "NO2CNC1 (Processed)": 6.473333333}, "15 minute "real" data": 5.92, "rec": "2019-02-08T00:00:00Z"}

DOCUMENT EXAMPLE - OUTPUT

{"rec": "2019-02-07T22:00:00Z", "Average of praxis-431": {"val": {"NO2": {"cnc": 24}, "NO": {"cnc": 67.54666667}}}, "Average of ref": {"NOCNC1 (Processed)": 1.606666667, "NO2CNC1 (Processed)": 6.473333333}, "15 minute "real" data": 5.92}

SEE ALSO

scs_analysis/localised_datetime
scs_analysis/sample_localize
scs_analysis/sample_timezone

RESOURCES

Data formats
ISO 8601

https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tooadate?view=netframework-4.8