TimeZoneOffset()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

TimeZoneOffset()

Post by Rescator »

Originally by netmaestro but I modified it a bit!
It returns the timezone offset in seconds as well
so you can use normal "math" to modify the result of Date() directly.

Code: Select all

Procedure TimeZoneOffset()
 Protected result,mode
 mode=GetTimeZoneInformation_(@TZ.TIME_ZONE_INFORMATION)
 If mode=1
  result-TZ\Bias
 ElseIf mode=2
  result-TZ\Bias-TZ\DaylightBias
 EndIf
 ProcedureReturn result*60
EndProcedure

Debug TimeZoneOffset()
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

THe above returns the timezone offset as seconds "from" UTC.
So europe is + and the US would be - etc.

Alternatively it could also be implemented as:

Code: Select all

Procedure TimeZoneOffset()
 Protected result,mode
 mode=GetTimeZoneInformation_(@TZ.TIME_ZONE_INFORMATION)
 If mode=1
  result=TZ\Bias
 ElseIf mode=2
  result=TZ\Bias+TZ\DaylightBias
 EndIf
 ProcedureReturn result*60
EndProcedure

Debug TimeZoneOffset()
Same as previous suggestion but instead it's returned as a timezone offset modification value.

So one could simply do:

Code: Select all

Debug Date()+TimeZoneOffset()
Which should be better performance wise than doing

Code: Select all

Debug Date()-TimeZoneOffset()
as in the first example.

Either solution is fine though, but we do need TimeZoneOffset() in some form or shape :)
Especially since various internet protocols and software uses UTC.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

also, you can look at this thread :

http://www.purebasic.fr/english/viewtop ... t=timezone
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Post Reply