mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
Add period field for en_US.UTF-8 locale
This commit is contained in:
@ -3,6 +3,7 @@ jc changelog
|
|||||||
20210104 v1.14.1
|
20210104 v1.14.1
|
||||||
- Add wi scan parser
|
- Add wi scan parser
|
||||||
- Update date parser for support Ubuntu 20.04
|
- Update date parser for support Ubuntu 20.04
|
||||||
|
- Update last parser for last -F support
|
||||||
- Update man page
|
- Update man page
|
||||||
- Minor documentation updates
|
- Minor documentation updates
|
||||||
|
|
||||||
|
@ -412,6 +412,7 @@ date | jc --date -p # or: jc -p date
|
|||||||
"hour": 16,
|
"hour": 16,
|
||||||
"minute": 48,
|
"minute": 48,
|
||||||
"second": 11,
|
"second": 11,
|
||||||
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Jul",
|
||||||
"weekday": "Fri",
|
"weekday": "Fri",
|
||||||
"weekday_num": 6,
|
"weekday_num": 6,
|
||||||
|
@ -29,6 +29,7 @@ Examples:
|
|||||||
"hour": 16,
|
"hour": 16,
|
||||||
"minute": 48,
|
"minute": 48,
|
||||||
"second": 11,
|
"second": 11,
|
||||||
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Jul",
|
||||||
"weekday": "Fri",
|
"weekday": "Fri",
|
||||||
"weekday_num": 6,
|
"weekday_num": 6,
|
||||||
@ -76,6 +77,7 @@ Returns:
|
|||||||
"hour": integer,
|
"hour": integer,
|
||||||
"minute": integer,
|
"minute": integer,
|
||||||
"second": integer,
|
"second": integer,
|
||||||
|
"period": string,
|
||||||
"month": string,
|
"month": string,
|
||||||
"weekday": string,
|
"weekday": string,
|
||||||
"weekday_num": integer,
|
"weekday_num": integer,
|
||||||
|
@ -27,6 +27,7 @@ Examples:
|
|||||||
"hour": 16,
|
"hour": 16,
|
||||||
"minute": 48,
|
"minute": 48,
|
||||||
"second": 11,
|
"second": 11,
|
||||||
|
"period": null,
|
||||||
"month": "Jul",
|
"month": "Jul",
|
||||||
"weekday": "Fri",
|
"weekday": "Fri",
|
||||||
"weekday_num": 6,
|
"weekday_num": 6,
|
||||||
@ -49,7 +50,7 @@ import jc.utils
|
|||||||
|
|
||||||
|
|
||||||
class info():
|
class info():
|
||||||
version = '1.0'
|
version = '1.1'
|
||||||
description = 'date command parser'
|
description = 'date command parser'
|
||||||
author = 'Kelly Brazil'
|
author = 'Kelly Brazil'
|
||||||
author_email = 'kellyjonbrazil@gmail.com'
|
author_email = 'kellyjonbrazil@gmail.com'
|
||||||
@ -81,6 +82,7 @@ def process(proc_data):
|
|||||||
"hour": integer,
|
"hour": integer,
|
||||||
"minute": integer,
|
"minute": integer,
|
||||||
"second": integer,
|
"second": integer,
|
||||||
|
"period": string,
|
||||||
"month": string,
|
"month": string,
|
||||||
"weekday": string,
|
"weekday": string,
|
||||||
"weekday_num": integer,
|
"weekday_num": integer,
|
||||||
@ -120,6 +122,7 @@ def process(proc_data):
|
|||||||
"hour": int(proc_data['hour']),
|
"hour": int(proc_data['hour']),
|
||||||
"minute": int(proc_data['minute']),
|
"minute": int(proc_data['minute']),
|
||||||
"second": int(proc_data['second']),
|
"second": int(proc_data['second']),
|
||||||
|
"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']],
|
||||||
@ -152,16 +155,31 @@ def parse(data, raw=False, quiet=False):
|
|||||||
data = data.replace(':', ' ')
|
data = data.replace(':', ' ')
|
||||||
split_data = data.split()
|
split_data = data.split()
|
||||||
|
|
||||||
raw_output = {
|
# date v8.32 uses a different format depending on locale, so need to support LANG=en_US.UTF-8
|
||||||
"year": split_data[7],
|
if len(split_data) == 9 and ('AM' in split_data or 'am' in split_data or 'PM' in split_data or 'pm' in split_data):
|
||||||
"month": split_data[1],
|
raw_output = {
|
||||||
"day": split_data[2],
|
"year": split_data[8],
|
||||||
"weekday": split_data[0],
|
"month": split_data[1],
|
||||||
"hour": split_data[3],
|
"day": split_data[2],
|
||||||
"minute": split_data[4],
|
"weekday": split_data[0],
|
||||||
"second": split_data[5],
|
"hour": split_data[3],
|
||||||
"timezone": split_data[6]
|
"minute": split_data[4],
|
||||||
}
|
"second": split_data[5],
|
||||||
|
"period": split_data[6],
|
||||||
|
"timezone": split_data[7]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
# standard LANG=C date output
|
||||||
|
raw_output = {
|
||||||
|
"year": split_data[7],
|
||||||
|
"month": split_data[1],
|
||||||
|
"day": split_data[2],
|
||||||
|
"weekday": split_data[0],
|
||||||
|
"hour": split_data[3],
|
||||||
|
"minute": split_data[4],
|
||||||
|
"second": split_data[5],
|
||||||
|
"timezone": split_data[6]
|
||||||
|
}
|
||||||
|
|
||||||
if raw:
|
if raw:
|
||||||
return raw_output
|
return raw_output
|
||||||
|
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, "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": 2, "timezone": "PDT"}
|
||||||
|
1
tests/fixtures/ubuntu-20.04/date.json
vendored
Normal file
1
tests/fixtures/ubuntu-20.04/date.json
vendored
Normal file
@ -0,0 +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"}
|
@ -13,10 +13,16 @@ class MyTests(unittest.TestCase):
|
|||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.out'), 'r', encoding='utf-8') as f:
|
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()
|
self.generic_date = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/date.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.ubuntu_20_04_date = f.read()
|
||||||
|
|
||||||
# output
|
# output
|
||||||
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/date.json'), 'r', encoding='utf-8') as f:
|
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())
|
self.generic_date_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/ubuntu-20.04/date.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.ubuntu_20_04_date_json = json.loads(f.read())
|
||||||
|
|
||||||
def test_date_nodata(self):
|
def test_date_nodata(self):
|
||||||
"""
|
"""
|
||||||
Test 'date' with no data
|
Test 'date' with no data
|
||||||
@ -29,6 +35,12 @@ class MyTests(unittest.TestCase):
|
|||||||
"""
|
"""
|
||||||
self.assertEqual(jc.parsers.date.parse(self.generic_date, quiet=True), self.generic_date_json)
|
self.assertEqual(jc.parsers.date.parse(self.generic_date, quiet=True), self.generic_date_json)
|
||||||
|
|
||||||
|
def test_date_ubuntu_20_04(self):
|
||||||
|
"""
|
||||||
|
Test 'date' on Ubuntu 20.4
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.date.parse(self.ubuntu_20_04_date, quiet=True), self.ubuntu_20_04_date_json)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user