2021-04-09 10:36:42 -07:00
|
|
|
[Home](https://kellyjonbrazil.github.io/jc/)
|
2022-01-25 17:07:47 -08:00
|
|
|
<a id="jc.parsers.date"></a>
|
2020-07-31 14:39:02 -07:00
|
|
|
|
|
|
|
# jc.parsers.date
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2022-03-04 13:27:39 -08:00
|
|
|
jc - JSON Convert `date` command output parser
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
The `epoch` calculated timestamp field is naive. (i.e. based on the local
|
|
|
|
time of the system the parser is run on)
|
2021-03-23 14:10:42 -07:00
|
|
|
|
2022-01-19 17:30:14 -08:00
|
|
|
The `epoch_utc` calculated timestamp field is timezone-aware and is only
|
|
|
|
available if the timezone field is UTC.
|
2021-03-22 20:56:57 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (cli):
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ date | jc --date
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-08-15 13:51:48 -07:00
|
|
|
or
|
2020-08-05 16:51:58 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
$ jc date
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2020-08-05 13:32:59 -07:00
|
|
|
Usage (module):
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
import jc
|
|
|
|
result = jc.parse('date', date_command_output)
|
2022-01-18 14:18:12 -08:00
|
|
|
|
2021-04-08 12:42:01 -07:00
|
|
|
Schema:
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
{
|
|
|
|
"year": integer,
|
|
|
|
"month": string,
|
|
|
|
"month_num": integer,
|
|
|
|
"day": integer,
|
|
|
|
"weekday": string,
|
|
|
|
"weekday_num": integer,
|
|
|
|
"hour": integer,
|
|
|
|
"hour_24": integer,
|
|
|
|
"minute": integer,
|
|
|
|
"second": integer,
|
|
|
|
"period": string,
|
|
|
|
"timezone": string,
|
|
|
|
"utc_offset": string, # null if timezone field is not UTC
|
|
|
|
"day_of_year": integer,
|
|
|
|
"week_of_year": integer,
|
|
|
|
"iso": string,
|
|
|
|
"epoch": integer, # [0]
|
|
|
|
"epoch_utc": integer, # [1]
|
|
|
|
"timezone_aware": boolean # [2]
|
|
|
|
}
|
|
|
|
|
|
|
|
[0] naive timestamp
|
|
|
|
[1] timezone-aware timestamp. Only available if timezone field is UTC
|
|
|
|
[2] if true, all fields are correctly based on UTC
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$ date | jc --date -p
|
|
|
|
{
|
|
|
|
"year": 2021,
|
|
|
|
"month": "Mar",
|
|
|
|
"month_num": 3,
|
|
|
|
"day": 25,
|
|
|
|
"weekday": "Thu",
|
|
|
|
"weekday_num": 4,
|
|
|
|
"hour": 2,
|
|
|
|
"hour_24": 2,
|
|
|
|
"minute": 2,
|
|
|
|
"second": 26,
|
|
|
|
"period": "AM",
|
|
|
|
"timezone": "UTC",
|
|
|
|
"utc_offset": "+0000",
|
|
|
|
"day_of_year": 84,
|
|
|
|
"week_of_year": 12,
|
|
|
|
"iso": "2021-03-25T02:02:26+00:00",
|
|
|
|
"epoch": 1616662946,
|
|
|
|
"epoch_utc": 1616637746,
|
|
|
|
"timezone_aware": true
|
|
|
|
}
|
2022-01-25 17:07:47 -08:00
|
|
|
|
|
|
|
<a id="jc.parsers.date.parse"></a>
|
|
|
|
|
2022-03-05 12:15:14 -08:00
|
|
|
### parse
|
2022-01-25 17:07:47 -08:00
|
|
|
|
2020-07-31 14:39:02 -07:00
|
|
|
```python
|
2022-01-25 17:07:47 -08:00
|
|
|
def parse(data, raw=False, quiet=False)
|
2020-07-31 14:39:02 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
Main text parsing function
|
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Parameters:
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
data: (string) text data to parse
|
|
|
|
raw: (boolean) unprocessed output if True
|
|
|
|
quiet: (boolean) suppress warning messages if True
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Returns:
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-25 18:03:34 -08:00
|
|
|
Dictionary. Raw or processed structured data.
|
2020-07-31 14:39:02 -07:00
|
|
|
|
2022-01-25 19:18:54 -08:00
|
|
|
### Parser Information
|
2021-04-09 10:36:42 -07:00
|
|
|
Compatibility: linux, darwin, freebsd
|
|
|
|
|
2023-12-21 14:55:21 -08:00
|
|
|
Source: [`jc/parsers/date.py`](https://github.com/kellyjonbrazil/jc/blob/master/jc/parsers/date.py)
|
|
|
|
|
2024-01-03 15:57:08 -08:00
|
|
|
This parser can be used with the `--slurp` command-line option.
|
|
|
|
|
|
|
|
Version 2.6 by Kelly Brazil (kellyjonbrazil@gmail.com)
|