Commit a2f00aff authored by Olav van Duin's avatar Olav van Duin Committed by Tjerk Vreeken

Fix flooring of dates/times in PI-XML import

Before, we would floor based on the base time (midnight 1-1-1970). This
would mean that having a start date of e.g. 09:35 and a time step of
00:15 did not work well together. The start date would get rounded down
to 09:30 instead of the desired 09:35. This commit makes sure that such
cases are handled correctly, but that rounding is still performed (e.g.
09:51 will get rounded down to 09:50).

Closes #1020
parent 9ce64c09
......@@ -642,10 +642,13 @@ class Timeseries:
raise Exception('Unsupported unit type: ' + el.get('unit'))
def __floor_date_time(self, dt, tdel):
# Floor a PI date time based on a PI time step
Floor a PI date time to an integer number of PI time steps from the
start date time.
roundTo = tdel.total_seconds()
seconds = (dt - dt.min).seconds
seconds = (dt - self.__start_datetime).seconds
# // is a floor division:
rounding = (seconds + roundTo / 2) // roundTo * roundTo
return dt + datetime.timedelta(0, rounding - seconds, -dt.microsecond)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment