Skip to content

Commit c2e0fe6

Browse files
committed
Fixed code formatting and add a news fragment for PR 2009
1 parent 2dcb22f commit c2e0fe6

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

can/io/asc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _datetime_to_timestamp(datetime_string: str) -> float:
141141
"%m %d %H:%M:%S.%f %Y",
142142
"%m %d %H:%M:%S %Y",
143143
"%m %d %H:%M:%S.%f %p %Y",
144-
"%m %d %H:%M:%S %p %Y"
144+
"%m %d %H:%M:%S %p %Y",
145145
)
146146

147147
datetime_string_parts = datetime_string.split(" ", 1)
@@ -153,7 +153,6 @@ def _datetime_to_timestamp(datetime_string: str) -> float:
153153
raise ValueError(f"Unsupported month abbreviation: {month}") from None
154154
datetime_string = " ".join(datetime_string_parts)
155155

156-
157156
for format_str in DATETIME_FORMATS:
158157
try:
159158
return datetime.strptime(datetime_string, format_str).timestamp()

doc/changelog.d/2009.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved datetime parsing and added support for “double-defined” datetime strings (such as, e.g., `"30 15:06:13.191 pm 2017"`) for ASCReader class.

test/logformats_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,19 @@ def test_write(self):
680680

681681
self.assertEqual(expected_file.read_text(), actual_file.read_text())
682682

683+
@parameterized.expand(
684+
[
685+
("May 27 04:09:35.000 pm 2014", 1401199775.0),
686+
("Mai 27 04:09:35.000 pm 2014", 1401199775.0),
687+
("Apr 28 10:44:52.480 2022", 1651135492.48),
688+
("Sep 30 15:06:13.191 2017", 1506776773.191),
689+
("Sep 30 15:06:13.191 pm 2017", 1506776773.191),
690+
("Sep 30 15:06:13.191 am 2017", 1506776773.191),
691+
]
692+
)
693+
def test_datetime_to_timestamp(self, datetime_string: str, expected_timestamp: float):
694+
timestamp = can.ASCReader._datetime_to_timestamp(datetime_string)
695+
self.assertAlmostEqual(timestamp, expected_timestamp)
683696

684697
class TestBlfFileFormat(ReaderWriterTest):
685698
"""Tests can.BLFWriter and can.BLFReader.

0 commit comments

Comments
 (0)