Skip to content

Instantly share code, notes, and snippets.

@Irwin1985
Created July 22, 2023 21:48
Show Gist options
  • Save Irwin1985/7dadf914ed2b8dc4e93f8f1e9ae0324e to your computer and use it in GitHub Desktop.
Save Irwin1985/7dadf914ed2b8dc4e93f8f1e9ae0324e to your computer and use it in GitHub Desktop.
El siguiente ejemplo consulta la hora de una zona en específico usando la API worldtimeapi.prg
* ==================================================================================== *
* Este ejemplo retorna la lista de zonas horarias soportadas por worldtimeapi.org
* REQUISITOS:
* 1. JSONFox (https://github.com/Irwin1985/JSONFox)
* 2. VFPRestClient (https://github.com/Irwin1985/VFPRestClient)
* ==================================================================================== *
Local lcJSONFoxLocation, lcVFPRestClientLocation, laZonasHorarias, loTimeZone
lcJSONFoxLocation = GetFile("app", "JSONFox")
lcVFPRestClientLocation = GetFile("prg", "VFPRestClient")
Do (lcJSONFoxLocation)
Set Procedure To (lcVFPRestClientLocation) additive
Local lcURI, loRest
Set Step On
* Lista de zonas horarias soportadas
lcURI = "http://worldtimeapi.org/api/timezone"
loRest = CreateObject("Rest")
loRest.AddRequest(loRest.GET, lcURI)
loRest.AddHeader("Content-Type", "application/json")
If !loRest.Send()
MessageBox("Se ha producido un error al intentar enviar la petición al servidor: " + lcURI, 16)
Release all
Return
EndIf
laZonasHorarias = _screen.json.parse(loRest.ResponseText)
If Val(_screen.json.version) < 9 && las versiones anteriores a la 9 no usan array nativo.
For each lcZona in laZonasHorarias._
? lcZona
EndFor
else
For each lcZona in laZonasHorarias
? lcZona
EndFor
EndIf
* Consultar la hora de una zona en específico (ver listado disponible)
* El siguiente ejemplo consulta la hora de Madrid/España
lcURI = "http://worldtimeapi.org/api/timezone/Europe/Madrid"
loRest.AddRequest(loRest.GET, lcURI)
loRest.AddHeader("Content-Type", "application/json")
If !loRest.Send()
MessageBox("Se ha producido un error al intentar enviar la petición al servidor: " + lcURI, 16)
Return
EndIf
loTimeZone = _screen.json.parse(loRest.ResponseText)
* Imprimir los datos
? "abbreviation:", loTimeZone.abbreviation
? "client_ip:", loTimeZone.client_ip
? "datetime:", loTimeZone.datetime
? "day_of_week:", loTimeZone.day_of_week
? "day_of_year:", loTimeZone.day_of_year
? "dst:", loTimeZone.dst
? "dst_from:", loTimeZone.dst_from
? "dst_offset:", loTimeZone.dst_offset
? "dst_until:", loTimeZone.dst_until
? "raw_offset:", loTimeZone.raw_offset
? "timezone:", loTimeZone.timezone
? "unixtime:", loTimeZone.unixtime
? "utc_datetime:", loTimeZone.utc_datetime
? "utc_offset:", loTimeZone.utc_offset
? "week_number:", loTimeZone.week_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment