473,414 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

inconsistencies with mktime()

I am getting some inconsistencies with mktime().

I allocate memory for my struct tm early in my program, and assign only
*some*
of the member variables.

t->tm_sec=s;
t->tm_min=m;
t->tm_hour=h;
t->tm_mday=d;
t->tm_mon=mo-1;
t->tm_year=y-1900;

I leave out tm_wday, tm_yday, & tm_isdst.

after this I free(t).

I examine the values in my debugger. When I allocate the memory, all the
values are 0. When I call mktime(t), the function changes my tm_hour
(adds an hour) and I get a certain value returned.

Why is it changing the hour?

In another part of my program (a totally different function), I allocate
memory for my struct tm (a different local struct tm), I read in data
(exactly the same values as in my other function), again I don't fill in
tm_wday, tm_yday, & tm_isdst. There seems to be some residual values
(not 0 this time)from when I allocated the memory and didn't initialize
the 3 fields.This time when I call mktime(t), it doesn't change my
tm_hour and I get a different value returned (the correct value).

Same initial values, two different calls, two different return values.

It appears mktime is trying to guess the correct date based on what I
provide.
I am thinking that perhaps whatever values happen to be in the memory
location when I allocate the memory are what are changing the values?

Should I be initializing the tm_wday, tm_yday, & tm_isdst to something?

Why is mktime() changing the hour in my struct tm?

Any suggestions?
Thanks!
John
Sep 8 '07 #1
2 3930
John Hanley wrote:
I am getting some inconsistencies with mktime().

I allocate memory for my struct tm early in my program, and assign only
*some*
of the member variables.

t->tm_sec=s;
t->tm_min=m;
t->tm_hour=h;
t->tm_mday=d;
t->tm_mon=mo-1;
t->tm_year=y-1900;

I leave out tm_wday, tm_yday, & tm_isdst.

after this I free(t).

I examine the values in my debugger. When I allocate the memory, all the
values are 0. When I call mktime(t), the function changes my tm_hour
(adds an hour) and I get a certain value returned.

Why is it changing the hour?
The tame you have set is an daylight saving for your timezone, so it has
been corrected. You have to set tm_isdst.

from the Solaris man page which expands on the standard:

If tm_isdst is positive, the original values are assumed to
be in the alternate timezone. If it turns out that the
alternate timezone is not valid for the computed calendar
time, then the components are adjusted to the main timezone.
Likewise, if tm_isdst is zero, the original values are
assumed to be in the main timezone and are converted to the
alternate timezone if the main timezone is not valid. If
tm_isdst is negative, mktime() attempts to determine whether
the alternate timezone is in effect for the specified time.
--
Ian Collins.
Sep 8 '07 #2
Ian Collins wrote:
John Hanley wrote:
>I am getting some inconsistencies with mktime().

I allocate memory for my struct tm early in my program, and assign only
*some*
of the member variables.

t->tm_sec=s;
t->tm_min=m;
t->tm_hour=h;
t->tm_mday=d;
t->tm_mon=mo-1;
t->tm_year=y-1900;

I leave out tm_wday, tm_yday, & tm_isdst.

after this I free(t).

I examine the values in my debugger. When I allocate the memory, all the
values are 0. When I call mktime(t), the function changes my tm_hour
(adds an hour) and I get a certain value returned.

Why is it changing the hour?
The tame you have set is an daylight saving for your timezone, so it has
been corrected. You have to set tm_isdst.

from the Solaris man page which expands on the standard:

If tm_isdst is positive, the original values are assumed to
be in the alternate timezone. If it turns out that the
alternate timezone is not valid for the computed calendar
time, then the components are adjusted to the main timezone.
Likewise, if tm_isdst is zero, the original values are
assumed to be in the main timezone and are converted to the
alternate timezone if the main timezone is not valid. If
tm_isdst is negative, mktime() attempts to determine whether
the alternate timezone is in effect for the specified time.

That did the trick. Thanks so much!

John
Sep 8 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: adam | last post by:
Hi all, I am having a problem with calculating a date. What I am looking to do is get the date of Sunday of this week, then use mktime() to find out other days in the past by subtracting days. ...
9
by: WebM¤nkey | last post by:
Hi folks Just found that the mktime function returns a negative value when the date is 26 march 2006 with 0 hours, 0 seconds and 0 minutes. Is this a documented problem ? Any suggestions ?
2
by: Bengt Richter | last post by:
Python 2.3.2 (#49, Oct 2 2003, 20:02:00) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import time >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 0))...
2
by: Florian Quetting | last post by:
Hi, I'm getting mad with following problem: The code compiles, but I always get a segfault and I don't have any clue why. I can't see any differences in my way of calling mktime and others. ...
4
by: McBooCzech | last post by:
Hi, on Linux (Fedora FC4) and Python 2.4.1 I am trying to know the time delta in seconds between two times given in the HHMMSS format. My code looks like: import datetime, time...
1
by: KW | last post by:
Hi all, Appreciate if someone can help me out on this. Currently, I have a tm structure holding information of the UTC time, which is very likely to be in the past, meaning not the current...
16
by: John Hanley | last post by:
I created a function that breaks down a date into broken down time, I subtract a certain number of seconds from that, then use mktime() to recompute the calendar time. It works basically except...
2
by: pedalpete | last post by:
I've got this error which keeps popping up, but I can't seem to figure out why. The error reads ' A non well formed numeric value encountered in filename on line <b>198</b>'. the lines...
5
by: Robert Latest | last post by:
Here's what happens on my Windows machine (Win XP / Cygwin) at work. I've googled a bit about this problem but only found references to instances where people referred to dates before the Epoch. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.