diff --git a/LICENSE b/LICENSE index 387b0b0..901fe39 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ MIT License -Copyright (c) 2011-2022, David Cooper -Copyright (c) 2017-2022, Carey Metcalfe +Copyright (c) 2011-2025, David Cooper +Copyright (c) 2017-2025, Carey Metcalfe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/api.rst b/docs/api.rst index 8d64e0f..e5db642 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -76,7 +76,7 @@ The ``FitFile`` Object try: fitfile = FitFile('/path.to/fitfile.fit') fitfile.parse() - except FitParseError, e: + except FitParseError as e: print "Error while parsing .FIT file: %s" % e sys.exit(1) diff --git a/fitparse/processors.py b/fitparse/processors.py index 6848584..34b36ba 100644 --- a/fitparse/processors.py +++ b/fitparse/processors.py @@ -70,7 +70,7 @@ def process_type_bool(self, field_data): def process_type_date_time(self, field_data): value = field_data.value if value is not None and value >= 0x10000000: - field_data.value = datetime.datetime.utcfromtimestamp(UTC_REFERENCE + value) + field_data.value = datetime.datetime.fromtimestamp(timestamp=(UTC_REFERENCE + value), tz=datetime.timezone.utc).replace(tzinfo=None) field_data.units = None # Units were 's', set to None def process_type_local_date_time(self, field_data): @@ -78,7 +78,7 @@ def process_type_local_date_time(self, field_data): # NOTE: This value was created on the device using it's local timezone. # Unless we know that timezone, this value won't be correct. However, if we # assume UTC, at least it'll be consistent. - field_data.value = datetime.datetime.utcfromtimestamp(UTC_REFERENCE + field_data.value) + field_data.value = datetime.datetime.fromtimestamp(timestamp=(UTC_REFERENCE + field_data.value), tz=datetime.timezone.utc).replace(tzinfo=None) field_data.units = None def process_type_localtime_into_day(self, field_data): diff --git a/tests/test.py b/tests/test.py index 886f21f..e4851d5 100755 --- a/tests/test.py +++ b/tests/test.py @@ -66,7 +66,7 @@ def generate_fitfile(data=None, endian='<'): def secs_to_dt(secs): - return datetime.datetime.utcfromtimestamp(secs + UTC_REFERENCE) + return datetime.datetime.fromtimestamp(timestamp=(secs + UTC_REFERENCE), tz=datetime.timezone.utc).replace(tzinfo=None) def testfile(filename): @@ -74,6 +74,7 @@ def testfile(filename): class FitFileTestCase(unittest.TestCase): + def test_basic_file_with_one_record(self, endian='<'): f = FitFile(generate_fitfile(endian=endian)) f.parse() @@ -414,7 +415,11 @@ def test_mismatched_field_size(self): with warnings.catch_warnings(record=True) as w: f.parse() assert w - assert all("falling back to byte encoding" in str(x) for x in w) + assert all( + "falling back to byte encoding" in str(x) + for x in w + if x.category == UserWarning + ) self.assertEqual(len(f.messages), 11293) def test_unterminated_file(self):