help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Time confusion?


From: Vic Norton
Subject: Time confusion?
Date: Wed, 10 Mar 2004 11:45:09 -0500

Maybe this is a bug. Maybe it isn't. In any case, it is very confusing. I'm talking about the relationship between time structures and the functions strptime, strftime, and mktime.

Start with the date 23-Feb-04. That was a Monday. Do strptime to get a TM_STRUCT and then do strftime to that. This changes the day. Now 23-Feb-04 is Sunday.

OK, let's get down to real time. Do mktime to the TM_STRUCT to see that the 23-Feb-04 date is 1077512400 seconds after after 1-Jan-1970 00:00:00 CUT. (1077512400 is also the time I get from the str2time function in the Date::Parse perl module.) Now do localtime to 1077512400 and strftime to the resulting TM_STRUCT to find out that 23-Feb-04 is back to Monday.

Something is very strange here. One date just can't be on two different days!

Regards,

Vic

P.S. Here is the test and the output.

=== test ===
% test1.m

date0 = '23-Feb-04'
tm_struct1 = strptime(date0, "%e-%b-%y")
date1 = strftime("%a, %e-%b-%y", tm_struct1)
time1 = mktime(tm_struct1)
tm_struct2 = localtime(time1)
date2 = strftime("%a, %e-%b-%y", tm_struct2)

=== output ===
octave> test1
date0 = 23-Feb-04
tm_struct1 =
{
  hour = 0
  isdst = 0
  mday = 23
  min = 0
  mon = 1
  sec = 0
  usec = 0
  wday = 0
  yday = 0
  year = 104
  zone =
}

date1 = Sun, 23-Feb-04
time1 = 1077512400
tm_struct2 =
{
  hour = 0
  isdst = 0
  mday = 23
  min = 0
  mon = 1
  sec = 0
  usec = 0
  wday = 1
  yday = 53
  year = 104
  zone = EST
}

date2 = Mon, 23-Feb-04



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]