| Title: | Quick Timezone-Aware Timestamps |
|---|---|
| Description: | Simple helpers to report the current time in UTC and your local timezone, with sensible detection heuristics when the system timezone is UTC. Supports fuzzy matching of timezone names like "Perth Australia". |
| Authors: | Michael Sumner [aut, cre] |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9001 |
| Built: | 2026-06-04 08:30:56 UTC |
| Source: | https://github.com/hypertidy/timenow |
Uses a cascade of methods to determine the local timezone, useful when the system timezone is set to UTC.
detect_timezone(quiet = FALSE)detect_timezone(quiet = FALSE)
quiet |
Suppress messages about detection method used |
A valid IANA timezone string
Matches partial or fuzzy timezone specifications against IANA timezone names. If the string cannot be matched directly, and the location package is installed, it will attempt to geocode the string via Nominatim and derive the timezone from the resulting coordinates.
resolve_timezone(tz)resolve_timezone(tz)
tz |
A timezone string, possibly fuzzy like "Perth" or "US Eastern", or a place name like "Jackson, TN" (requires location). |
A valid IANA timezone string
resolve_timezone("Perth") resolve_timezone("new york") resolve_timezone("tokyo") ## Not run: # requires location + lutz packages resolve_timezone("Jackson, TN") resolve_timezone("Davis Station, Antarctica") ## End(Not run)resolve_timezone("Perth") resolve_timezone("new york") resolve_timezone("tokyo") ## Not run: # requires location + lutz packages resolve_timezone("Jackson, TN") resolve_timezone("Davis Station, Antarctica") ## End(Not run)
Reports the current timestamp in UTC and optionally in a local or specified timezone. Uses a detection cascade to find your local timezone when the system reports UTC.
timenow(tz = NULL, quiet = FALSE)timenow(tz = NULL, quiet = FALSE)
tz |
Optional timezone specification. Can be:
|
quiet |
Suppress the local timezone detection message |
When your system timezone is UTC (common on servers), timenow uses this cascade to find your actual local timezone:
getOption("timenow.tz") - set in .Rprofile
Sys.getenv("R_TIMENOW_TZ") - set in .Renviron
/etc/timezone file (Debian/Ubuntu)
timedatectl output (systemd)
Sys.timezone() - the R default
In ~/.Renviron:
R_TIMENOW_TZ=Australia/Hobart
Or in ~/.Rprofile:
options(timenow.tz = "Australia/Hobart")
A named list of class "timenow" with UTC and local times (invisibly)
timenow() timenow("Perth") timenow("US Eastern")timenow() timenow("Perth") timenow("US Eastern")
Prints guidance on setting your local timezone for timenow.
timenow_help()timenow_help()
Writes your timezone preference to ~/.Renviron so it persists across sessions. Supports fuzzy timezone matching.
timenow_set(tz, renviron = "~/.Renviron", restart = TRUE)timenow_set(tz, renviron = "~/.Renviron", restart = TRUE)
tz |
Timezone string (can be fuzzy like "Hobart" or "Perth Australia") |
renviron |
Path to .Renviron file (default: ~/.Renviron) |
restart |
Prompt to restart R after setting (default: TRUE) |
The resolved timezone string (invisibly)
## Not run: timenow_set("Hobart") timenow_set("Perth Australia") ## End(Not run)## Not run: timenow_set("Hobart") timenow_set("Perth Australia") ## End(Not run)