Skip to content
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

How to skip invalid dates forward or backward? #2827

Open
khawarizmus opened this issue Apr 23, 2024 · 1 comment
Open

How to skip invalid dates forward or backward? #2827

khawarizmus opened this issue Apr 23, 2024 · 1 comment
Labels

Comments

@khawarizmus
Copy link

khawarizmus commented Apr 23, 2024

I am currently looking at the SKIP property in section 4.1 of RFC 7529. and specifically this part:

This specification introduces a new "RRULE" element, "SKIP", for use
only when the "RSCALE" element is present.  The "SKIP" element allows
the calendar user agent to specify new options for handling invalid dates.

      "SKIP=OMIT": this is the default option and corresponds to the
      existing iCalendar behavior of simply ignoring the invalid date.

      "SKIP=BACKWARD": when this option is set, a date with an invalid
      month is changed to the previous (valid) month.  A date with an
      invalid day-of-month is changed to the previous (valid)
      day-of-month.

      "SKIP=FORWARD": when this option is set, a date with an invalid
      month is changed to the next (valid) month.  A date with an
      invalid day-of-month is changed to the next (valid) day-of-month.

With that in mind I see that it's possible to implement the OMIT option by using overflow: reject option in temporal. However I don't see any controls offered by the overflow option to decide if clamping for example when using overflow: constrain should go forward or backward.

currently i have the following logic where i combine it with the disambiguation option but i think it's not really serving the purpose.

private _resolveSkipOptions(skip: SkipType): SkipDerivedOptions {
    switch (skip) {
      case 'OMIT':
        return {
          overflow: 'reject',
          disambiguation: 'compatible',
        }
      case 'BACKWARD':
        return {
          overflow: 'constrain',
          disambiguation: 'earlier',
        }
      case 'FORWARD':
        return {
          overflow: 'constrain',
          disambiguation: 'later',
        }
      default:
        // default RFC 5545 behaviour
        return {
          overflow: 'reject',
          disambiguation: 'compatible',
        }
    }
  }

Is the above implementation correct and if not what's the proper approach?

@justingrant
Copy link
Collaborator

disambiguation is only used for dealing with repeated or skipped hours caused by time zone transitions. But the spec you linked above refers only to dates, not times. So using disambiguation in that context is probably not correct, unless there's some other part of the spec that requires applying the same SKIP behavior to times too.

overflow: 'reject' will throw, and I'm not sure if this is the behavior you want from OMIT unless you're catching the exception upstream.

To get FORWARD or BACKWARD behavior, you'd probably want to use overflow: 'reject', catch the exception, and then call add in a loop until you get a date whose day matches the original day.

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

No branches or pull requests

3 participants