Skip to content

Implement date_time_info() and zoned_time_info() #295

Description

@DavisVaughan
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()

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions