Daylight saving problems when using winapi's timezone functions.

Hi, I get times from a server given in UTC (Coordinated 
Universal Time or Universal Time Coordinated), 
that is similar to GMT (Greenwich Mean Time) but not 
adjusted to daylight saving time. That is, during 
summer, UTC differs one hour from London time, since UK 
uses daylight saving during summer.

The application I develop is used worldwide so I can not 
assume or hardcode anything. This should not
be a problem since winapi have functions to handle this. 
I do the following.

The function I use to convert UTC time to local time (New 
York time for me) looks like this:

COleDateTime ConvertToLocalTime(const COleDateTime& 
timeUTC)
{
// Set time environment variables.

_tzset();

// Output environment variables

CString str;
str.Format("offset = %d, daylight = %d, %s, %s\n", 
_timezone, _daylight, _tzname[0], _tzname[1]);
cout << (LPCTSTR)str<< endl;

// Adjust given time to local time.

COleDateTimeSpan timeSpanOffset(0, 0, 0, _timezone);

COleDateTime timeLocal = timeUTC - timeSpanOffset;

// Output local time

str.Format("time UTC = %s, time local = %s", 
timeUTC.Format("%H:%M:%S"), timeLocal.Format("%H:%M:%S"));
cout << (LPCTSTR)str<< endl;

return timeLocal;
}

and produces the following output:

offset = 18000, daylight = 1, Eastern Standard Time, 
Eastern Daylight Time
time UTC = 11:23:45, time local = 06:23:45

Five hour difference which is fine during winter time, 
but when daylight saving is in effect, it only differs 
four hours. Windows apperently handles this fine, the 
clock in the notification area adjusts properly, but is 
there some way from the API to find out if daylight 
saving is in effect or not? Are there other ways than 
using 
the functions I been using? _daylight only tells you if 
Windows should adjust for daylight saving or not. 
Disabling automatic adjust of daylight saving in the 
Windows clock only affects the output as follows:

offset = 18000, daylight = 0, Eastern Standard Time, 
Eastern Standard Time
time UTC = 11:23:45, time local = 06:23:45

Thanks, Mellowman
0
patric_j (1)
10/16/2003 3:58:35 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
870 Views

Similar Articles

[PageSpeed] 0

I have a simple SNTP client app where I need to do the same thing.  My case
correctly handles daylight savings, here's the relevant section of code:

DWORD tzResult;
TIME_ZONE_INFORMATION tzInfo;
// Get time zone offset
tzResult = GetTimeZoneInformation(&tzInfo);
m_Bias = (int)tzInfo.Bias;
switch(tzResult)
{
case TIME_ZONE_ID_STANDARD:
    m_Bias += (int)tzInfo.StandardBias;
    m_TZ = tzInfo.StandardName;
    break;

case TIME_ZONE_ID_DAYLIGHT:
    m_Bias += (int)tzInfo.DaylightBias;
    m_TZ = tzInfo.DaylightName;
    break;

case TIME_ZONE_ID_UNKNOWN:
    break;

default:
    m_Bias = 0;
}
m_Bias now holds the correct timezone offset from UTC in seconds for the
local time regardless of the time of year (assuming the computer has a
correctly configured clock and operating system).  GetTimeZoneInformation()
is a Win32 function IIRC.

"Patric" <patric_j@hotmail.com> wrote in message
news:01b301c393fe$5aef3bf0$a101280a@phx.gbl...
> Hi, I get times from a server given in UTC (Coordinated
> Universal Time or Universal Time Coordinated),
> that is similar to GMT (Greenwich Mean Time) but not
> adjusted to daylight saving time. That is, during
> summer, UTC differs one hour from London time, since UK
> uses daylight saving during summer.
>
> The application I develop is used worldwide so I can not
> assume or hardcode anything. This should not
> be a problem since winapi have functions to handle this.
> I do the following.
>
> The function I use to convert UTC time to local time (New
> York time for me) looks like this:
>
> COleDateTime ConvertToLocalTime(const COleDateTime&
> timeUTC)
> {
> // Set time environment variables.
>
> _tzset();
>
> // Output environment variables
>
> CString str;
> str.Format("offset = %d, daylight = %d, %s, %s\n",
> _timezone, _daylight, _tzname[0], _tzname[1]);
> cout << (LPCTSTR)str<< endl;
>
> // Adjust given time to local time.
>
> COleDateTimeSpan timeSpanOffset(0, 0, 0, _timezone);
>
> COleDateTime timeLocal = timeUTC - timeSpanOffset;
>
> // Output local time
>
> str.Format("time UTC = %s, time local = %s",
> timeUTC.Format("%H:%M:%S"), timeLocal.Format("%H:%M:%S"));
> cout << (LPCTSTR)str<< endl;
>
> return timeLocal;
> }
>
> and produces the following output:
>
> offset = 18000, daylight = 1, Eastern Standard Time,
> Eastern Daylight Time
> time UTC = 11:23:45, time local = 06:23:45
>
> Five hour difference which is fine during winter time,
> but when daylight saving is in effect, it only differs
> four hours. Windows apperently handles this fine, the
> clock in the notification area adjusts properly, but is
> there some way from the API to find out if daylight
> saving is in effect or not? Are there other ways than
> using
> the functions I been using? _daylight only tells you if
> Windows should adjust for daylight saving or not.
> Disabling automatic adjust of daylight saving in the
> Windows clock only affects the output as follows:
>
> offset = 18000, daylight = 0, Eastern Standard Time,
> Eastern Standard Time
> time UTC = 11:23:45, time local = 06:23:45
>
> Thanks, Mellowman


