Skip to content

Commit

Permalink
Changes to calculate local time correctly
Browse files Browse the repository at this point in the history
As described by Ulrik Brinck
  • Loading branch information
nickpiggott committed Jul 14, 2020
1 parent eb5f18f commit f61f996
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/spi/binary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import datetime, dateutil.tz
import logging
import sys
from datetime import timedelta

logger = logging.getLogger("spi.binary")

Expand Down Expand Up @@ -417,6 +418,8 @@ def encode_timepoint(timepoint):

bits = bitarray(1)
bits.setall(False)
offset = (timepoint.utcoffset().days * 86400 + timepoint.utcoffset().seconds) + (timepoint.dst().days * 86400 + timepoint.dst().days)
timepoint = timepoint - timedelta(seconds=offset)

# b0: RFA(0)

Expand Down Expand Up @@ -454,7 +457,6 @@ def encode_timepoint(timepoint):
# b32/48: LTO
if bits[19]:
bits += bitarray('00') # b49-50: RFA(0)
offset = (timepoint.utcoffset().days * 86400 + timepoint.utcoffset().seconds) + (timepoint.dst().days * 86400 + timepoint.dst().days)
bits += bitarray('0' if offset > 0 else '1') # b51: LTO sign
bits += encode_number(offset / (60 * 60) * 2, 5) # b52-56: Half hours

Expand Down

0 comments on commit f61f996

Please sign in to comment.