l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 20: Web Application Hacking: How to Make and Break Security on the Web
Next Installfest:
TBD
Latest News:
Oct. 10: LUGOD Installfests coming again soon
Page last updated:
2006 Jun 29 20:11

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Timezone conversions with zoneinfo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Timezone conversions with zoneinfo



I'm trying to do timezone conversions from UTC using the zoneinfo
database, by using the following routine:

date convert_to_tz(date theday, double thetime, std::string timezone){
   struct tm tm;
   time_t timenum;

   //mktime has the side effect of normalizing tm
   tm.tm_min=tm.tm_hour=0;
   tm.tm_sec=static_cast<int>(thetime*60*60);
   tm.tm_mon=theday.month()-1;
   tm.tm_mday=theday.day();
   tm.tm_year=theday.year()-1900;

   //Get timenum for the UTC time.
   setenv("TZ","UTC",1);
   tzset();
   timenum=mktime(&tm);

   //Convert back to the requested local timezone
   setenv("TZ",timezone.c_str(),1);
   tzset();
   localtime_r(&timenum,&tm);
   
   //return a value
   date returnDate(tm.tm_mon+1,tm.tm_mday,tm.tm_year+1900);
   returnDate.hour(tm.tm_hour);
   returnDate.min(tm.tm_min);
   return returnDate;
}

date is a class I wrote for handling dates. thetime is a double
representing a fractional number of hours. (I've been using
approximately 10 and 25 for this number)

The code behaves correctly for the DST change between 4/1/2006 and
4/2/2006, but the upcoming DST change between 3/10/2007 and 3/11/2007
is being encountered a day early (i.e. between 3/9/2007 and
3/10/2007).

However the date(1) gets the time change right.

[bloom@little-cat-a zmanim-simpletz]$ date -d '3/10/2007 10:00pm'
Sat Mar 10 22:00:00 EST 2007
[bloom@little-cat-a zmanim-simpletz]$ date -d '3/11/2007 10:00pm'
Sun Mar 11 22:00:00 EDT 2007

Any idea what's wrong with my code? Is it my code at all? Is there
someone appropriate to ask whether it's a system bug?

--Ken Bloom

-- 
I usually have a GPG digital signature included as an attachment.
See http://www.gnupg.org/ for info about these digital signatures.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech


LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.