473,385 Members | 1,546 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,385 software developers and data experts.

Converting datetimes from/to UTC/GMT including daylight saving

Hi all,

I need to convert datetimes from any timezone to UTC and back
considering daylight saving. It is not enough, to just add or subtract
the timezone offset.
Also, I can not use c functions and structures like localtime and
time_h, since they only can handle datetimes "younger" than
01/01/1970. I need to handle birthday dates also.
I tried to integrate Boost libraries (see www.boost.org), but I was
not able to get them running together with SGI STL and also got
internal compiler errors when compiling them with MS VC++ 6 SP5.
So should you have any suggestions, they would be HIGHLY appreciated.
Thanx in advance.

Regards,
Michael
Nov 14 '05 #1
4 6581
In article <91**************************@posting.google.com >,
mu*******@web.de says...
I need to convert datetimes from any timezone to UTC and back
considering daylight saving. It is not enough, to just add or subtract
the timezone offset.
Worst case, build a table of timezones and which of them use DST and
which do not, along with their normal offsets from UTC and do it
yourself.
Also, I can not use c functions and structures like localtime and
time_h, since they only can handle datetimes "younger" than
01/01/1970.
ITYM "can't handle" typically?
I need to handle birthday dates also.


Well, if you need a bigger date format, something like ISO 8601
might be handy (google should tell you more than enough). It
incudes the century in the date format, so you should be able
to represent any date AD, surely you aren't worrying about
birthdays of anyone before then?

The "calendar FAQ" (again google) might be very helpful to you
as well.

Or roll your own "big date" format and what not.
--
Randy Howard _o
2reply remove FOOBAR \<,
______________________()/ ()______________________________________________
SCO Spam-magnet: po********@sco.com
Nov 14 '05 #2
On Tue, 9 Dec 2003 11:46:12 -0600, Randy Howard
<ra**********@FOOmegapathdslBAR.net> wrote:
In article <91**************************@posting.google.com >,
mu*******@web.de says...
I need to convert datetimes from any timezone to UTC and back
considering daylight saving. It is not enough, to just add or subtract
the timezone offset.


Worst case, build a table of timezones and which of them use DST and
which do not, along with their normal offsets from UTC and do it
yourself.

Depending on how complete you want to be internationally and/or
historically, just "yes or no" for DST is not enough. There are dozens
if not hundreds of algorithms that are or have been used for DST plus
lots of instances that didn't obey any algorithm.
Also, I can not use c functions and structures like localtime and
time_h, since they only can handle datetimes "younger" than
01/01/1970.


ITYM "can't handle" typically?

ITHM *can* handle *younger* and *can't* handle *older*. (Aside: in
English we usually don't describe inanimate things, or concepts, as
"young"; "newer" or "more recent" would be better, or just "after".)

<Obtopic>The C and C++ standards do not require this limitation to the
Unix epoch, although it is practically universal.</> Of course that
doesn't help you much if you want to run on existing systems.

The Olson timezone code and database (including DST) is available from
ftp://elsie.nci.nih.gov/pub . It shouldn't be hard to change it to an
earlier epoch and larger range, using (C99) long long or equivalent,
common if not completely standard double, or just multiword arithmetic
(especially in C++ overloading normal arithmetic), although I'm not
aware of anyone having done so already. On most systems you could even
keep the nominally-same-as-standard-C API and leave your calling code
unchanged, although technically this (defining stdlib functions
yourself) is illegal; or you could change the names, e.g. my_mktime,
and the calls to them accordingly.
I need to handle birthday dates also.


I don't understand how a birthday date is different from any other.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #3
Dave Thompson <da*************@worldnet.att.net> wrote in message news:<e6********************************@4ax.com>. ..
On Tue, 9 Dec 2003 11:46:12 -0600, Randy Howard
<ra**********@FOOmegapathdslBAR.net> wrote:
In article <91**************************@posting.google.com >,
mu*******@web.de says...
I need to convert datetimes from any timezone to UTC and back
considering daylight saving. It is not enough, to just add or subtract
the timezone offset.
Worst case, build a table of timezones and which of them use DST and
which do not, along with their normal offsets from UTC and do it
yourself.

Depending on how complete you want to be internationally and/or
historically, just "yes or no" for DST is not enough. There are dozens
if not hundreds of algorithms that are or have been used for DST plus
lots of instances that didn't obey any algorithm.

Exactly that is problem
Also, I can not use c functions and structures like localtime and
time_h, since they only can handle datetimes "younger" than
01/01/1970.
ITYM "can't handle" typically?

