Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Getting timezone or UTC offset?
Getting timezone or UTC offset? [message #23446] Tue, 20 October 2009 16:37 Go to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I am wondering about a U++ method to tell me the timezone offset or to get the time in UTC. I am thinking that it should be there but I'm just missing it somewhere.

Jeremy
Re: Getting timezone or UTC offset? [message #23465 is a reply to message #23446] Wed, 21 October 2009 09:36 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Tue, 20 October 2009 10:37

I am wondering about a U++ method to tell me the timezone offset or to get the time in UTC. I am thinking that it should be there but I'm just missing it somewhere.

Jeremy



It is not there yet.

Mirek
Re: Getting timezone or UTC offset? [message #23471 is a reply to message #23465] Wed, 21 October 2009 18:35 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I have created GetUtcDate(), GetUtcTime(). I have not tested these functions on Linux, though. The Windows version works fine.

Would these be suitable for inclusion in U++?

Jeremy
  • Attachment: gmtime.diff
    (Size: 1.33KB, Downloaded 348 times)
Re: Getting timezone or UTC offset? [message #23472 is a reply to message #23471] Wed, 21 October 2009 22:20 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Wed, 21 October 2009 12:35

I have created GetUtcDate(), GetUtcTime(). I have not tested these functions on Linux, though. The Windows version works fine.

Would these be suitable for inclusion in U++?

Jeremy



Yes, but we need TESTED Linux version....

Mirek
Re: Getting timezone or UTC offset? [message #23475 is a reply to message #23472] Wed, 21 October 2009 23:16 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
I was hoping you had access to a Linux install. I have Linux on a remote server, but no GUI interface nor U++ installed.

Jeremy
Re: Getting timezone or UTC offset? [message #23477 is a reply to message #23475] Thu, 22 October 2009 08:17 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jeremy_c

I will try it.

Best regards
Koldo


Best regards
Iñaki
Re: Getting timezone or UTC offset? [message #23478 is a reply to message #23477] Thu, 22 October 2009 09:32 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jeremy_c

With an small change in GetUtcTime they work well. Here it is the changed version:

Time GetUtcTime() {
	time_t gmt = time(NULL);
	struct tm *utc = gmtime(&gmt);
	return Time(utc->tm_year + 1900, utc->tm_mon + 1, utc->tm_mday, 
		utc->tm_hour, utc->tm_min, utc->tm_sec);
}

Best regards
Koldo


Best regards
Iñaki
Re: Getting timezone or UTC offset? [message #23480 is a reply to message #23478] Thu, 22 October 2009 13:03 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Thanks koldo, luzr, can they be added now?

Jeremy
Re: Getting timezone or UTC offset? [message #23483 is a reply to message #23480] Thu, 22 October 2009 16:55 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Thu, 22 October 2009 07:03

Thanks koldo, luzr, can they be added now?

Jeremy



Yes!

Mirek
Re: Getting timezone or UTC offset? [message #23484 is a reply to message #23483] Thu, 22 October 2009 18:14 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Thanks. I knew it would need to be tested in Linux, I just didn't have that ability at this time (easily).

Jeremy
Re: Getting timezone or UTC offset? [message #23488 is a reply to message #23484] Fri, 23 October 2009 01:32 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Hello Jeremy_c

Quote:

Thanks. I knew it would need to be tested in Linux, I just didn't have that ability at this time (easily).

I have tried your code from a windows XP computer with Portable Ubuntu. Nothing installed, no partition, no Wubi, no switch off and on, just run it using windows programs at the same time.

Not very fast but everyting works (but graphics acceleration). If you can I think it is a great idea.

Best regards
Koldo


Best regards
Iñaki
Re: Getting timezone or UTC offset? [message #23489 is a reply to message #23488] Fri, 23 October 2009 01:37 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Thanks for the suggestion koldo, I'll do it. I use to live in Linux but I gave in to the constant need of Windows for my work. I got tired of switching back and forth :-/

Jeremy

[Updated on: Fri, 23 October 2009 01:37]

Report message to a moderator

Re: Getting timezone or UTC offset? [message #24307 is a reply to message #23446] Sun, 10 January 2010 08:57 Go to previous messageGo to next message
Shire is currently offline  Shire
Messages: 41
Registered: September 2006
Location: Russia, Yamal peninsula
Member
IMHO, GetUTCTime() and GetSysTime() is not quite correct.

Better and correct name for GetSysTime is GetLocalTime.

GetUTCTime() works wrong with Time::AsFileTime() - if time will be not local, this method returns invalid file time.

One of workarounds of this problem is typedef int64 (or incapsulate it to struct) as UTC time offset type. GetUTCTime() will return this value, which can be converted to/from local Time by Time::Set()/Get() and will be good for time serialization to present same time in different time zones.
Re: Getting timezone or UTC offset? [message #24546 is a reply to message #24307] Sat, 23 January 2010 20:32 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Shire wrote on Sun, 10 January 2010 02:57

IMHO, GetUTCTime() and GetSysTime() is not quite correct.

Better and correct name for GetSysTime is GetLocalTime.



I agree, but 'Sys' has to stay - too many code written already.

Quote:


GetUTCTime() works wrong with Time::AsFileTime() - if time will be not local, this method returns invalid file time.



FileTime is always local.

But it looks like we should have some conversion functions, right?

Mirek
Re: Getting timezone or UTC offset? [message #24550 is a reply to message #24546] Sat, 23 January 2010 22:11 Go to previous messageGo to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
luzr wrote on Sat, 23 January 2010 14:32

Shire wrote on Sun, 10 January 2010 02:57

IMHO, GetUTCTime() and GetSysTime() is not quite correct.

Better and correct name for GetSysTime is GetLocalTime.



I agree, but 'Sys' has to stay - too many code written already.




I wonder if GetLocalTime shouldn't be a define and from here on out encourage people to use GetLocalTime simply for clarity in their own apps.

Jeremy
Re: Getting timezone or UTC offset? [message #24552 is a reply to message #24550] Sat, 23 January 2010 23:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Sat, 23 January 2010 16:11

luzr wrote on Sat, 23 January 2010 14:32

Shire wrote on Sun, 10 January 2010 02:57

IMHO, GetUTCTime() and GetSysTime() is not quite correct.

Better and correct name for GetSysTime is GetLocalTime.



I agree, but 'Sys' has to stay - too many code written already.




I wonder if GetLocalTime shouldn't be a define and from here on out encourage people to use GetLocalTime simply for clarity in their own apps.

Jeremy



Does not need to be #define, Time GetLocalTime() { return GetSysTime(); } (or vice versa) would work as well.

Still, at this stage, IMO it is nitpicking. After all, you set your PC time in BIOS to your local time -> I would say system time is local then...

Mirek
Re: Getting timezone or UTC offset? [message #24799 is a reply to message #24546] Sat, 30 January 2010 15:36 Go to previous messageGo to next message
Shire is currently offline  Shire
Messages: 41
Registered: September 2006
Location: Russia, Yamal peninsula
Member
[quote title=luzr wrote on Sun, 24 January 2010 00:32]
Shire wrote on Sun, 10 January 2010 02:57


Quote:


GetUTCTime() works wrong with Time::AsFileTime() - if time will be not local, this method returns invalid file time.



FileTime is always local.


On Win32 it is not local:
MSDN FILETIME Structure
Quote:


FILETIME. Contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).



luzr wrote on Sun, 24 January 2010 00:32


But it looks like we should have some conversion functions, right?


Right.
Re: Getting timezone or UTC offset? [message #24804 is a reply to message #24799] Sat, 30 January 2010 19:48 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry, my info was incorrect. Correct description:

FileTime value is unspecified. Allowed operations are comparisons and conversion from/to Time.

When converted to Time, the result is local time.
Previous Topic: Bug?: Command line arguments passing problem (Windows)
Next Topic: VC2010
Goto Forum:
  


Current Time: Fri Mar 29 16:14:48 CET 2024

Total time taken to generate the page: 0.01642 seconds