- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8
 
Description
I'm aware you've made some very deliberate design decisions in regards to the calendar classes, and what can be done with them, but would you consider being a little more flexible in some of the methods you provide? The motivation for this is to avoid downstream packages providing multiple, similar methods to work around some of the strictness.
As a concrete example, consider <iso_year_week_day> objects of varying precision. Quite often you would want something akin to calendar_spanning_seq that corresponds to valid timepoints. At present, due to the strictness of the class, I could envisage multiple implementations popping up similar to:
library(clock)
days <- iso_year_week_day(2021:2022, c(1L, 52L), 1L)
wks  <- calendar_narrow(days, "week")
yrs <- calendar_narrow(days, "year")
my_calendar_spanning_seq.clock_iso_year_week_day <- function(x) {
    
    df <- function(x) {
        out <- as_naive_time(x)
        out <- seq(min(out), max(out), by = 1L)
        as_iso_year_week_day(out)
    }
    
    wf <- function(x) {
        out <- calendar_widen(x, "day")
        out <- as_naive_time(out)
        out <- seq(min(out), max(out), by = 7L)
        out <- as_iso_year_week_day(out)
        calendar_narrow(out, "week")
    }
    
    precision <- calendar_precision(x)
    
    switch(
        precision,
        "day" = df(x),
        "week" = wf(x),
        "year" = calendar_spanning_seq(x),
        stop("Unsupported precision")
    )
}I'm aware that you're still working on how you think {clock} is best utilised by other packages and for end users the benefit of the current approach is to make them explicitly handle these situations. However I'm hoping there is scope to maintain the minimalist class constructors but slightly increase the flexibility of the methods (balanced with increased documentation as to what the methods are doing).
I hope all this makes sense and no problem if you want to keep things as is (I just wanted to ensure I had raised it as a discussion point).