mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-15 01:24:29 +02:00
finish date parser
This commit is contained in:
18
EXAMPLES.md
18
EXAMPLES.md
@ -377,6 +377,24 @@ cat homes.csv | jc --csv -p
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
### date
|
||||||
|
```bash
|
||||||
|
date | jc --date -p # or: jc -p date
|
||||||
|
```
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"year": 2020,
|
||||||
|
"month_num": 7,
|
||||||
|
"day": 31,
|
||||||
|
"hour": 16,
|
||||||
|
"minute": 48,
|
||||||
|
"second": 11,
|
||||||
|
"month": "Jul",
|
||||||
|
"weekday": "Fri",
|
||||||
|
"weekday_num": 6,
|
||||||
|
"timezone": "PDT"
|
||||||
|
}
|
||||||
|
```
|
||||||
### df
|
### df
|
||||||
```bash
|
```bash
|
||||||
df | jc --df -p # or: jc -p df
|
df | jc --df -p # or: jc -p df
|
||||||
|
@ -119,6 +119,7 @@ The JSON output can be compact (default) or pretty formatted with the `-p` optio
|
|||||||
- `--crontab` enables the `crontab` command and file parser
|
- `--crontab` enables the `crontab` command and file parser
|
||||||
- `--crontab-u` enables the `crontab` file parser with user support
|
- `--crontab-u` enables the `crontab` file parser with user support
|
||||||
- `--csv` enables the `CSV` file parser
|
- `--csv` enables the `CSV` file parser
|
||||||
|
- `--date` enables the `date` command parser
|
||||||
- `--df` enables the `df` command parser
|
- `--df` enables the `df` command parser
|
||||||
- `--dig` enables the `dig` command parser
|
- `--dig` enables the `dig` command parser
|
||||||
- `--dmidecode` enables the `dmidecode` command parser
|
- `--dmidecode` enables the `dmidecode` command parser
|
||||||
|
@ -15,12 +15,14 @@ Examples:
|
|||||||
$ date | jc --date -p
|
$ date | jc --date -p
|
||||||
{
|
{
|
||||||
"year": 2020,
|
"year": 2020,
|
||||||
"month": "Jul",
|
"month_num": 7,
|
||||||
"day": 31,
|
"day": 31,
|
||||||
|
"hour": 16,
|
||||||
|
"minute": 48,
|
||||||
|
"second": 11,
|
||||||
|
"month": "Jul",
|
||||||
"weekday": "Fri",
|
"weekday": "Fri",
|
||||||
"hour": 14,
|
"weekday_num": 6,
|
||||||
"minute": 35,
|
|
||||||
"second": 55,
|
|
||||||
"timezone": "PDT"
|
"timezone": "PDT"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,9 +32,9 @@ Examples:
|
|||||||
"month": "Jul",
|
"month": "Jul",
|
||||||
"day": "31",
|
"day": "31",
|
||||||
"weekday": "Fri",
|
"weekday": "Fri",
|
||||||
"hour": "14",
|
"hour": "16",
|
||||||
"minute": "36",
|
"minute": "50",
|
||||||
"second": "14",
|
"second": "01",
|
||||||
"timezone": "PDT"
|
"timezone": "PDT"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,12 +62,14 @@ Returns:
|
|||||||
|
|
||||||
{
|
{
|
||||||
"year": integer,
|
"year": integer,
|
||||||
"month": string,
|
"month_num": integer,
|
||||||
"day": integer,
|
"day": integer,
|
||||||
"weekday": string,
|
|
||||||
"hour": integer,
|
"hour": integer,
|
||||||
"minute": integer,
|
"minute": integer,
|
||||||
"second": integer,
|
"second": integer,
|
||||||
|
"month": string,
|
||||||
|
"weekday": string,
|
||||||
|
"weekday_num": integer,
|
||||||
"timezone": string
|
"timezone": string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
tests/fixtures/generic/date.json
vendored
Normal file
1
tests/fixtures/generic/date.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"year": 2020, "month_num": 8, "day": 3, "hour": 9, "minute": 12, "second": 51, "month": "Aug", "weekday": "Mon", "weekday_num": 2, "timezone": "PDT"}
|
1
tests/fixtures/generic/date.out
vendored
Normal file
1
tests/fixtures/generic/date.out
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
Mon Aug 3 09:12:51 PDT 2020
|
34
tests/test_date.py
Normal file
34
tests/test_date.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
import jc.parsers.date
|
||||||
|
|
||||||
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class MyTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# input
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_date = f.read()
|
||||||
|
|
||||||
|
# output
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.generic_date_json = json.loads(f.read())
|
||||||
|
|
||||||
|
def test_date_nodata(self):
|
||||||
|
"""
|
||||||
|
Test 'date' with no data
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.date.parse('', quiet=True), {})
|
||||||
|
|
||||||
|
def test_date(self):
|
||||||
|
"""
|
||||||
|
Test 'date'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.date.parse(self.generic_date, quiet=True), self.generic_date_json)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user