Skip to content

Instantly share code, notes, and snippets.

@marcinhlybin
Created February 20, 2018 14:39
Show Gist options
  • Save marcinhlybin/6d514f65db0685021f467304ff7a3d87 to your computer and use it in GitHub Desktop.
Save marcinhlybin/6d514f65db0685021f467304ff7a3d87 to your computer and use it in GitHub Desktop.
Pendulum DST issue
import pendulum
tz = pendulum.timezone('America/Los_Angeles')
start_time = pendulum.parse('2018-03-11 09:00:00+00:00')
end_time = pendulum.parse('2018-03-11 10:00:00+00:00')
print((end_time - start_time).in_hours()) # 1
print((end_time.in_tz(tz) - start_time).in_hours()) # 1
print((end_time - start_time.in_tz(tz)).in_hours()) # 1
print((end_time.in_tz(tz) - start_time.in_tz(tz)).in_hours()) # 1
p1 = (end_time - start_time).in_hours()
print(start_time.add(hours=p1) == end_time) # True
print(p1) # 1.0
p2 = (end_time.in_tz(tz) - start_time.in_tz(tz)).in_hours()
print(start_time.add(hours=p2) == end_time) # True
print(p2) # 1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment