worldtimeapi
Module worldtimeapi
API
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_worldtimeapi_1.1.0.png)
ballerinax/worldtimeapi Ballerina library
Overview
This is a generated connector for WorldTimeAPI v0.6.1 OpenAPI Specification.
WorldTime API is a simple "microservice" which returns the local-time for a given timezone in both unixtime and ISO8601 format. The worldTimeAPI connector supports to get the current time based on a request with a timezone and additional information including whether that timezone is currently in Daylight Savings Time, when DST starts and ends, the UTC offset, etc.
Quickstart
- Listing all time zone as json
Step 1 - Import connector
ballerinax/worldtimeapi
Step 2 - Create a new connector instance
worldtimeapi:Client baseClient = check new Client();
Step 3 - Invoke connector operation
- Invoke connector operations using the client
worldtimeapi:ListJsonResponse output = check baseClient->listTimezones();
- Use
bal run
command to compile and run the Ballerina program.
Clients![](/images/permalink.svg)
worldtimeapi: Client![](/images/permalink.svg)
This is a generated connector for WorldTimeAPI v0.6.1 OpenAPI Specification. WorldTime API is a simple "microservice" which returns the local-time for a given timezone in both unixtime and ISO8601 format. The worldTimeAPI connector supports to get the current time based on a request with a timezone and additional information including whether that timezone is currently in Daylight Savings Time, when DST starts and ends, the UTC offset, etc.
Constructor![](/images/permalink.svg)
Gets invoked to initialize the connector
.
The connector initialization doesn't require setting the API credentials.
World Time API data is simple and free to access. Follow this link for more details.
init (ClientConfiguration clientConfig, string serviceUrl)
- clientConfig ClientConfiguration {} - The configurations to be used when initializing the
connector
- serviceUrl string "http://worldtimeapi.org/api/" - URL of the target service
listTimezones![](/images/permalink.svg)
function listTimezones() returns ListJsonResponse|error
a listing of all timezones.
Return Type
- ListJsonResponse|error - the list of available timezones in JSON format
listTimezonesAsText![](/images/permalink.svg)
function listTimezonesAsText() returns ListTextResponse|error
a listing of all timezones.
Return Type
- ListTextResponse|error - the list of available timezones in plain text
getTimezoneByArea![](/images/permalink.svg)
a listing of all timezones available for that area.
Parameters
- area string - Area
Return Type
- ListJsonResponse|error - the list of available timezones in JSON format
getTimezoneByAreaAsText![](/images/permalink.svg)
function getTimezoneByAreaAsText(string area) returns ListTextResponse|error
a listing of all timezones available for that area.
Parameters
- area string - Area
Return Type
- ListTextResponse|error - the list of available timezones in plain text
getCurrentTime![](/images/permalink.svg)
function getCurrentTime(string area, string location) returns DateTimeJsonResponse|error
request the current time for a timezone.
Return Type
- DateTimeJsonResponse|error - the current time for the timezone requested in JSON format
getCurrentTimeAsText![](/images/permalink.svg)
function getCurrentTimeAsText(string area, string location) returns DateTimeTextResponse|error
request the current time for a timezone.
Return Type
- DateTimeTextResponse|error - the current time for the timezone requested in plain text
getCurrentTimeByRegion![](/images/permalink.svg)
function getCurrentTimeByRegion(string area, string location, string region) returns DateTimeJsonResponse|error
request the current time for a timezone.
Return Type
- DateTimeJsonResponse|error - the current time for the timezone requested in JSON format
getCurrentTimeByRegionAsText![](/images/permalink.svg)
function getCurrentTimeByRegionAsText(string area, string location, string region) returns DateTimeTextResponse|error
request the current time for a timezone.
Return Type
- DateTimeTextResponse|error - the current time for the timezone requested in plain text
getCurrentTimeBasedOnIp![](/images/permalink.svg)
function getCurrentTimeBasedOnIp() returns DateTimeJsonResponse|error
request the current time based on the ip of the request. note: this is a "best guess" obtained from open-source data.
Return Type
- DateTimeJsonResponse|error - the current time for the timezone requested in JSON format
getCurrentTimeBasedOnIpAsText![](/images/permalink.svg)
function getCurrentTimeBasedOnIpAsText() returns DateTimeTextResponse|error
request the current time based on the ip of the request. note: this is a "best guess" obtained from open-source data.
Return Type
- DateTimeTextResponse|error - the current time for the timezone requested in plain text
getCurrentTimeBasedOnIpv4![](/images/permalink.svg)
function getCurrentTimeBasedOnIpv4(string ipv4) returns DateTimeJsonResponse|error
request the current time based on the ip of the request. note: this is a "best guess" obtained from open-source data.
Parameters
- ipv4 string - IPv4 address
Return Type
- DateTimeJsonResponse|error - the current time for the timezone requested in JSON format
getCurrentTimeBasedOnIpv4AsText![](/images/permalink.svg)
function getCurrentTimeBasedOnIpv4AsText(string ipv4) returns DateTimeTextResponse|error
request the current time based on the ip of the request. note: this is a "best guess" obtained from open-source data.
Parameters
- ipv4 string - IPv4 address
Return Type
- DateTimeTextResponse|error - the current time for the timezone requested in plain text
Records![](/images/permalink.svg)
worldtimeapi: DateTimeJsonResponse![](/images/permalink.svg)
Fields
- abbreviation string - the abbreviated name of the timezone
- client_ip string - the IP of the client making the request
- datetime string - an ISO8601-valid string representing the current, local date/time
- day_of_week int - current day number of the week, where sunday is 0
- day_of_year int - ordinal date of the current year
- dst boolean - flag indicating whether the local time is in daylight savings
- dst_from string? - an ISO8601-valid string representing the datetime when daylight savings started for this timezone
- dst_offset int - the difference in seconds between the current local time and daylight saving time for the location
- dst_until string? - an ISO8601-valid string representing the datetime when daylight savings will end for this timezone
- raw_offset int? - the difference in seconds between the current local time and the time in UTC, excluding any daylight saving difference (see dst_offset)
- timezone string - timezone in
Area/Location
orArea/Location/Region
format
- unixtime int - number of seconds since the Epoch
- utc_datetime string - an ISO8601-valid string representing the current date/time in UTC
- utc_offset string - an ISO8601-valid string representing the offset from UTC
- week_number int - the current week number
worldtimeapi: ErrorJsonResponse![](/images/permalink.svg)
Fields
- _error string - details about the error encountered
String types![](/images/permalink.svg)
worldtimeapi: DateTimeTextResponse![](/images/permalink.svg)
DateTimeTextResponse
time zone details, as per the DateTimeJsonResponse response, in the format key: value
, one item per line
worldtimeapi: ErrorTextResponse![](/images/permalink.svg)
ErrorTextResponse
details about the error encountered in plain text
worldtimeapi: ListTextResponse![](/images/permalink.svg)
ListTextResponse
a list of available timezones, one per line
Import
import ballerinax/worldtimeapi;
Metadata
Released date: over 2 years ago
Version: 1.1.0
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: slbeta6
GraalVM compatible: Yes
Pull count
Total: 8
Current verison: 1
Weekly downloads
Keywords
IT Operations/Cloud Services
Cost/Free
Contributors
Dependencies