Skip to content

Instantly share code, notes, and snippets.

@s-taylor
Created June 10, 2017 23:39
Show Gist options
  • Save s-taylor/f59e0cefc9c2e52d77271cebf021de01 to your computer and use it in GitHub Desktop.
Save s-taylor/f59e0cefc9c2e52d77271cebf021de01 to your computer and use it in GitHub Desktop.
How does Time Walk differ to Rrule

How does Time Walk differ to Rrule?

Timezone Support

The largest issue I have with Rrule is that it has no real timezone support. Dates are always generated based off the timezone of your machine/server. I want the same functionality but with the ability to specify what timezone the resulting dates should be in.

Leverage Moment

I also wanted to see if it was possible to make a much more lightweight library. For the most part moment-timezone already handles the complex logic of adding months, weeks, days to a date, so why not leverage that for date logic?

Enforce Rule Start Dates

I also don't particularly like how Rrule does not enforce the use of DTSTART (the start date for a rule). For some rules this is not necessary, this is best explained with an example.

Imagine I want a rule that gives me the 1st of every month, there's two completely different ways I could define this.

  • Without DTSTART - FREQ=MONTHLY;BYMONTHDAY=1. This specifically states give me the 1st of every month, without providing a start date.
  • With DTSTART - FREQ=MONTHLY;DTSTART=20170501T000000Z. This works since the 1st of May is a Monday (I've used UTC midnight here) and I want a recurrance every month.

This is sort of fine, both of these get the job done, I'd prefer no ambiguity but it's not that bad. But what if we want a fortnightly or bi-monthly rule? Then we MUST set a DTSTART otherwise our rule simply doesn't know which week/month to include and which week/month to skip (since it's every second month/week). If we don't, we're going to get weird results when we call the .between rule multiple times.

So my thoughts were, why not just always have a DTSTART value? If I want a rule that gives me the 1st of every month, it's not hard to just pick from a calendar "the 1st" and then set the interval to 1 month. Likewise if I want every second Wednesday, I pick a Wednesday on my calendar that I want to include, then set the interval to 2 weeks.

In my opinion it just makes sense to always have a start date.

Multiple Patterns in 1 Rule

One thing I've chosen to omit which Rrule provides is the option to have a single rule that can effecively output multiple patterns. Rrule can for example provide a rule that gives me every tuesday and friday each week, this will not be possible with Time Walk. The reason for this, is in my mind this is two rules, not one. Why not just create two rules instead?

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