Functions to talk to the WorldTimeAPI http://worldtimeapi.org
Arguments
- resource
Path in the WorldTimeAPI. Normally either a valid timezone or an IP.
- ...
Arguments passed on to
httr2::resp_body_json
resp
A response object.
check_type
Check that response has expected content type? Set to
FALSE
to suppress the automated checksimplifyVector
Should JSON arrays containing only primitives (i.e. booleans, numbers, and strings) be caused to atomic vectors?
- ipv4
An ipv4 address for which to return the current time. The default
NULL
uses the system's public IP address.
Examples
# \donttest{
# Change R option for printing decimal digits of seconds
old <- options(digits.secs = 6)
# Specific timezone
new_york_time <- try(worldtimer("America/New_York"))
str(new_york_time)
#> List of 14
#> $ abbreviation: chr "EDT"
#> $ datetime : chr "2022-03-31T14:01:13.467482-04:00"
#> $ day_of_week : int 4
#> $ day_of_year : int 90
#> $ dst : logi TRUE
#> $ dst_from : chr "2022-03-13T07:00:00+00:00"
#> $ dst_offset : int 3600
#> $ dst_until : chr "2022-11-06T06:00:00+00:00"
#> $ raw_offset : int -18000
#> $ timezone : chr "America/New_York"
#> $ unixtime : int 1648749673
#> $ utc_datetime: POSIXct[1:1], format: "2022-03-31 18:01:13.467482"
#> $ utc_offset : chr "-04:00"
#> $ week_number : int 13
#> - attr(*, "class")= chr "worldtimer"
print(new_york_time)
#> [1] "2022-03-31 14:01:13.467482 EDT"
# The system's public ip
system_ip <- worldtimer_ip()
str(system_ip)
#> List of 14
#> $ abbreviation: chr "CDT"
#> $ datetime : chr "2022-03-31T13:01:13.511972-05:00"
#> $ day_of_week : int 4
#> $ day_of_year : int 90
#> $ dst : logi TRUE
#> $ dst_from : chr "2022-03-13T08:00:00+00:00"
#> $ dst_offset : int 3600
#> $ dst_until : chr "2022-11-06T07:00:00+00:00"
#> $ raw_offset : int -21600
#> $ timezone : chr "America/Chicago"
#> $ unixtime : int 1648749673
#> $ utc_datetime: POSIXct[1:1], format: "2022-03-31 18:01:13.511971"
#> $ utc_offset : chr "-05:00"
#> $ week_number : int 13
#> - attr(*, "class")= chr "worldtimer"
print(system_ip)
#> [1] "2022-03-31 13:01:13.511971 CDT"
# Other public ip
other_ip <- worldtimer_ip("101.110.34.62")
str(other_ip)
#> List of 14
#> $ abbreviation: chr "JST"
#> $ datetime : chr "2022-04-01T03:01:13.540641+09:00"
#> $ day_of_week : int 5
#> $ day_of_year : int 91
#> $ dst : logi FALSE
#> $ dst_from : NULL
#> $ dst_offset : int 0
#> $ dst_until : NULL
#> $ raw_offset : int 32400
#> $ timezone : chr "Asia/Tokyo"
#> $ unixtime : int 1648749673
#> $ utc_datetime: POSIXct[1:1], format: "2022-03-31 18:01:13.54064"
#> $ utc_offset : chr "+09:00"
#> $ week_number : int 13
#> - attr(*, "class")= chr "worldtimer"
print(other_ip)
#> [1] "2022-04-01 03:01:13.54064 JST"
# Restore old options
options(old)
# }