Skip to content

Commit 707cd57

Browse files
committed
fix(db): fix timezone issue when setting datetimes (#168)
Datetime fields are now set with UTC which is the same format that Rekordbox uses. Timezone agnostic dates or dates with another timezone are converted accordingly.
1 parent a69e12a commit 707cd57

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

pyrekordbox/db6/tables.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import math
88
import re
99
import struct
10-
from datetime import datetime
10+
from datetime import datetime, timezone
1111
from enum import IntEnum
1212
from typing import Any, Dict, Iterator, List, Optional, Tuple
1313

@@ -117,13 +117,11 @@
117117

118118

119119
def datetime_to_str(value: datetime) -> str:
120-
s = value.isoformat().replace("T", " ")
121-
if value.tzinfo is not None:
122-
# Get the timezone info (last 6 characters of the string)
123-
tzinfo = s[-6:]
124-
s = s[:-9] + " " + tzinfo
125-
else:
126-
s = s[:-3] + " +00:00"
120+
# Convert to UTC timezone string
121+
s = value.astimezone(timezone.utc).isoformat().replace("T", " ")
122+
# Get the timezone info (last 6 characters of the string)
123+
tzinfo = s[-6:]
124+
s = s[:-9] + " " + tzinfo
127125
return s
128126

129127

0 commit comments

Comments
 (0)