Title: | Look Up Time Zones of Point Coordinates |
---|---|
Description: | Input latitude and longitude values or an 'sf/sfc' POINT object and get back the time zone in which they exist. Two methods are implemented. One is very fast and uses 'Rcpp' in conjunction with data from the 'Javascript' library (<https://github.com/darkskyapp/tz-lookup-oss/>). This method also works outside of countries' borders and in international waters, however speed comes at the cost of accuracy - near time zone borders away from populated centres there is a chance that it will return the incorrect time zone. The other method is slower but more accurate - it uses the 'sf' package to intersect points with a detailed map of time zones from here: <https://github.com/evansiroky/timezone-boundary-builder/>. The package also contains several utility functions for helping to understand and visualize time zones, such as listing of world time zones, including information about daylight savings times and their offsets from UTC. You can also plot a time zone to visualize the UTC offset over a year and when daylight savings times are in effect. |
Authors: | Andy Teucher [aut, cre] , Bob Rudis [ctb] |
Maintainer: | Andy Teucher <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.2.9000 |
Built: | 2025-01-08 04:27:38 UTC |
Source: | https://github.com/ateucher/lutz |
Output a list of time zone names, with daylight savings time and utc offset
tz_list()
tz_list()
A data.frame of all time zones on your system. Columns:
tz_name: the name of the time zone
zone: time zone
is_dst: is the time zone in daylight savings time
utc_offset_h: offset from UTC (in hours)
There are two methods - "fast"
, and "accurate"
. The "fast"
version can
look up many thousands of points very quickly, however when a point is near
a time zone boundary and not near a populated centre, it may return the
incorrect time zone. If accuracy is more important than speed, use
method = "accurate"
.
tz_lookup(x, crs = NULL, method = "fast", warn = TRUE)
tz_lookup(x, crs = NULL, method = "fast", warn = TRUE)
x |
either an |
crs |
the coordinate reference system: integer with the EPSG code, or character with proj4string.
If not specified (i.e., |
method |
method by which to do the lookup. Either |
warn |
By default, if |
Note that there are some regions in the world where a single point can land in
two different overlapping time zones. The "accurate"
method includes these,
and when they are encountered they are concatenated in a single string,
separated by a semicolon.
The data used in the "fast"
method does not include overlapping time zones
at this time.
character vector the same length as x
specifying the time zone of the points.
if (require("sf")) { state_pts <- lapply(seq_along(state.center$x), function(i) { st_point(c(state.center$x[i], state.center$y[i])) }) state_centers_sf <- st_sf(st_sfc(state_pts)) state_centers_sf$tz <- tz_lookup(state_centers_sf) plot(state_centers_sf[, "tz"]) }
if (require("sf")) { state_pts <- lapply(seq_along(state.center$x), function(i) { st_point(c(state.center$x[i], state.center$y[i])) }) state_centers_sf <- st_sf(st_sfc(state_pts)) state_centers_sf$tz <- tz_lookup(state_centers_sf) plot(state_centers_sf[, "tz"]) }
There are two methods - "fast"
, and "accurate"
. The "fast"
version can
look up many thousands of points very quickly, however when a point is near
a time zone boundary and not near a populated centre, it may return the
incorrect time zone. If accuracy is more important than speed, use
method = "accurate"
.
tz_lookup_coords(lat, lon, method = "fast", warn = TRUE)
tz_lookup_coords(lat, lon, method = "fast", warn = TRUE)
lat |
numeric vector of latitudes |
lon |
numeric vector of longitudes the same length as |
method |
method by which to do the lookup. Either |
warn |
By default, if |
character vector the same length as x and y specifying the time zone of the points.
tz_lookup_coords(42, -123) tz_lookup_coords(lat = c(48.9, 38.5, 63.1, -25), lon = c(-123.5, -110.2, -95.0, 130))
tz_lookup_coords(42, -123) tz_lookup_coords(lat = c(48.9, 38.5, 63.1, -25), lon = c(-123.5, -110.2, -95.0, 130))
Find the offset from UTC at a particular date/time in a particular time zone
tz_offset(dt, tz = "")
tz_offset(dt, tz = "")
dt |
|
tz |
A time zone name from |
a one-row data frame with details of the time zone
tz_offset("2018-06-12", "America/Moncton")
tz_offset("2018-06-12", "America/Moncton")
Make a circular plot of a time zone, visualizing the UTC offset over the course of the year, including Daylight Savings times
tz_plot(tz)
tz_plot(tz)
tz |
a valid time zone name. See |
a ggplot2
object
tz_plot("America/Vancouver")
tz_plot("America/Vancouver")