How to get the current time in a specified time zone

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

How to get the current time in a specified time zone

4D Tech mailing list
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: How to get the current time in a specified time zone

4D Tech mailing list
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: How to get the current time in a specified time zone

4D Tech mailing list
> 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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
Thanks guys!
Miyako, that is so simple ... :)

On Tue, 25 Sep 2018 at 01:43, Keisuke Miyako via 4D_Tech <
[hidden email]> wrote:

> 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:[hidden email]
> **********************************************************************



--
*************************************************
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
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 <[hidden email]> 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:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
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 <[hidden email]>
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 <
> [hidden email]> 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:[hidden email]
> > **********************************************************************
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************



--
*************************************************
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
It is really a database problem of managing all of the various rules of different locations. Postgres has this built in. If you don't want to use Postgres, you still might find the data you need to add to your 4D implementation. See list below of 79 distinct zones.

John DeSoi, Ph.D.




> On Sep 26, 2018, at 8:17 AM, Pat Bensky via 4D_Tech <[hidden email]> wrote:
>
> 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?



postgres=# select distinct on (abbrev) * from pg_timezone_names;
          name           | abbrev | utc_offset | is_dst
-------------------------+--------+------------+--------
 Atlantic/Azores         | +00    | 00:00:00   | t
 Etc/GMT-1               | +01    | 01:00:00   | f
 Antarctica/Troll        | +02    | 02:00:00   | t
 Asia/Qatar              | +03    | 03:00:00   | f
 Iran                    | +0330  | 03:30:00   | f
 Asia/Yerevan            | +04    | 04:00:00   | f
 Asia/Kabul              | +0430  | 04:30:00   | f
 Asia/Tashkent           | +05    | 05:00:00   | f
 Asia/Colombo            | +0530  | 05:30:00   | f
 Asia/Kathmandu          | +0545  | 05:45:00   | f
 Asia/Bishkek            | +06    | 06:00:00   | f
 Asia/Yangon             | +0630  | 06:30:00   | f
 Indian/Christmas        | +07    | 07:00:00   | f
 Asia/Ulaanbaatar        | +08    | 08:00:00   | f
 Australia/Eucla         | +0845  | 08:45:00   | f
 Asia/Chita              | +09    | 09:00:00   | f
 Etc/GMT-10              | +10    | 10:00:00   | f
 Australia/Lord_Howe     | +1030  | 10:30:00   | f
 Pacific/Noumea          | +11    | 11:00:00   | f
 Pacific/Wake            | +12    | 12:00:00   | f
 Pacific/Chatham         | +1245  | 12:45:00   | f
 Etc/GMT-13              | +13    | 13:00:00   | f
 Pacific/Kiritimati      | +14    | 14:00:00   | f
 Atlantic/Cape_Verde     | -01    | -01:00:00  | f
 Atlantic/South_Georgia  | -02    | -02:00:00  | f
 America/Rosario         | -03    | -03:00:00  | f
 America/La_Paz          | -04    | -04:00:00  | f
 Etc/GMT+5               | -05    | -05:00:00  | f
 Etc/GMT+6               | -06    | -06:00:00  | f
 Etc/GMT+7               | -07    | -07:00:00  | f
 Etc/GMT+8               | -08    | -08:00:00  | f
 Pacific/Gambier         | -09    | -09:00:00  | f
 Pacific/Marquesas       | -0930  | -09:30:00  | f
 Etc/GMT+10              | -10    | -10:00:00  | f
 Etc/GMT+11              | -11    | -11:00:00  | f
 Etc/GMT+12              | -12    | -12:00:00  | f
 Australia/Adelaide      | ACST   | 09:30:00   | f
 America/Moncton         | ADT    | -03:00:00  | t
 Australia/Hobart        | AEST   | 10:00:00   | f
 US/Alaska               | AKDT   | -08:00:00  | t
 America/Guadeloupe      | AST    | -04:00:00  | f
 Australia/Perth         | AWST   | 08:00:00   | f
 Europe/Belfast          | BST    | 01:00:00   | t
 Africa/Bujumbura        | CAT    | 02:00:00   | f
 America/Chicago         | CDT    | -05:00:00  | t
 Europe/Belgrade         | CEST   | 02:00:00   | t
 Africa/Tunis            | CET    | 01:00:00   | f
 America/Regina          | CST    | -06:00:00  | f
 Pacific/Guam            | ChST   | 10:00:00   | f
 Indian/Comoro           | EAT    | 03:00:00   | f
 America/Indiana/Marengo | EDT    | -04:00:00  | t
 Europe/Sofia            | EEST   | 03:00:00   | t
 Egypt                   | EET    | 02:00:00   | f
 Jamaica                 | EST    | -05:00:00  | f
 GMT0                    | GMT    | 00:00:00   | f
 US/Aleutian             | HDT    | -09:00:00  | t
 Hongkong                | HKT    | 08:00:00   | f
 HST                     | HST    | -10:00:00  | f
 Asia/Jerusalem          | IDT    | 03:00:00   | t
 Asia/Calcutta           | IST    | 05:30:00   | f
 Japan                   | JST    | 09:00:00   | f
 Asia/Seoul              | KST    | 09:00:00   | f
 America/Edmonton        | MDT    | -06:00:00  | t
 MET                     | MEST   | 02:00:00   | t
 W-SU                    | MSK    | 03:00:00   | f
 America/Dawson_Creek    | MST    | -07:00:00  | f
 Canada/Newfoundland     | NDT    | -02:30:00  | t
 Pacific/Auckland        | NZST   | 12:00:00   | f
 America/Ensenada        | PDT    | -07:00:00  | t
 Asia/Karachi            | PKT    | 05:00:00   | f
 Africa/Mbabane          | SAST   | 02:00:00   | f
 Pacific/Pago_Pago       | SST    | -11:00:00  | f
 UCT                     | UCT    | 00:00:00   | f
 Universal               | UTC    | 00:00:00   | f
 Africa/Luanda           | WAT    | 01:00:00   | f
 Africa/Casablanca       | WEST   | 01:00:00   | t
 Asia/Pontianak          | WIB    | 07:00:00   | f
 Asia/Jayapura           | WIT    | 09:00:00   | f
 Asia/Makassar           | WITA   | 08:00:00   | f
(79 rows)

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
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


llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
"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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: How to get the current time in a specified time zone

4D Tech mailing list
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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
>
> 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 <
[hidden email]>:

> 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 <[hidden email]
> >
> 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 <
> > [hidden email]> 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:[hidden email]
> > > **********************************************************************
> >
> > **********************************************************************
> > 4D Internet Users Group (4D iNUG)
> > Archive:  http://lists.4d.com/archives.html
> > Options: https://lists.4d.com/mailman/options/4d_tech
> > Unsub:  mailto:[hidden email]
> > **********************************************************************
>
>
>
> --
> *************************************************
> 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:[hidden email]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: How to get the current time in a specified time zone

4D Tech mailing list
In reply to this post by 4D Tech mailing list
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:[hidden email]
**********************************************************************