Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit 8d7acdb

Browse files
committed
Handle datetime depricataion
1 parent 937f9ec commit 8d7acdb

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/adif_file/adi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import re
77
import copy
8-
import datetime
98
from collections.abc import Iterator
109

1110
from . import __version_str__, __proj_name__
11+
from .util import get_cur_adif_dt
1212

1313

1414
class TooMuchHeadersException(Exception):
@@ -213,8 +213,7 @@ def dumpi(data_dict: dict, comment: str = 'ADIF export by ' + __proj_name__,
213213
default = {'ADIF_VER': '3.1.4',
214214
'PROGRAMID': __proj_name__,
215215
'PROGRAMVERSION': __version_str__,
216-
'CREATED_TIMESTAMP': datetime.datetime.utcnow().strftime('%Y%m%d %H%M%S')
217-
# TODO: Fix deprication > 3.10: datetime.datetime.now(tz=datetime.UTC).strftime('%Y%m%d %H%M%S')
216+
'CREATED_TIMESTAMP': get_cur_adif_dt(),
218217
}
219218

220219
data = comment + ' \n'

src/adif_file/adx.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# PyADIF-File (c) 2023-2025 by Andreas Schawo is licensed under CC BY-SA 4.0.
2+
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/
3+
14
"""Convert ADIF ADX content to dictionary and vice versa
25
The XML is validated against the XSD from ADIF.org"""
36

47
import copy
5-
import datetime
68
import os.path
79
import xml
810
from xml.etree.ElementTree import ElementTree, ParseError
@@ -11,6 +13,7 @@
1113
import xmltodict
1214

1315
from . import __version_str__, __proj_name__
16+
from .util import get_cur_adif_dt
1417

1518
ADX_EXPORT_SCHEMA = xmlschema.XMLSchema(os.path.join(os.path.dirname(__file__), 'xsd/adx314.xsd'))
1619
ADX_IMPORT_SCHEMA = xmlschema.XMLSchema(os.path.join(os.path.dirname(__file__), 'xsd/adx314generic.xsd'))
@@ -95,7 +98,7 @@ def dump(file_name: str, data_dict: dict, raise_exc=True) -> list[Exception]:
9598
'ADIF_VER': '3.1.4',
9699
'PROGRAMID': __proj_name__,
97100
'PROGRAMVERSION': __version_str__,
98-
'CREATED_TIMESTAMP': datetime.datetime.utcnow().strftime('%Y%m%d %H%M%S')
101+
'CREATED_TIMESTAMP': get_cur_adif_dt()
99102
}
100103

101104
if 'HEADER' not in data_dict:

src/adif_file/util.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# PyADIF-File (c) 2023-2025 by Andreas Schawo is licensed under CC BY-SA 4.0.
2+
# To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/
3+
4+
"""Provides some useful function to handle ADIF data"""
5+
6+
import sys
7+
import datetime
8+
9+
10+
def get_cur_adif_dt() -> str:
11+
"""Get current date/time in ADIF format independant of Python version"""
12+
if sys.version_info[0] == 3 and sys.version_info[1] < 11:
13+
return datetime.datetime.utcnow().strftime('%Y%m%d %H%M%S')
14+
15+
return datetime.datetime.now(datetime.UTC).strftime('%Y%m%d %H%M%S')
16+
17+
18+
def adif_date2iso(date: str) -> str:
19+
"""Tries to convert ADIF date to iso format"""
20+
if not date or len(date) != 8:
21+
return date
22+
return date[:4] + '-' + date[4:6] + '-' + date[6:8]
23+
24+
25+
def adif_time2iso(time: str) -> str:
26+
"""Tries to convert ADIF time to iso format"""
27+
if not time or len(time) not in (4, 6):
28+
return time
29+
return time[:2] + ':' + time[2:4] + (':' + time[4:6] if len(time) == 6 else '')
30+
31+
32+
__all__ = ['get_cur_adif_dt', 'adif_date2iso', 'adif_time2iso']

0 commit comments

Comments
 (0)