ITHM *can* handle *younger* and *can't* handle *older*. (Aside: in
English we usually don't describe inanimate things, or concepts, as
"young"; "newer" or "more recent" would be better, or just "after".)

thanx, but I see clever guys like you get it anyway :-)))

<Obtopic>The C and C++ standards do not require this limitation to the
Unix epoch, although it is practically universal.</> Of course that
doesn't help you much if you want to run on existing systems.

The Olson timezone code and database (including DST) is available from
ftp://elsie.nci.nih.gov/pub . It shouldn't be hard to change it to an
earlier epoch and larger range, using (C99) long long or equivalent,
common if not completely standard double, or just multiword arithmetic
(especially in C++ overloading normal arithmetic), although I'm not
aware of anyone having done so already. On most systems you could even
keep the nominally-same-as-standard-C API and leave your calling code
unchanged, although technically this (defining stdlib functions
yourself) is illegal; or you could change the names, e.g. my_mktime,
and the calls to them accordingly.
I need to handle birthday dates also.


I don't understand how a birthday date is different from any other.

Well, I said that to emphasize that dates are most likely to be before
(note, I did not say "older" :-) ) 01.01.1970 and that I can not live
with that restriction
Nov 14 '05 #4
Michael Pfeifer wrote:
Dave Thompson <da*************@worldnet.att.net> wrote in message news:<e6********************************@4ax.com>. ..
On Tue, 9 Dec 2003 11:46:12 -0600, Randy Howard
<ra**********@FOOmegapathdslBAR.net> wrote:

In article <91**************************@posting.google.com >,
mu*******@web.de says...

I need to convert datetimes from any timezone to UTC and back
considering daylight saving. It is not enough, to just add or subtract
the timezone offset.

Worst case, build a table of timezones and which of them use DST and
which do not, along with their normal offsets from UTC and do it
yourself.


Depending on how complete you want to be internationally and/or
historically, just "yes or no" for DST is not enough. There are dozens
if not hundreds of algorithms that are or have been used for DST plus
lots of instances that didn't obey any algorithm.


Exactly that is problem

In addition, the time routines are not symmetric. To wit, there's

localtime() and gmtime(), which will take a time_t* and return a struct tm
with either the local or UTC time respectively. However, there is only one inverse
function: mktime(), which takes a struct tm with the localtime and returns a time_t.
There is no mkgmtime(), which would be the inverse of gmtime.

I have a similar problem to the OP, and currently have a kluged workaround, but it breaks on DST transitions.
Any suggestions would be very appreciated!

Nov 14 '05 #5

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

Similar topics

4
by: Michael Pfeifer | last post by:
Hi all, I need to convert datetimes from any timezone to UTC and back considering daylight saving. It is not enough, to just add or subtract the timezone offset. Also, I can not use c functions...
14
by: Amitabh Deepak | last post by:
Is there any way to check whether daylight saving is enabled on a linux machine?
1
by: Drew | last post by:
Is there a way to check if it is daylight savings or not via c#? I have heard you can use System.Globalization? Thanks - Drew
6
by: Robm | last post by:
Since googling this issue only brings up the April fool's problem, which was solved years ago, I hope that somebody can help me with this. I have a large vc++/mfc application which needs to know...
0
by: Chirag Shukla | last post by:
Colleagues, I wanted to share a function to find if a date is in Daylight Saving Time or not. I was able to make this function faster than reading MSDN to find functions that .NET provides. I...
2
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, My app picks ccurrent time on the PC to retrieve data from sql DB, the Sql data is always data with non-daylight saving. The app runs on PC with both daylight saving and non-daylight...
6
by: shivaranjan | last post by:
Hi, I need to calculate the local time without considering the daylight saving into account. Is there any way to do it?. I want to use the ANSI C routines present as this program needs to be...
3
by: bernhard Hoyler | last post by:
Hi, I would like to determine whether at a certain time point in time the daylight savings time is in effect. This means such a logic should show that today (16-Nov-2007) no daylight savings...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I have a web application that will be hosted on servers with timezones configured to EST with daylight saving. My application takes an XML datafeed that contains times in GMT (also with...
4
by: Rohit | last post by:
I am trying to get client machine's timezone from my java script . But i have no idea how would i be able to get it in uclibc format. (e.g. GMT+0IST-1,M3.5.0/01:00:00,M10.5.0/02:00:00) . I saw...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.