0
mairdanot (111)
10/17/2003 8:02:16 PM
Reply:

Similar Artilces:

300 Locations+ using RMS?
Does anyone out there have 300-400 locations operating on RMS? Is this even possible. Currently we have 80 with a projected 150 next year and 200 following. Within 5-10 years we will hit 500-1,000. Can RMS support a company of our size? Has anyone pushed the system to this level? -- Jocelyn wow :) Is there a HQ Dongle with license up to 1000+ locations...your company is rocketing :) Is your company in fashion retail ?Food? Your implementation is quite big. how was the performance of RMS hitting 80 locations? Are you using HQ (I suppose you do.)? how's the speed in terms of conne...

How do I insert a radio button using Excel 2007?
How do I insert a 2 radio button group using Excel 2007 and of course how do i program them? thank you in advance. The following code will create a Frame and two Option Buttons at cell C3. Change the various Top and Left properties to get them positioned as you want. Sub AAA() Dim FRA As OLEObject Dim BTN1 As OLEObject Dim BTN2 As OLEObject Dim WS As Worksheet Dim TopLeftCell As Range Dim VBComp As VBIDE.VBComponent Dim CodeMod As VBIDE.CodeModule Dim N As Long Set WS = Worksheets("Sheet1") Set TopLeftCell = WS.Rang...

about function keys
This is a multi-part message in MIME format. ------=_NextPart_000_0149_01CA656F.25EEE970 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I went out a got a new keyboard. guess what? the function keys don't work on the new one. could this be anything with windows 7 by any chance????? bonnie ------=_NextPart_000_0149_01CA656F.25EEE970 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HT...

Speech Function
Can the speech function be added to Excel version 9.0.2719? Or is it already there? Speech was added in xl2002. You may want to look for a third part voice recognition program. Gayle wrote: > > Can the speech function be added to Excel version 9.0.2719? Or is it already > there? -- Dave Peterson ec35720@msn.com ...

Better Return Function
1. When Recall Transaction For Return, instead of bringing up everything that was purchased in return mode ( and having to delete the ones not being return), there should be an option to make the POS to ask the user to scan/enter the item to be return. Then the program has to check that the item scanned does exists in that transaction. 2. Returned item from that transaction should not be allowed to be return again. 3. In Recall Transaction For Return mode, have the ability to block user from giving credit/cash back to customer. 4. In Recall Transaction For Return mode, do not pref...

Report Writer
I know report writer is not agreat tool and Crystal is an option. However, I would like to achieve this in report writer. I simply want some 'boxes' and 'lines' on my invoice so that the fields 'appear' as if they are in a table. I can get lines and boxes in, but how do I get the box to extend down to the top of my report footer? Have a look at the SOP Blank Invoice for an example. In a graphic report, you can draw a box by adding the top horizontal line to the page or report header and then add vertical lines that start in the same section but are as long a...

Problem Veiwing Reports in CRM 3.0
Hi, I am having problems viewing reports in CRM Webclient. I log on as a standard user click on the report edit the filter and generate the report, and the system says the page cannot be displayed. If i log on as administrator it works, so i am assuming it is a permissions issue. Where and how to i change this so all users can view and generate reports? Any help on this issue would be much appreciated, thanks in advance Hi, Now the administrator cannot view the reports, apart from going to the report server via IP. Any help would be great. "Patrickh" wrote: > Hi, > ...

