mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
add parse_datetime_to_timestamp() tests
This commit is contained in:
16
jc/utils.py
16
jc/utils.py
@ -122,14 +122,14 @@ def parse_datetime_to_timestamp(data):
|
||||
utc_tz = True if 'UTC' in data else False
|
||||
|
||||
formats = [
|
||||
{'id': 1, 'format': '%c', 'locale': None}, # C locale format conversion, or date cli command in C locale with non-UTC tz: Tue Mar 23 16:12:11 2021 or Tue Mar 23 16:12:11 IST 2021
|
||||
{'id': 2, 'format': '%a %d %b %Y %I:%M:%S %p %Z', 'locale': None}, # en_US.UTF-8 local format (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM UTC
|
||||
{'id': 3, 'format': '%a %d %b %Y %I:%M:%S %p', 'locale': None}, # en_US.UTF-8 local format with non-UTC tz (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM IST
|
||||
{'id': 4, 'format': '%A %d %B %Y %I:%M:%S %p %Z', 'locale': None}, # European local format (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM UTC
|
||||
{'id': 5, 'format': '%A %d %B %Y %I:%M:%S %p', 'locale': None}, # European local format with non-UTC tz (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM IST
|
||||
{'id': 6, 'format': '%a %b %d %I:%M:%S %p %Z %Y', 'locale': None}, # date cli command in en_US.UTF-8 format: Wed Mar 24 06:16:19 PM UTC 2021
|
||||
{'id': 7, 'format': '%a %b %d %H:%M:%S %Z %Y', 'locale': None}, # date cli command in C locale format: Wed Mar 24 11:11:30 UTC 2021
|
||||
{'id': 8, 'format': '%c', 'locale': ''} # locally configured locale format conversion: Could be anything :) this is a last-gasp attempt
|
||||
{'id': 1000, 'format': '%c', 'locale': None}, # C locale format conversion, or date cli command in C locale with non-UTC tz: Tue Mar 23 16:12:11 2021 or Tue Mar 23 16:12:11 IST 2021
|
||||
{'id': 2000, 'format': '%a %d %b %Y %I:%M:%S %p %Z', 'locale': None}, # en_US.UTF-8 local format (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM UTC
|
||||
{'id': 3000, 'format': '%a %d %b %Y %I:%M:%S %p', 'locale': None}, # en_US.UTF-8 local format with non-UTC tz (found in upower cli output): Tue 23 Mar 2021 04:12:11 PM IST
|
||||
{'id': 4000, 'format': '%A %d %B %Y %I:%M:%S %p %Z', 'locale': None}, # European local format (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM UTC
|
||||
{'id': 5000, 'format': '%A %d %B %Y %I:%M:%S %p', 'locale': None}, # European local format with non-UTC tz (found in upower cli output): Tuesday 01 October 2019 12:50:41 PM IST
|
||||
{'id': 6000, 'format': '%a %b %d %I:%M:%S %p %Z %Y', 'locale': None}, # date cli command in en_US.UTF-8 format: Wed Mar 24 06:16:19 PM UTC 2021
|
||||
{'id': 7000, 'format': '%a %b %d %H:%M:%S %Z %Y', 'locale': None}, # date cli command in C locale format: Wed Mar 24 11:11:30 UTC 2021
|
||||
{'id': 9000, 'format': '%c', 'locale': ''} # locally configured locale format conversion: Could be anything :) this is a last-gasp attempt
|
||||
]
|
||||
|
||||
# from https://www.timeanddate.com/time/zones/
|
||||
|
28
tests/test_utils.py
Normal file
28
tests/test_utils.py
Normal file
@ -0,0 +1,28 @@
|
||||
import unittest
|
||||
import jc.utils
|
||||
|
||||
|
||||
class MyTests(unittest.TestCase):
|
||||
def test_utils_parse_datetime_to_timestamp(self):
|
||||
|
||||
# naive timestamps created in PDT
|
||||
datetime_map = {
|
||||
# C locale format conversion, or date cli command in C locale with non-UTC tz
|
||||
'Tue Mar 23 16:12:11 2021': {'format': 1000, 'timestamp_naive': 1616541131, 'timestamp_utc': None},
|
||||
'Tue Mar 23 16:12:11 IST 2021': {'format': 1000, 'timestamp_naive': 1616541131, 'timestamp_utc': None},
|
||||
# en_US.UTF-8 local format (found in upower cli output)
|
||||
'Tue 23 Mar 2021 04:12:11 PM UTC': {'format': 2000, 'timestamp_naive': 1616541131, 'timestamp_utc': 1616515931},
|
||||
# en_US.UTF-8 local format with non-UTC tz (found in upower cli output)
|
||||
'Tue 23 Mar 2021 04:12:11 PM IST': {'format': 3000, 'timestamp_naive': 1616541131, 'timestamp_utc': None},
|
||||
# European local format (found in upower cli output)
|
||||
'Tuesday 01 October 2019 12:50:41 PM UTC': {'format': 4000, 'timestamp_naive': 1569959441, 'timestamp_utc': 1569934241},
|
||||
# European local format with non-UTC tz (found in upower cli output)
|
||||
'Tuesday 01 October 2019 12:50:41 PM IST': {'format': 5000, 'timestamp_naive': 1569959441, 'timestamp_utc': None},
|
||||
# date cli command in en_US.UTF-8 format
|
||||
'Wed Mar 24 06:16:19 PM UTC 2021': {'format': 6000, 'timestamp_naive': 1616634979, 'timestamp_utc': 1616609779},
|
||||
# date cli command in C locale format
|
||||
'Wed Mar 24 11:11:30 UTC 2021': {'format': 7000, 'timestamp_naive': 1616609490, 'timestamp_utc': 1616584290}
|
||||
}
|
||||
|
||||
for input_string, expected_output in datetime_map.items():
|
||||
self.assertEqual(jc.utils.parse_datetime_to_timestamp(input_string), expected_output)
|
Reference in New Issue
Block a user