Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions canopen/objectdictionary/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,12 @@ def export_record(var, eds):
origFileInfo = {
# just set some defaults
"CreationDate": defmtime.strftime("%m-%d-%Y"),
"CreationTime": defmtime.strftime("%I:%m%p"),
"CreationTime": defmtime.strftime("%I:%M%p"),
"EdsVersion": 4.2,
}

file_info.setdefault("ModificationDate", defmtime.strftime("%m-%d-%Y"))
file_info.setdefault("ModificationTime", defmtime.strftime("%I:%m%p"))
file_info.setdefault("ModificationTime", defmtime.strftime("%I:%M%p"))
for k, v in origFileInfo.items():
file_info.setdefault(k, v)

Expand Down
42 changes: 42 additions & 0 deletions test/test_eds_timestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""File timestamps must preserve the clock's minutes, not the month."""
from configparser import RawConfigParser
from datetime import datetime
from io import StringIO
from unittest.mock import patch

import pytest

from canopen.objectdictionary import ObjectDictionary
from canopen.objectdictionary.eds import export_dcf, export_eds


@pytest.mark.parametrize('exporter', [export_eds, export_dcf])
@pytest.mark.parametrize('hour,minute,expected', [(15, 45, '03:45PM'), (0, 7, '12:07AM')])
def test_generated_file_times(exporter, hour, minute, expected):
class Clock(datetime):
@classmethod
def utcnow(cls):
return cls(2026, 11, 18, hour, minute)

output = StringIO()
with patch('datetime.datetime', Clock):
# Give each export its own metadata dictionary.
exporter(ObjectDictionary(), output, {})
result = RawConfigParser()
result.read_string(output.getvalue())
assert result['FileInfo']['CreationTime'] == expected
assert result['FileInfo']['ModificationTime'] == expected
assert result['FileInfo']['CreationDate'] == '11-18-2026'
assert result['FileInfo']['ModificationDate'] == '11-18-2026'


@pytest.mark.parametrize('exporter', [export_eds, export_dcf])
def test_explicit_file_times_are_preserved(exporter):
output = StringIO()
exporter(ObjectDictionary(), output, {
'CreationTime': '06:29AM', 'ModificationTime': '08:53PM',
})
result = RawConfigParser()
result.read_string(output.getvalue())
assert result['FileInfo']['CreationTime'] == '06:29AM'
assert result['FileInfo']['ModificationTime'] == '08:53PM'