mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
fix weekday numbering to be ISO 8601 compliant. Add naive calculated epoch timestamp field
This commit is contained in:
21
EXAMPLES.md
21
EXAMPLES.md
@ -464,17 +464,18 @@ date | jc --date -p # or: jc -p date
|
|||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"year": 2020,
|
"year": 2021,
|
||||||
"month_num": 7,
|
"month_num": 3,
|
||||||
"day": 31,
|
"day": 22,
|
||||||
"hour": 16,
|
"hour": 20,
|
||||||
"minute": 48,
|
"minute": 54,
|
||||||
"second": 11,
|
"second": 39,
|
||||||
"period": null,
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Mar",
|
||||||
"weekday": "Fri",
|
"weekday": "Mon",
|
||||||
"weekday_num": 6,
|
"weekday_num": 1,
|
||||||
"timezone": "PDT"
|
"timezone": "PDT",
|
||||||
|
"epoch": 1616471679
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### df
|
### df
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
# jc.parsers.date
|
# jc.parsers.date
|
||||||
jc - JSON CLI output utility `date` command output parser
|
jc - JSON CLI output utility `date` command output parser
|
||||||
|
|
||||||
|
Calculated epoch time field is naive (i.e. based on the local time of the system the parser is run on) since there is no unambiguous timezone information in the `date` command output.
|
||||||
|
|
||||||
Usage (cli):
|
Usage (cli):
|
||||||
|
|
||||||
$ date | jc --date
|
$ date | jc --date
|
||||||
@ -23,28 +25,30 @@ Examples:
|
|||||||
|
|
||||||
$ date | jc --date -p
|
$ date | jc --date -p
|
||||||
{
|
{
|
||||||
"year": 2020,
|
"year": 2021,
|
||||||
"month_num": 7,
|
"month_num": 3,
|
||||||
"day": 31,
|
"day": 22,
|
||||||
"hour": 16,
|
"hour": 20,
|
||||||
"minute": 48,
|
"minute": 47,
|
||||||
"second": 11,
|
"second": 3,
|
||||||
"period": null,
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Mar",
|
||||||
"weekday": "Fri",
|
"weekday": "Mon",
|
||||||
"weekday_num": 6,
|
"weekday_num": 1,
|
||||||
"timezone": "PDT"
|
"timezone": "PDT",
|
||||||
|
"epoch": 1616471223
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$ date | jc --date -p -r
|
$ date | jc --date -p -r
|
||||||
{
|
{
|
||||||
"year": "2020",
|
"year": "2021",
|
||||||
"month": "Jul",
|
"month": "Mar",
|
||||||
"day": "31",
|
"day": "22",
|
||||||
"weekday": "Fri",
|
"weekday": "Mon",
|
||||||
"hour": "16",
|
"hour": "20",
|
||||||
"minute": "50",
|
"minute": "48",
|
||||||
"second": "01",
|
"second": "12",
|
||||||
"timezone": "PDT"
|
"timezone": "PDT"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +85,8 @@ Returns:
|
|||||||
"month": string,
|
"month": string,
|
||||||
"weekday": string,
|
"weekday": string,
|
||||||
"weekday_num": integer,
|
"weekday_num": integer,
|
||||||
"timezone": string
|
"timezone": string,
|
||||||
|
"epoch": integer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""jc - JSON CLI output utility `date` command output parser
|
"""jc - JSON CLI output utility `date` command output parser
|
||||||
|
|
||||||
|
Calculated epoch time field is naive (i.e. based on the local time of the system the parser is run on) since there is no unambiguous timezone information in the `date` command output.
|
||||||
|
|
||||||
Usage (cli):
|
Usage (cli):
|
||||||
|
|
||||||
$ date | jc --date
|
$ date | jc --date
|
||||||
@ -21,36 +23,39 @@ Examples:
|
|||||||
|
|
||||||
$ date | jc --date -p
|
$ date | jc --date -p
|
||||||
{
|
{
|
||||||
"year": 2020,
|
"year": 2021,
|
||||||
"month_num": 7,
|
"month_num": 3,
|
||||||
"day": 31,
|
"day": 22,
|
||||||
"hour": 16,
|
"hour": 20,
|
||||||
"minute": 48,
|
"minute": 47,
|
||||||
"second": 11,
|
"second": 3,
|
||||||
"period": null,
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Mar",
|
||||||
"weekday": "Fri",
|
"weekday": "Mon",
|
||||||
"weekday_num": 6,
|
"weekday_num": 1,
|
||||||
"timezone": "PDT"
|
"timezone": "PDT",
|
||||||
|
"epoch": 1616471223
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$ date | jc --date -p -r
|
$ date | jc --date -p -r
|
||||||
{
|
{
|
||||||
"year": "2020",
|
"year": "2021",
|
||||||
"month": "Jul",
|
"month": "Mar",
|
||||||
"day": "31",
|
"day": "22",
|
||||||
"weekday": "Fri",
|
"weekday": "Mon",
|
||||||
"hour": "16",
|
"hour": "20",
|
||||||
"minute": "50",
|
"minute": "48",
|
||||||
"second": "01",
|
"second": "12",
|
||||||
"timezone": "PDT"
|
"timezone": "PDT"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
from datetime import datetime
|
||||||
import jc.utils
|
import jc.utils
|
||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
version = '1.1'
|
version = '1.2'
|
||||||
description = 'date command parser'
|
description = 'date command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -86,7 +91,8 @@ def process(proc_data):
|
|||||||
"month": string,
|
"month": string,
|
||||||
"weekday": string,
|
"weekday": string,
|
||||||
"weekday_num": integer,
|
"weekday_num": integer,
|
||||||
"timezone": string
|
"timezone": string,
|
||||||
|
"epoch": integer
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
month_map = {
|
month_map = {
|
||||||
@ -105,28 +111,38 @@ def process(proc_data):
|
|||||||
}
|
}
|
||||||
|
|
||||||
weekday_map = {
|
weekday_map = {
|
||||||
"Sun": 1,
|
"Mon": 1,
|
||||||
"Mon": 2,
|
"Tue": 2,
|
||||||
"Tue": 3,
|
"Wed": 3,
|
||||||
"Wed": 4,
|
"Thu": 4,
|
||||||
"Thu": 5,
|
"Fri": 5,
|
||||||
"Fri": 6,
|
"Sat": 6,
|
||||||
"Sat": 7
|
"Sun": 7
|
||||||
}
|
}
|
||||||
|
|
||||||
if proc_data:
|
if proc_data:
|
||||||
|
dt_year = int(proc_data['year'])
|
||||||
|
dt_month = month_map[proc_data['month']]
|
||||||
|
dt_day = int(proc_data['day'])
|
||||||
|
dt_hour = int(proc_data['hour'])
|
||||||
|
dt_minute = int(proc_data['minute'])
|
||||||
|
dt_second = int(proc_data['second'])
|
||||||
|
|
||||||
|
epoch_dt = datetime(dt_year, dt_month, dt_day, hour=dt_hour, minute=dt_minute, second=dt_second)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"year": int(proc_data['year']),
|
"year": dt_year,
|
||||||
'month_num': month_map[proc_data['month']],
|
'month_num': dt_month,
|
||||||
"day": int(proc_data['day']),
|
"day": dt_day,
|
||||||
"hour": int(proc_data['hour']),
|
"hour": dt_hour,
|
||||||
"minute": int(proc_data['minute']),
|
"minute": dt_minute,
|
||||||
"second": int(proc_data['second']),
|
"second": dt_second,
|
||||||
"period": proc_data['period'] if 'period' in proc_data else None,
|
"period": proc_data['period'] if 'period' in proc_data else None,
|
||||||
"month": proc_data['month'],
|
"month": proc_data['month'],
|
||||||
"weekday": proc_data['weekday'],
|
"weekday": proc_data['weekday'],
|
||||||
"weekday_num": weekday_map[proc_data['weekday']],
|
"weekday_num": weekday_map[proc_data['weekday']],
|
||||||
"timezone": proc_data['timezone']
|
"timezone": proc_data['timezone'],
|
||||||
|
"epoch": int(epoch_dt.strftime('%s'))
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return {}
|
return {}
|
||||||
|
2
tests/fixtures/generic/date.json
vendored
2
tests/fixtures/generic/date.json
vendored
@ -1 +1 @@
|
|||||||
{"year": 2020, "month_num": 8, "day": 3, "hour": 9, "minute": 12, "second": 51, "period": null, "month": "Aug", "weekday": "Mon", "weekday_num": 2, "timezone": "PDT"}
|
{"year": 2020, "month_num": 8, "day": 3, "hour": 9, "minute": 12, "second": 51, "period": null, "month": "Aug", "weekday": "Mon", "weekday_num": 1, "timezone": "PDT", "epoch": 1596471171}
|
||||||
|
2
tests/fixtures/ubuntu-20.04/date.json
vendored
2
tests/fixtures/ubuntu-20.04/date.json
vendored
@ -1 +1 @@
|
|||||||
{"year": 2021, "month_num": 1, "day": 5, "hour": 1, "minute": 2, "second": 4, "period": "AM", "month": "Jan", "weekday": "Tue", "weekday_num": 3, "timezone": "UTC"}
|
{"year": 2021, "month_num": 1, "day": 5, "hour": 1, "minute": 2, "second": 4, "period": "AM", "month": "Jan", "weekday": "Tue", "weekday_num": 2, "timezone": "UTC", "epoch": 1609837324}
|
||||||
|
Reference in New Issue
Block a user