Date bug? For me, August changes to September

C de-Avillez hggdh2 at ubuntu.com
Sun Oct 13 01:07:12 UTC 2013


On Sat, 12 Oct 2013 22:57:55 +0100
David Fletcher <dave at thefletchers.net> wrote:


<snip/>

> I find my curiosity aroused too. At the moment I'm working on a little
> project to interpret gpx track files from my Garmin GPS. The lines in
> the file that contain the time the track point was recorded are like
> this:-
> <time>2013-08-12T16:08:21Z</time>
> 
> Using code similar to that in a previous project,
> PointTimeStruct.tm_year = atoi(GFTag.c_str() + 6) - 1900;
> PointTimeStruct.tm_mon = atoi(GFTag.c_str() + 11);
> PointTimeStruct.tm_mday = atoi(GFTag.c_str() + 14);
> PointTimeStruct.tm_hour = atoi(GFTag.c_str() + 17);
> PointTimeStruct.tm_min = atoi(GFTag.c_str() + 20);
> PointTimeStruct.tm_sec = atoi(GFTag.c_str() + 23);
> PointTimeStruct.tm_isdst = 0;
> 
> NextPt->SecondsSinceEpoch = mktime(&PointTimeStruct);
> 
> where GFTag is a string object loaded with the above gpx <time> line.
> 
> Debug output of the structure elements assigned above shows
> Year    113
> Month   8
> Date    12
> Hour    16
> Minute  8
> Second  21
> so I'm picking out the correct data from the gpx file. I can't
> remember the reason for subtracting 1900 from the year, but debug
> output showing NextPt->SecondsSinceEpoch is
> lat is  51.5798 degrees
> lon is  -1.82932 degrees
> ele is  87.836 metres
> Time is 1379002101 seconds
> 
> Now, if I put the time in seconds back into the date command that
> Johnny R was using I get:-
> dave at Tosh-NB520:~/code$ date -d @1379002101 +'%F %T'
> 2013-09-12 17:08:21
> 
> So, the hour has gone up by one, which I'm not too bothered about.
> Everything else is correct EXCEPT that August has changed into
> September! How the hell has that happened?

Hum. I tried it locally (and I took out the 'Z' time zone so that I
would get the same timestamp as you):

hggdh⟫ date -d 2013-08-12T16:08:21Z +%s # <- no TZ
1376323701
hggdh⟫ date -d 2013-08-12T16:08:21 <- # no TZ
Mon Aug 12 16:08:21 CDT 2013
hggdh⟫ date -d @1379002101 # <- *your* seconds-since-epoch
Thu Sep 12 11:08:21 CDT 2013
hggdh⟫ date -d 2013-08-12T16:08:21Z +%s # <- with TZ
1376323701
hggdh⟫ date -d @1376323701 # <- *my* seconds-since-epoch
Mon Aug 12 11:08:21 CDT 2013

So my guess is you have a wrong offset in your conversions.

> 
> Thanks to all who have had the patience to read this.

You are welcome :-)

..C..


-- 
ab alio expectes alteri quod feceris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20131012/3e454eac/attachment.sig>


More information about the ubuntu-users mailing list