DragonFly BSD
DragonFly users List (threaded) for 2011-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

mktime isn't doing what I expect


From: Pierre Abbat <phma@xxxxxxxxxxxxx>
Date: Wed, 19 Oct 2011 16:20:16 -0400

This isn't a problem with the DragonFly library (I ran it on Linux and got the 
same result), but I hope you can help me.

I have a function:

time_t parse_time(string taim,char *tz)
{tm timest;
 time_t tsepoch;
 timest.tm_year=strint(taim.substr(0,4));
 timest.tm_mon =strint(taim.substr(4,2));
 timest.tm_mday=strint(taim.substr(6,2));
 timest.tm_hour=strint(taim.substr(9,2));
 timest.tm_min =strint(taim.substr(11,2));
 timest.tm_sec =strint(taim.substr(13,2));
 timest.tm_wday=timest.tm_yday=timest.tm_gmtoff=0;
 cout<<timest.tm_year<<"-"<<timest.tm_mon<<"-"<<timest.tm_mday;
 cout<<" "<<timest.tm_hour<<":"<<timest.tm_min<<":"<<timest.tm_sec<<endl;
 timest.tm_isdst=-1;
 timest.tm_zone=tz;
 tsepoch=mktime(&timest);
 cout<<timest.tm_year<<"-"<<timest.tm_mon<<"-"<<timest.tm_mday;
 
cout<<" "<<timest.tm_hour<<":"<<timest.tm_min<<":"<<timest.tm_sec<<" "<<tsepoch<<endl;
 return tsepoch;
 }

It's supposed to convert a string to seconds since epoch. Everything looks 
fine except the return value, which is always -1, which indicates an error in 
mktime. Here's the output:

2011-9-6 1:8:58
2011-9-6 1:8:58 -1
DTSTART   20110906T010858
2011-9-6 1:26:8
2011-9-6 1:26:8 -1
DTEND   20110906T012608Z

Pierre
-- 
. i toljundi do .ibabo mi'afra tu'a do
. ibabo damba do .ibabo do jinga
. icu'u la ma'atman.



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