[Off] RE: How to get the current time in a specified time zone
Timothy Penner writes: >There are a lot of nuances for timezone data; here are a few that I find >interesting - >The following article is both interesting and funny in how it explains some of >these nuances: >https://zachholman.com/talk/utc-is-enough-for-everyone-right Indeed, the whole history of Standard Time is fascinating (at least to me). It's a very recent (late 19th century) concept which came about mostly due to advances in transportation and telecommunication. Until then, Local Time was all that was needed. Under Local Time, the clocks were set to whatever time the local people/king/government decided. It didn't matter what time it was two days travel from there because the links between place were asynchronous. As transportation speeds increased and telecommunications were established the world 'shrank' (became more synchronous) and it became valuable to know the local time everywhere. But having thousands of Local Times, sometimes varying by only minutes, was difficult to manage. Hence the invention of Standard Time, based on geography (mostly longitude). Tom Benedict Optum This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately. ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
this will be a repost of links I already mentioned in my previous post. plugins to handle timezones: https://github.com/miyako/4d-plugin-tz https://github.com/miyako/4d-plugin-time-and-number ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
> > The only thing I'm not sure about is how various time zones change in their > relationship to GMT (eg Summer Time etc.) For example if Country A is > normally on GMT -8 but they're currently on Summer Time so 7AM in that time > zone is CurrentHourGMT-8+1, how do we account for that? > > One idea I have is to get a list of timezones using sudo - eg > sudo system setup -listtimezones > but I haven't been able to get that to work using LEP - eg > to get the local Time(zone) on a Mac with LEP you could use one of these commands: date +%z date +"%Z %z" ls -l /etc/localtime curl https://ipapi.co/timezone Cheers, Bernd Am Mi., 26. Sep. 2018 um 15:17 Uhr schrieb Pat Bensky via 4D_Tech < 4d_tech@lists.4d.com>: > After trying various complicated methods of calculating the different time > zones, the final method was actually quite simple. > I needed to set up an email-sending routine to send emails out at 7AM for > each time zone. This is what I have. This is currently being tested :) > Please feel free to point out any obvious flaws! > > // get the current GMT time > > *XML DECODE*(*Delete string*(*String*(*Current date*;ISO date GMT;*Current > time*);20;1);$tTime) > > $CurrentHourGMT:=*Num*(*Substring*(*String*($tTime);1;2)) > > // get the difference between current GMT and 7AM > > *If* ($CurrentHourGMT>=7) > > $TimeZoneDiff:=($CurrentHourGMT-7)*-1 // gives us a starting point for > where it is currently 7AM > > *Else* > > $TimeZoneDiff:=7-$CurrentHourGMT > > *End if* > > $Current7AM:=$TimeZoneDiff > > *For* ($i;1;24) > > * QUERY*([Emails];[Emails]gmt=$Current7AM) > > // send the emails > > *Case of* > > *:* ($Current7AM=0) > > $Current7AM:=-1 > > *:* ($Current7AM=-11) > > $Current7AM:=12 > > *Else* > > $Current7AM:=$Current7AM-1 > > *End case* > > $lastHour:=$CurrentHourGMT > > *While* ($CurrentHourGMT<=$lastHour) > > *DELAY PROCESS*(*Current process*;$DelayTime) > > *If* ($testing) > > $CurrentHourGMT:=$CurrentHourGMT+1 > > *Else* > > *XML DECODE*(*Delete string*(*String*(*Current date*;ISO date GMT;*Current > time*);20;1);$tTime) > > $CurrentHourGMT:=*Num*(*Substring*(*String*($tTime);1;2)) > > *End if* > > *End while* > > End For // 24 iterations > > The only thing I'm not sure about is how various time zones change in their > relationship to GMT (eg Summer Time etc.) For example if Country A is > normally on GMT -8 but they're currently on Summer Time so 7AM in that time > zone is CurrentHourGMT-8+1, how do we account for that? > > > One idea I have is to get a list of timezones using sudo - eg > > sudo system setup -listtimezones > > but I haven't been able to get that to work using LEP - eg > > * C_TEXT*($result) > > $cmd:="sudo systemsetup -listtimezones" > > *LAUNCH EXTERNAL PROCESS*($cmd;$result) > > $result is always empty - I guess I'm doing something wrong! > Then maybe go through each timezone, temporarily switch the machines's zone > sudo system setup - settimezone timezone > > Get the current time in that zone and calculate its difference from GMT ... > Save all those results into a lookup array. > > Any ideas about that? > > Pat > > > On Tue, 25 Sep 2018 at 14:07, Jody Bevan via 4D_Tech <4d_tech@lists.4d.com > > > wrote: > > > Pat: > > > > Thanks. I will try it out. I will see if then I can figure out getting it > > for the different time zones without having it hard coded in. > > > > Jody > > > > > > > On Sep 24, 2018, at 4:28 PM, Pat Bensky via 4D_Tech < > > 4d_tech@lists.4d.com> wrote: > > > > > > Using v16: > > > I've figured out how to get the current GMT time using cURL. (Code at > the > > > bottom if anybody is interested). > > > Now I need to get the current time in a different time zone - eg in > > France. > > > Any ideas how to do that? > > > > > > > > > > > > == > > > > > > // GetTimeGMT > > > > > > // Gest the current time in GMT from Google > > > > > > // 21/09/18 pb > > > > > > *C_LONGINT*(*$0*) > > > > > > $input:="curl -I https://www.google.com/; // this gets GMT from > Google > > > > > > $empty:="" > > > > > > *LAUNCH EXTERNAL PROCESS*($input;$empty;$output;$error) > > > > > > *$0*:=0 > > > > > > *If* ($output#"") > > > > > > $pos:=*Position*("GMT";$output) > > > > > > *If* ($pos>0) > > > > > > $time:=*Substring*($output;$pos-9;8) > > > > > > $pos:=*Position*(":";$time) > > > > > > *If* ($pos>0) > > > > > > *$0*:=*Num*(*Substring*($time;1;$pos-1)) > > > > > > *End if* > > > > > > *End if* > > > > > > *End if* > > > > > > -- > > > * > > > CatBase - Top Dog in Data Publishing > > > tel: +44 (0) 207 118 7889 > > > w: http://www.catbase.com > > > skype: pat.bensky > > > * > > > ** > > > 4D Internet Users Group (4D iNUG) > > > Archive: http://lists.4d.com/archives.html > > > Options: https://lists.4d.com/mailman/options/4d_tech >
RE: How to get the current time in a specified time zone
There are a lot of nuances for timezone data; here are a few that I find interesting - * Is "12:00:00 AM Tuesday" at the beginning of Tuesday or at the end of Tuesday? Depends on which year you are talking about and what country you are in. * If you have a timestamp that originates in Russia between 1st and 13th of February 1918, is it a valid timestamp? This is the period of time Russia switched from Julian to Gregorian calendar thus skipping those days. * Samoa changed their timezone offset by 25 hours in 2011 so, technically speaking, December 30th 2011 never happened in Samoa; a similar (yet opposite) occurrence happened in Samoa on July 4th 1892, where July 4th 1892 happened twice in Samoa. The following article is both interesting and funny in how it explains some of these nuances: https://zachholman.com/talk/utc-is-enough-for-everyone-right -Tim ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
Ah, this is such a complex issue. You need to know: - the time zone where your server is (which is where you will get the date and time using Current Time(*) - the time zone where your user is - the time zone where you want to know what time it is - whether it is daylight savings time where your server is - whether it is daylight savings time where your user is - whether it is daylight savings time where you want to know what time it is This is compounded by the fact that it could be a different DAY in some of these zones, as they can be on different sides of midnight. Fortunately, the computer operating system does a lot of this for you. I use Windows and some time ago asked the excellent people at Orchard Software to add sys_GetTimeZoneList to Win32API. This allows returns an array of all time zones with the current GMT offset, taking into account daylight savings time, etc. You might be able to get a similar thing from the Mac operating system. What I do is capture the user's current time zone from the OS when he logs in. I do this on the server and save it in a table, which I then read into a variable on the user's session, so I can calculate the time difference between the user and the server. Then if I need to know the time in another area, I have an array of time zones from the OS I present to the user and can calculate the time accordingly. Once upon a time I used a web service to do this, but when I found it was all built into the OS, I used that with good results. Hope this helps - Bob Miller Chomerics, a division of Parker Hannifin Corporation ll "PLEASE NOTE: The preceding information may be confidential or privileged. It only should be used or disseminated for the purpose of conducting business with Parker. If you are not an intended recipient, please notify the sender by replying to this message and then delete the information from your system. Thank you for your cooperation." ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
Pat Bensky writes: >The only thing I'm not sure about is how various time zones change in their >relationship to GMT (eg Summer Time etc.) For example if Country A is >normally on GMT -8 but they're currently on Summer Time so 7AM in that >time zone is CurrentHourGMT-8+1, how do we account for that? Ya gotta have a database and you gotta maintain it, because the rules change for a range of reasons. This takes me back to my programming infancy in 1988 when I created a Hypercard stack that was filled with all the countries and major cities of the world. I'm a geography fan, so I thoroughly enjoyed do the research (pre-internet). You entered your local time and selected the city/country you wanted to know the time in and it would look it up and display it. The stack was called "What Time?" and it got an award from the Boston Computer Society. I distributed it as shareware (remember that concept?) and I sold about 10 licenses. Even got an order from Switzerland. Fulfillment was by mail. Thanks for the trip down memory lane. Sorry for the diversion. Tom Benedict Optum This e-mail, including attachments, may include confidential and/or proprietary information, and may be used only by the person or entity to which it is addressed. If the reader of this e-mail is not the intended recipient or his or her authorized agent, the reader is hereby notified that any dissemination, distribution or copying of this e-mail is prohibited. If you have received this e-mail in error, please notify the sender by replying to this message and delete this e-mail immediately. ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
After trying various complicated methods of calculating the different time zones, the final method was actually quite simple. I needed to set up an email-sending routine to send emails out at 7AM for each time zone. This is what I have. This is currently being tested :) Please feel free to point out any obvious flaws! // get the current GMT time *XML DECODE*(*Delete string*(*String*(*Current date*;ISO date GMT;*Current time*);20;1);$tTime) $CurrentHourGMT:=*Num*(*Substring*(*String*($tTime);1;2)) // get the difference between current GMT and 7AM *If* ($CurrentHourGMT>=7) $TimeZoneDiff:=($CurrentHourGMT-7)*-1 // gives us a starting point for where it is currently 7AM *Else* $TimeZoneDiff:=7-$CurrentHourGMT *End if* $Current7AM:=$TimeZoneDiff *For* ($i;1;24) * QUERY*([Emails];[Emails]gmt=$Current7AM) // send the emails *Case of* *:* ($Current7AM=0) $Current7AM:=-1 *:* ($Current7AM=-11) $Current7AM:=12 *Else* $Current7AM:=$Current7AM-1 *End case* $lastHour:=$CurrentHourGMT *While* ($CurrentHourGMT<=$lastHour) *DELAY PROCESS*(*Current process*;$DelayTime) *If* ($testing) $CurrentHourGMT:=$CurrentHourGMT+1 *Else* *XML DECODE*(*Delete string*(*String*(*Current date*;ISO date GMT;*Current time*);20;1);$tTime) $CurrentHourGMT:=*Num*(*Substring*(*String*($tTime);1;2)) *End if* *End while* End For // 24 iterations The only thing I'm not sure about is how various time zones change in their relationship to GMT (eg Summer Time etc.) For example if Country A is normally on GMT -8 but they're currently on Summer Time so 7AM in that time zone is CurrentHourGMT-8+1, how do we account for that? One idea I have is to get a list of timezones using sudo - eg sudo system setup -listtimezones but I haven't been able to get that to work using LEP - eg * C_TEXT*($result) $cmd:="sudo systemsetup -listtimezones" *LAUNCH EXTERNAL PROCESS*($cmd;$result) $result is always empty - I guess I'm doing something wrong! Then maybe go through each timezone, temporarily switch the machines's zone sudo system setup - settimezone timezone Get the current time in that zone and calculate its difference from GMT ... Save all those results into a lookup array. Any ideas about that? Pat On Tue, 25 Sep 2018 at 14:07, Jody Bevan via 4D_Tech <4d_tech@lists.4d.com> wrote: > Pat: > > Thanks. I will try it out. I will see if then I can figure out getting it > for the different time zones without having it hard coded in. > > Jody > > > > On Sep 24, 2018, at 4:28 PM, Pat Bensky via 4D_Tech < > 4d_tech@lists.4d.com> wrote: > > > > Using v16: > > I've figured out how to get the current GMT time using cURL. (Code at the > > bottom if anybody is interested). > > Now I need to get the current time in a different time zone - eg in > France. > > Any ideas how to do that? > > > > > > > > == > > > > // GetTimeGMT > > > > // Gest the current time in GMT from Google > > > > // 21/09/18 pb > > > > *C_LONGINT*(*$0*) > > > > $input:="curl -I https://www.google.com/; // this gets GMT from Google > > > > $empty:="" > > > > *LAUNCH EXTERNAL PROCESS*($input;$empty;$output;$error) > > > > *$0*:=0 > > > > *If* ($output#"") > > > > $pos:=*Position*("GMT";$output) > > > > *If* ($pos>0) > > > > $time:=*Substring*($output;$pos-9;8) > > > > $pos:=*Position*(":";$time) > > > > *If* ($pos>0) > > > > *$0*:=*Num*(*Substring*($time;1;$pos-1)) > > > > *End if* > > > > *End if* > > > > *End if* > > > > -- > > * > > CatBase - Top Dog in Data Publishing > > tel: +44 (0) 207 118 7889 > > w: http://www.catbase.com > > skype: pat.bensky > > * > > ** > > 4D Internet Users Group (4D iNUG) > > Archive: http://lists.4d.com/archives.html > > Options: https://lists.4d.com/mailman/options/4d_tech > > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > > ** > > ** > 4D Internet Users Group (4D iNUG) > Archive: http://lists.4d.com/archives.html > Options: https://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ** -- * CatBase - Top Dog in Data Publishing tel: +44 (0) 207 118 7889 w: http://www.catbase.com skype: pat.bensky * ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: How to get the current time in a specified time zone
actually you can get UTC time without a network connection: // v17 C_TIME($t) XML DECODE(Delete string(Timestamp;24;1);$t) // before C_TIME($t) XML DECODE(Delete string(string(Current date;ISO date GMT;Current time);20;1);$t) both of which are effectively "substring" + "time" operations that strip away the date. however, time in a specified zone requires date information, because of day light savings and other peculiarities. c.f. https://github.com/miyako/4d-plugin-time-and-number https://github.com/miyako/4d-plugin-tz ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
RE: How to get the current time in a specified time zone
> There is also the NET_TIME command in 4D Internet Commands: > http://doc.4d.com/4Dv17/4D/17/NET-Time.301-3785509.en.html Something like this: C_TIME($vTime) C_DATE($vNetDate) C_LONGINT($vNetTime;$vOffset;$err) $vOffset:=-7 $err:=NET_Time ("time.nist.gov";$vNetDate;$vNetTime;$vOffset) If ($err=0) $vTime:=Time(Time string($vNetTime)) //Convert the LongInt time to a 4D Time End if -Tim ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
RE: How to get the current time in a specified time zone
Interesting approach; I also just found these: UTC: http://worldclockapi.com/api/json/utc/now PST: http://worldclockapi.com/api/json/pst/now EST: http://worldclockapi.com/api/json/est/now The output is JSON, so it should be easily parsed. There is also the NET_TIME command in 4D Internet Commands: http://doc.4d.com/4Dv17/4D/17/NET-Time.301-3785509.en.html ** 4D Internet Users Group (4D iNUG) Archive: http://lists.4d.com/archives.html Options: https://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **