worldtimeapi
Module worldtimeapi
API
![](https://bcentral-packageicons.azureedge.net/images/ballerinax_worldtimeapi_1.4.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 (ConnectionConfig config, string serviceUrl)
- config ConnectionConfig {} - 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: ClientHttp1Settings![](/images/permalink.svg)
Provides settings related to HTTP/1.x protocol.
Fields
- keepAlive KeepAlive(default http:KEEPALIVE_AUTO) - Specifies whether to reuse a connection for multiple requests
- chunking Chunking(default http:CHUNKING_AUTO) - The chunking behaviour of the request
- proxy ProxyConfig? - Proxy server related options
worldtimeapi: ConnectionConfig![](/images/permalink.svg)
Provides a set of configurations for controlling the behaviours when communicating with a remote HTTP endpoint.
Fields
- httpVersion HttpVersion(default http:HTTP_2_0) - The HTTP version understood by the client
- http1Settings ClientHttp1Settings? - Configurations related to HTTP/1.x protocol
- http2Settings ClientHttp2Settings? - Configurations related to HTTP/2 protocol
- timeout decimal(default 60) - The maximum time to wait (in seconds) for a response before closing the connection
- forwarded string(default "disable") - The choice of setting
forwarded
/x-forwarded
header
- poolConfig PoolConfiguration? - Configurations associated with request pooling
- cache CacheConfig? - HTTP caching related configurations
- compression Compression(default http:COMPRESSION_AUTO) - Specifies the way of handling compression (
accept-encoding
) header
- circuitBreaker CircuitBreakerConfig? - Configurations associated with the behaviour of the Circuit Breaker
- retryConfig RetryConfig? - Configurations associated with retrying
- responseLimits ResponseLimitConfigs? - Configurations associated with inbound response size limits
- secureSocket ClientSecureSocket? - SSL/TLS-related options
- proxy ProxyConfig? - Proxy server related options
- validation boolean(default true) - Enables the inbound payload validation functionality which provided by the constraint package. Enabled by default
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
worldtimeapi: ProxyConfig![](/images/permalink.svg)
Proxy server configurations to be used with the HTTP client endpoint.
Fields
- host string(default "") - Host name of the proxy server
- port int(default 0) - Proxy server port
- userName string(default "") - Proxy server username
- password string(default "") - Proxy server password
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: almost 2 years ago
Version: 1.4.0
License: Apache-2.0
Compatibility
Platform: any
Ballerina version: 2201.2.1
GraalVM compatible: Yes
Pull count
Total: 8
Current verison: 0
Weekly downloads
Keywords
IT Operations/Cloud Services
Cost/Free
Contributors
Dependencies