0

These times are from Queensland, Australia where Daylight savings is not observed.

I have a program that interpolates time using this strategy, but it interpolates with respect to daylight savings time.

For example, this script interpolates between two time points with 100 intervals total.

import numpy as np
from datetime import datetime
import datetime as dt
import time

x_dec = np.linspace(0, np.pi, num=100)

time1 = dt.datetime(2017, 11, 4, 20, 47, 0)
time2 = dt.datetime(2017, 11, 5, 3, 1, 0)

this_time = time.mktime(time1.timetuple())
next_time = time.mktime(time2.timetuple())

this_x_temp = np.interp(x_dec, (x_dec.min(), x_dec.max()), (this_time,     next_time))

this_x = np.vectorize(datetime.fromtimestamp)(this_x_temp)
print(this_x)

Instead of cleanly producing interpolated times, it cycles through times around 1AM twice in concordance with American Daylight Savings time. See the example output.

...
datetime.datetime(2017, 11, 5, 1, 49, 29, 90909)
datetime.datetime(2017, 11, 5, 1, 53, 52, 121212)
datetime.datetime(2017, 11, 5, 1, 58, 15, 151515)
datetime.datetime(2017, 11, 5, 1, 2, 38, 181818)
datetime.datetime(2017, 11, 5, 1, 7, 1, 212121)
datetime.datetime(2017, 11, 5, 1, 11, 24, 242424)
datetime.datetime(2017, 11, 5, 1, 15, 47, 272727)
...

I don't think that I can use a time series for this application given that all of my observations are at random times throughout the day and I need around 100 datapoints of interpolated times between the observations. How can I make np.interp ignore American daylight savings time and just interpolate the time as if it there is no daylight savings switch?

conchoecia
  • 491
  • 1
  • 8
  • 25
  • 1
    I'm voting to close this question as off-topic because The problem is not programming related and is unlikely to help future readers. Please send bug report to the US Congress re: Daylight Savings Time. – Daniel F Aug 30 '18 at 06:07
  • My version adds a `fold=1` during that hour:`datetime.datetime(2017, 11, 5, 1, 2, 38, 181818, fold=1)` – hpaulj Aug 30 '18 at 07:02
  • hpaulj - are you able to post your version? – conchoecia Aug 30 '18 at 13:57

1 Answers1

1

What you're seeing is US daylight savings time kicking in. At 2AM on 5 Nov 2017, it actually became 1AM again.

If you don't want to deal with US DST, I recommend using pytz to explicitly set your your time zone. It also might help to check what time zone your computer is set to, as datetime draws it's location and DST data from that. You can set it with

os.environ['TZ'] = 'Australia/Brisbane'

I think. Don't want to play around with my system too much

Daniel F
  • 13,620
  • 2
  • 29
  • 55
  • Hi Daniel, thanks for pointing that out. These times are taken from Queensland, Australia though where Daylight Savings time is not observed at all. Is there some way to correct for the seemingly baked-in feature of American Daylight Savings time in the python time packages? I have edited the question to reflect this information. – conchoecia Aug 30 '18 at 14:33
  • Probably want to ask another question, this one is buried by now. Revert your edits first so some numbskull doesn't close the new question as a duplicate of this one. – Daniel F Aug 31 '18 at 05:36