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

Duration's fromString & toString may be incorrect acrroding to rfc5545 #732

Open
FangNotFish opened this issue Jul 14, 2024 · 1 comment

Comments

@FangNotFish
Copy link

rfc5545 says the notation of duration is:

dur-value  = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
dur-date   = dur-day [dur-time]
dur-time   = "T" (dur-hour / dur-minute / dur-second)
dur-week   = 1*DIGIT "W"
dur-hour   = 1*DIGIT "H" [dur-minute]
dur-minute = 1*DIGIT "M" [dur-second]
dur-second = 1*DIGIT "S"
dur-day    = 1*DIGIT "D"

For convenience, ignore the leading (["+"] / "-") "P" and use NUM to represent 1*DIGIT, then expand it:

  1. (dur-date)
    • NUM "D"
    • NUM "D" "T" NUM "H" [NUM "M" [NUM "S"]]
    • NUM "D" "T" NUM "M" [NUM "S"]
    • NUM "D" "T" NUM "S"
  2. (dur-time)
    • "T" NUM "H" [NUM "M" [NUM "S"]]
    • "T" NUM "M" [NUM "S"]
    • "T" NUM "S"
  3. (dur-week)
    • NUM "W"

Thus, the conclusion is

  1. each parts of dur-time is ordered.
  2. dur-week is mutually exclusive with dur-date and dur-time.

In current implementation of ical.js, the order is ignored and dur-week could appear while dur-date or dur-time is displayed.

parseDurationChunk(...) do not respect conclusion#1, just assume the input string follow the rfc5545 spec.

object[type] = num;

toString() do not respect conclusion#2, but after normalize() called would be fine.

if (this.weeks) str += this.weeks + "W";

if (this.days) str += this.days + "D";

@kewisch
Copy link
Owner

kewisch commented Sep 11, 2024

Thanks for reporting, your conclusions seem right to me as well. Let's see if we can fix toString as well!

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

No branches or pull requests

2 participants