phone textbox default value problem
I have a phone field and I have a default area code set and when I tab to the field the area code is highlighted and I have to click off of it to enter data. How can I have it so when I tab to the field I can immediatly start typing the phone number after the area code? If the area code is different than the default I figure I could just back space and change it. 90% of the time the default will be correct. I have the input mask as !\(999") "000\-0000;0;_ and the default value as (916), I am leaving the formatting info in because I have to import the data and it has the...

Office apps won't open, report Office in use by another use
Version: 2004 Operating System: Mac OS X 10.4 (Tiger) Processor: Intel A few days ago, our Office applications started showing the report that "An Office program is being used by "user." your installation exceeds the number of installations permitted by thelicense agreement. Click More Information to learn about Microsoft Office licensing." But OFFICE ISN'T BEING USED BY ANYONE. All computers have been restarted to no avail. HELP! <sakas@officeformac.com> wrote: > A few days ago, our Office applications started showing the report that > "An Office p...

Using auto
Hi, Good Day to everyone... I 'am currently using Microsoft Outlook 2003...My Boss wants me to make accounts that will be able to send and receive messages....I have been trying to do it manually, but when I try to do the send/receive messages an error occurs. Someone explained to me to do a Auto Configuration using the cpanel of the site....I tried it but then I don't know how to use it.....in the Tools menu the send and receive button disappeared.....i have no idea on what is currently happening.....and I can't make sure if the mail accounts have been add to outlook e-m...

use of countif()
Hi. Does anyone knows how can apply the countif() function partial? (for ex. If i have the column A10:A100 to apply countif() in the follow cells A54, A67, A72:A79 , A87, A91:A95, A98.) If that impossible, any other idea? Thanks. One way =SUMPRODUCT(COUNTIF(INDIRECT({"a2","a5","a8","e10"}),"a")) -- Don Guillett SalesAid Software dguillett1@austin.rr.com "nikos" <nikos@discussions.microsoft.com> wrote in message news:0702BFB4-B60A-42D4-8B04-C5D055CC5072@microsoft.com... > Hi. > > Does anyone knows how can appl...

Getting a LockMatchID error using sp_rename
When I'm trying to rename a table in the tempdb table, I'm getting an error when I run it in a stored procedure or code, but it works ok on MSSMS. I get the error: Invalid EXECUTE statement using object "Object", method "LockMatchID". EXEC sp_rename 'Tempdb.dbo.oldFile' , 'newFile' Don't ask me why I have to mess with the tempdb files (This is probably the problem). But I have old legacy code that writes to the tempdb database. On Jul 14, 10:00=A0am, Cindy Lee <danparker...@yahoo.com> wrote: > When I'm trying to renam...

"Theme" and "recently used" font list
How do I change the "theme" and "recently used" font list? "WD2000: How to Turn off the Font Most Recently Used (MRU) List" at http://support.microsoft.com/?kbid=199785; for Word 2002, see http://support.microsoft.com/?kbid=289506; for Word 2003, see http://support.microsoft.com/?kbid=820917. -- <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> &g...

Exchange 2000/2003 Routing Problems
I recently added a new Exchange 2003 server to our 1 server Exchange 2000 org. I am able to send mail from the new Exchange 2003 server to the 2000 server. But when I send to the 2003 server the mail does not go delivered. I am assuming this is a routing issue. How can I troubleshoot this? Should each server be in a seperate routing group and use a routing group connector? They are currently i n the same routing group. Thanks, Forest In case anyone has this problem my STMP connector was setup to use a smart relay. I had to check the box that said attempt local delivery before using...

VBA Function Reference
Is there a good VBA reference manual or website? I have in mind something like the Principles of Operations manuals (for you dinosaurs who remember Assembly Language) that shows each function with the parameters and a few examples. For which Office program and version? They vary depending on version, and each program has it's own objects and methods. --JP On Mar 18, 10:31=A0am, Square Peg <Square...@Round.Hole> wrote: > Is there a good VBA reference manual or website? > > I have in mind something like the Principles of Operations manuals > (for you dinosaurs who remem...

Find function in a macro
I want to set up a macro that searches a column for a value 'X' and then selects the cell right under the cell that contains 'X'. I have been stumped on this for a few days now and would really really appreciate any sort of help or guidance. Thanks a lot! SK --- Message posted from http://www.ExcelForum.com/ Sub Findit() Dim r as Range For Each r in Range("A1:A1000") 'Or whatever yours is If r.Value = "X" Then Range("A" & r.Row+1).Select 'Change A to your column Exit For End If Next End Sub K P.S. You could probably use an...

MIME hdr problems
we send mail from Goldmine application through our exchange smtp server. A few emails are being sent back. The NDR is 5.7.1 but in the header I see this line: x-amavid alert" BAD HEADER MIME error: illegal encoding [base64] for mime type message /rfc822 I appreciate this is not necessarily an exchange issue but hoping someone might know something about this and what I steps i can take to solve it. sandgroper <sandgroper@discussions.microsoft.com> wrote: >we send mail from Goldmine application through our exchange smtp server. A >few emails are being sent back. The NDR...

dynamic charts using named formulas
I have dates in the first row I have values in the second row I use tecnique of named formuls of offset function (tushar Methta) so that the chart is updated when data for new dates are added. now after some time I want to delete the older data If I delete the columns of older dates the named formula get messed up and I get error message that three is some wrong reference. actulally in the offset formula the starting cell is relaced by "REF" Then I have to redo the whole exercise any solutions. If the first row is some sort of header that doesn't get deleted, use it as the ba...

free/busy problem, again
Sorry to bump this, but I really need to figure this out. Here's the origiinal question, (thanks, EdC for the original response) for clarification, "co-exist" with exchange 5.5 is what the exchange 2003 setup "wizard" that I was running from the CD called it. It walked you through the process in 30 easy steps! Anyway, there is just the one organization with the two servers: I have an exchange 5.5 server, which for various reasons, the schedule+ free/busy folders are gone/corrupted/not working. I set up a new exchange 2003 server in co-exist mode, and moved some...

Problem with installation of Microsoft Office Enterprise 2007
L.S. I have problem with re-installing Microfost Office Enterprise 2007. With the help of Google I discovered that a part of the problem were the remnants of the former installation that didn't show up in the "Software" window, and I removed them using Windows Install Cleanup. Now the installation process is proceeding further that before, but still cancels at a certain point, restarting the computer doesn't seem to help. In the "SetupExe"document in my \Temp map the following frase seems to point at the error in the installation: Log level chan...

Problem with backup of microsoft exchange information store
Having a problem with backup exec 10d backing up microsoft exchange information store. Worked yesterday, but not today. Error is as below. Anyone have any ideas? Thanks Job ended: Wednesday, August 23, 2006 at 8:49:28 PM Completed status: Failed Final error: 0xe0008488 - Access is denied. Final error category: Security Errors For additional information regarding this error refer to link V-79-57344-33928 Backup- \\NYMAIL03\Microsoft Exchange Information Store V-79-57344-33928 - Access is denied. Access denied to database . Hi, You should rally check with Veritas, but here is what a ...

Mail merge problem #3
Running Publisher 2003, Word 2003 I have a Word document -- with an Avery label format -- containing my mailing list. When trying to mail merge with the wizard, it errors out saying; "Some of the field names in this data source are blank or contain invalid characters, such as periods, brackets, or exclamation points. Change these field names before you import data from this data source." I've cleared out all the punctuation, etc. marks that are there and cleared out any blank "Labels". I'm still getting this error. What's up? Will I be able to make...

Invoice Designer portrait/landscape problems
I'm using Money 2004 Small Business edition with winXP. I go into Invoice Designer and open the template 'Service Portrait 1 (Logo)'. This opens, and gives me nearly enough to the invoice layout I would want subject to a few minor alterations. If I then save this template as a new template (with or without any alterations), open the invoice feature within Money and select this new template as the one I want to use, the print preview gives me a landscape orientation of this invoice. It also prints as landscape. (Choosing the original 'Service Portrait 1 (Logo)' templat...

Can I Save My Relationship
What if you could recapture your ex lovers mind, heart and soul?...Wipe the slate clean? Turn back time? Even if you feel right now that your situation is too far gone=85too screwed up =85or just plain too darn complicated? You already know how hard it is to just even wake up and roll out of bed in the morning. You leave your radio off on your way to work because every song is a painful reminder of him. You can't even bear to eat at the same restaurants you took her to. And if that isn't bad enough, you have to cope with the loss of friends and family that are on their side. Did you...

OL 2003 and MAPPOINT problem
Using OL 2003 with Mappoint 2004. The Cut & Paste function using Ctrl-C and Ctrl-V is malfunctioning. When doing a cut & paste using the Ctrl functions, the MAPPOINT symbol is always PASTED into the new area (Mappoint has not been involked in the session to create a map to paste). IF I use the EDIT | COPY menu items and then the EDIT|Paste into the new area, the selected text is properly pasted. Displaying the Office Clipboard confirms what is happening, but WHY? Previously, I used OL 2002 with a prev version of Mappoint and this operation worked fine. Ideas?? or is this a ...