473,749 Members | 2,394 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3960
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
2746
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. In the code below, today is Saturday, October 16, 2004, this week's Sunday is 2004-10-17. I successfully get that. But, when I try to subtract 7 days using mktime(), I instead of getting
9
2182
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
2506
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)) 3600.0 >>> time.mktime((1969, 12, 31, 17, 0, 0, 0, 0, 1)) 0.0 >>> time.mktime((1969, 12, 31, 16, 0, 0, 0, 0, 1))
2
4713
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. --------------------------------------------------------------------------- #include <iostream> #include <sys/stat.h>
4
10243
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 ta1=(time.strptime('000001', '%H%M%S')) ta2=(time.strptime('230344', '%H%M%S')) t1=time.mktime(ta1) t2=time.mktime(ta2) print t1, t2
1
24528
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 time. So, let's say I'm in CST(-6) now, and I want to know the equivalent local time of that tm structure, how do I do that taking into consideration daylight savings adjustments?
16
14342
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 every so often, I get the date 060207 (Feb 7, 2006) which is obviously not correct. When it does this it always gives me this date. I tracked it down to my mktime() call, when I get to a certain date, mktime returns a number in 4000000000,...
2
2768
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 which contain the error are all the same. list($sHour, $sMin, $sSec)=split(':', $startTime2);
5
2188
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. Of course at home on my Linux box everything works. I know that everything has its limits somewhere, but I've never heard of March 2008 being a problem. Tomorrow I'm going to write a test loop that shows me the exact last
0
8996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6078
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.