So here I'm working with gpx files. Take note of an excerpt of one:
<?xml version="1.0" encoding="UTF-8"?>
<!-- GPSTrack 2.2.1 — http://bafford.com/gpstrack -->
<gpx xmlns="http://www.topografix.com/GPX/1/1">
<trk>
<name><![CDATA[2016-03-31 10-17-54]]></name>
<trkseg>
<trkpt lat="38.704859" lon="-8.970304"><ele>13.050667</ele><time>2016-03-31T09:17:51Z</time><!-- hAcc=95.768176 vAcc=10.000000 --></trkpt>
<trkpt lat="38.704894" lon="-8.970324"><ele>13.050667</ele><time>2016-03-31T09:17:55Z</time><!-- hAcc=141.087476 vAcc=10.000000 --></trkpt>
<trkpt lat="38.704859" lon="-8.970304"><ele>13.050667</ele><time>2016-03-31T09:17:55Z</time><!-- hAcc=95.768176 vAcc=10.000000 --></trkpt>
<trkpt lat="38.704878" lon="-8.970343"><ele>13.150488</ele><time>2016-03-31T09:18:43Z</time><!-- hAcc=165.000000 vAcc=10.000000 --></trkpt>
See the name of the file? It gives us the time 10H17. Now check the time for each point. It's counted with one less hour.
I still don't get how the times are messed up here. But this is the beginning of the problem.
Now, I'm parsing these many gpx files, and loading them into a PostgreSQL database. More specifically this table:
CREATE TABLE IF NOT EXISTS trips (
trip_id SERIAL PRIMARY KEY,
start_location TEXT REFERENCES locations(label),
end_location TEXT REFERENCES locations(label),
start_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
end_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
bounds geography(POLYGONZ, 4326) NOT NULL,
points geography(LINESTRINGZ, 4326) NOT NULL,
timestamps TIMESTAMP WITHOUT TIME ZONE[] NULL
);
Even while using TIMESTAMP WITHOUT TIME ZONE
the points are being loaded with the wrong hour (one less hour). This happens only in the days after the Daylight Savings Time is in effect. The point here: is there any way to check if a date is on DST time and add one hour to it if that checks?
I checked for tm_isdst
and datetime.dst()
but I still don't understand it.