Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UTCDatetime - a VFPX project
Message
De
02/04/2019 03:26:56
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
VFPX/Sedna
Titre:
UTCDatetime - a VFPX project
Divers
Thread ID:
01667821
Message ID:
01667821
Vues:
71
J'aime (1)
UTCDatetime is a new VFPX project to allow exchange between local time and UTC in any time zone in the World, presently, in the past, and the future (that is, as long as the current time zone definitions perdure). The goal of this project is to facilitate the integration of UTC data in VFP programs and to increase their interoperability.

A ready-to-use app is available in the repository. When executed, it instantiates a UTCDatetime object and adds it to _Screen, thus assuring complete visibility in any VFP context.

The examples in the documentation include calculating the duration of international flights, given the local time of departure and arrival; determining the local time in different points of the globe of the first Moon landing; and getting the current local time in different USA cities.

What follows is a rewrite of the last example. It starts by loading the time zone definition for the three US states with more UT/LE users (California, Texas, and Florida).
Then, for each of the time zones, displays the ISO8601 representation of the DateTime, including UTC offset and name of the current time definition.
DO LOCFILE("utc.app")

* these functions return .T. on success, .F. on failure
_Screen.utc.Loadtimezone("America/Los_Angeles")
_Screen.utc.Loadtimezone("America/Chicago")
_Screen.utc.Loadtimezone("America/New_York")
_Screen.utc.LoadTimezone("Etc/Universal")

? "UTC: " + _Screen.utc.Ttoc(_Screen.utc.Now(), "Etc/Universal", 1)
? "California: " + _Screen.utc.Ttoc(_Screen.utc.Localtime(,"America/Los_Angeles"), "America/Los_Angeles", 1)
? "Texas: " + _Screen.utc.Ttoc(_Screen.utc.Localtime(,"America/Chicago"), "America/Chicago", 1)
? "Florida: " + _Screen.utc.Ttoc(_Screen.utc.Localtime(,"America/New_York"), "America/New_York", 1)
The result:
UTC: 2019-04-02T07:13:33+00:00 UTC
California: 2019-04-02T00:13:33-07:00 PDT
Texas: 2019-04-02T02:13:33-05:00 CDT
Florida: 2019-04-02T03:13:33-04:00 EDT
Issues, bugs detection, or ideas for enhancements are welcomed, as usual.
----------------------------------
António Tavares Lopes
Répondre
Fil
Voir

Click here to load this message in the networking platform