1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-17 00:07:37 +02:00
Files
jc/docs/parsers/date.md

115 lines
2.2 KiB
Markdown
Raw Normal View History

2020-07-31 14:39:02 -07:00
# jc.parsers.date
2020-08-05 16:51:58 -07:00
jc - JSON CLI output utility `date` command output parser
2020-07-31 14:39:02 -07: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
The `epoch_utc` calculated timestamp field is timezone-aware and is only available if the timezone field is UTC.
2020-08-05 13:32:59 -07:00
Usage (cli):
2020-07-31 14:39:02 -07:00
2020-08-05 16:51:58 -07:00
$ date | jc --date
or
$ jc date
2020-07-31 14:39:02 -07:00
2020-08-05 13:32:59 -07:00
Usage (module):
import jc.parsers.date
result = jc.parsers.date.parse(date_command_output)
2020-07-31 14:39:02 -07:00
Compatibility:
'linux', 'darwin', 'freebsd'
Examples:
$ date | jc --date -p
{
"year": 2021,
"month_num": 3,
"day": 23,
2021-03-23 14:59:03 -07:00
"hour": 8,
"hour_24": 20,
"minute": 45,
"second": 29,
"period": "PM",
"month": "Mar",
"weekday": "Tue",
"weekday_num": 2,
"timezone": "UTC",
2021-03-23 14:59:03 -07:00
"epoch": 1616557529,
"epoch_utc": 1616532329
2020-07-31 14:39:02 -07:00
}
$ date | jc --date -p -r
{
"year": "2021",
"month": "Mar",
"day": "23",
"weekday": "Tue",
2021-03-23 14:59:03 -07:00
"hour": "08",
"minute": "45",
"second": "29",
"period": "PM",
"timezone": "UTC"
2020-07-31 14:39:02 -07:00
}
## info
```python
info()
```
## process
```python
process(proc_data)
```
Final processing to conform to the schema.
Parameters:
2021-01-04 18:01:16 -08:00
proc_data: (Dictionary) raw structured data to process
2020-07-31 14:39:02 -07:00
Returns:
2020-07-31 14:47:06 -07:00
Dictionary. Structured data with the following schema:
2020-07-31 14:39:02 -07:00
{
2020-08-03 09:26:37 -07:00
"year": integer,
"month_num": integer,
"day": integer,
"hour": integer,
"minute": integer,
"second": integer,
"period": string, # 'AM' or 'PM'. null if 24-hour output
2020-08-03 09:26:37 -07:00
"month": string,
"weekday": string,
"weekday_num": integer,
"timezone": string,
"epoch": integer, # naive timestamp
"epoch_utc": integer, # timezone-aware timestamp. Only available if timezone field is UTC
2020-07-31 14:39:02 -07:00
}
## parse
```python
parse(data, raw=False, quiet=False)
```
Main text parsing function
Parameters:
data: (string) text data to parse
raw: (boolean) output preprocessed JSON if True
quiet: (boolean) suppress warning messages if True
Returns:
2020-07-31 14:47:06 -07:00
Dictionary. Raw or processed structured data.
2020-07-31 14:39:02 -07:00