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

Do not output DTSTART in toString() #83

Closed
espen opened this issue Jan 25, 2015 · 11 comments
Closed

Do not output DTSTART in toString() #83

espen opened this issue Jan 25, 2015 · 11 comments

Comments

@espen
Copy link
Collaborator

espen commented Jan 25, 2015

DTSTART and DTEND is not part of iCalendar RRULE and should not be included when doing .toString().

Perhaps generate something like "DTSTART=x;DTEND=x;RRULE=x" which would be valid iCalendar syntax.

@espen espen changed the title Do not output DTSTART/DTEND in toString() Do not output DTSTART in toString() Jan 25, 2015
@GeoffreyEmery
Copy link

also plus 1 this

@fredpalmer
Copy link

Agreed - this is causing some grief when interoperating with other implementations (e.g. Python dateutil)

@tilthouse
Copy link

👍 for this issue

AFAIK, DTSTART is always supposed to be a different line, not just delimited by ;, so like the example referenced in #84 (newlines are significant):

DTSTART;TZID=US-Eastern:19970902T090000
RRULE:FREQ=WEEKLY;INTERVAL=2;UNTIL=19971224T000000Z;WKST=SU;BYDAY=MO,WE,FR

I do not think (but await correction if wrong) that concatenating these lines with a ; is valid RFC 5545.

@tiltec
Copy link

tiltec commented Jan 20, 2017

@jkbrzt do you accept Pull Requests for this?

Since this would be a breaking change, I could imagine implementing it in a separate function, e.g. icalString() and give an option to the parser as well.

@jorroll
Copy link

jorroll commented Jan 16, 2018

For anyone else running across this issue, I created a helper function which seems to work for my needs (note: it's written in typescript)

export function rrulesetToIcalString(schedule: RRuleSet, startDate: Moment): string {
  // matches `;DTSTART=20180125T080000Z` until `;` or end
  const icalStrings = schedule.valueOf().map(ruleString => ruleString.replace(/;DTSTART=.*?(?=(?:;)|$)/, ''));

  icalStrings.unshift(`DTSTART;TZID=UTC:${startDate.utc().format('YYYYMMDDTHHmmss')}`);

  return icalStrings.join('\n');
}

You give it a RRuleSet and a startDate (I set it up for use with Moment dates, but you get the idea) and it goes through and removes any ;DTSTART=...; sections in the RRuleSet. It then adds one, properly formatted DTSTART section at the beginning of the RuleSet, and then it joins all the sections together.

Note: I think there's only suppose to be one DTSTART value present. Maybe there are iCalendar flavors where this isn't true, however (outside my use case).

@phillbaker
Copy link

To get a compliant rrule string (without the DTSTART), one option is to use RRule.optionsToString directly:

var rule = new RRule({
   freq: RRule.WEEKLY,
   interval: 5,
   byweekday: [RRule.MO, RRule.FR],
   dtstart: new Date(2012, 1, 1, 10, 30),
   until: new Date(2012, 12, 31)
});
var copy = Object.assign({}, rule.origOptions);
delete copy.dtstart
RRule.optionsToString(copy)

@indexofmetals
Copy link

Any update on this? Not too difficult to get a compliant rrule string, thanks to @phillbaker's advice, but would be nice to be able to plug and play with Python's dateutil.

@davidgoli
Copy link
Collaborator

Agreed, there are some differences in syntax with the RFC and with Python. Would be very open to a pull request addressing this!

@davidgoli
Copy link
Collaborator

Now that TZID has been implemented (#261), the library can no longer parse strings that it outputs. I think a backwards-compatible solution can be reached by continuing to parse pre-2.4.0 output strings, but outputting RFC-compliant strings.

@davidgoli
Copy link
Collaborator

^ my last statement here ("the library can no longer parse strings that it outputs") is now incorrect, this was just fixed by #267. Still, it would be ideal to conform to the RFC!

@davidgoli
Copy link
Collaborator

Fixed by #269

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

9 participants