Skip to content

Implement date_time_info() and zoned_time_info() #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DavisVaughan opened this issue Apr 8, 2022 · 0 comments · Fixed by #337
Closed

Implement date_time_info() and zoned_time_info() #295

DavisVaughan opened this issue Apr 8, 2022 · 0 comments · Fixed by #337
Labels
feature a feature request or enhancement

Comments

@DavisVaughan
Copy link
Member

DavisVaughan commented Apr 8, 2022

library(clock)

# Add input type checking
zoned_time_info <- function(x) {
  zone <- clock:::zoned_time_zone_attribute(x)
  x <- as_sys_time(x)
  out <- sys_time_info(x, zone)
  out$begin <- as_zoned_time(out$begin, zone = zone)
  out$end <- as_zoned_time(out$end, zone = zone)
  out
}

date_time_info <- function(x) {
  x <- as_zoned_time(x)
  out <- zoned_time_info(x)
  out$begin <- as_date_time(out$begin)
  out$end <- as_date_time(out$end)
  out
}

x <- date_time_parse("1970-10-25 00:00:00", "America/New_York")
x <- x + c(3600, 7200)

date_time_info(x)
#>                 begin                 end offset   dst abbreviation
#> 1 1970-04-26 03:00:00 1970-10-25 01:00:00 -14400  TRUE          EDT
#> 2 1970-10-25 01:00:00 1971-04-25 03:00:00 -18000 FALSE          EST
zoned_time_info(as_zoned_time(x))
#>                                         begin
#> 1 1970-04-26T03:00:00-04:00[America/New_York]
#> 2 1970-10-25T01:00:00-05:00[America/New_York]
#>                                           end offset   dst abbreviation
#> 1 1970-10-25T01:00:00-05:00[America/New_York] -14400  TRUE          EDT
#> 2 1971-04-25T03:00:00-04:00[America/New_York] -18000 FALSE          EST

These won't actually conflict with or be ambiguous with naive_time_info() in any way because we already know the time zone to look the information up in, and we know it is a unique type because the times exist already.

Follow up to #170 that does add zoned_time_info() back in. I feel like these wrappers are actually fairly useful and unambiguous.

Should make sure the begin/end limits are working right (year 32767 and whatnot)

Crosslink between these and naive_time_info() and sys_time_info()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant