Skip to content

Commit f814f91

Browse files
Copy exiv2's date/time to seconds conversions
By using the same system calls as exiv2 we should get the same answer! I hope this cures bug #57.
1 parent 0ec19c6 commit f814f91

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

tests/test_value.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## python-exiv2 - Python interface to libexiv2
22
## http://github.com/jim-easterbrook/python-exiv2
3-
## Copyright (C) 2023-25 Jim Easterbrook jim@jim-easterbrook.me.uk
3+
## Copyright (C) 2023-26 Jim Easterbrook jim@jim-easterbrook.me.uk
44
##
55
## This program is free software: you can redistribute it and/or
66
## modify it under the terms of the GNU General Public License as
@@ -23,6 +23,7 @@
2323
import random
2424
import struct
2525
import sys
26+
import time
2627
import unittest
2728

2829
import exiv2
@@ -414,8 +415,8 @@ def do_test_DateValue(self, py_date):
414415
self.assertEqual(str(value), py_date.isoformat())
415416
value.setDate(py_date.year, py_date.month, py_date.day)
416417
self.assertEqual(str(value), py_date.isoformat())
417-
seconds = int(datetime.datetime.combine(
418-
py_date, datetime.time(), datetime.timezone.utc).timestamp())
418+
seconds = time.mktime(time.struct_time(
419+
(py_date.year, py_date.month, py_date.day, 0, 0, 0, 0, 0, 0)))
419420
self.do_common_tests(value, exiv2.TypeId.date, py_date.isoformat(), data)
420421
self.do_conversion_tests(value, py_date.isoformat(), seconds)
421422
self.do_dataarea_tests(value)
@@ -491,9 +492,9 @@ def do_test_TimeValue(self, py_time):
491492
value.setTime(py_time.hour, py_time.minute, py_time.second, 1)
492493
value.setTime(py_time.hour, py_time.minute, py_time.second, 1, 30)
493494
self.assertEqual(str(value), py_time.isoformat())
494-
seconds = (py_time.hour * 3600) + (py_time.minute * 60) + py_time.second
495-
seconds -= py_time.tzinfo.utcoffset(
496-
datetime.datetime.now()).total_seconds()
495+
seconds = (((exiv_time.hour - exiv_time.tzHour) * 3600) +
496+
((exiv_time.minute - exiv_time.tzMinute) * 60) +
497+
exiv_time.second)
497498
if seconds < 0:
498499
seconds += 24 * 3600
499500
value = exiv2.TimeValue()

0 commit comments

Comments
 (0)