schyntax / js-schyntax

A simple Node.js utility for parsing schedule strings, and finding the next scheduled event time.
MIT License
4 stars 2 forks source link

Weeks Expressions #5

Open bretcope opened 10 years ago

bretcope commented 10 years ago

Weeks

I'm starting to think there needs to be a weeks expression to help express things like:

The two above examples could be expressed as:

days(friday) weeks(1,3) and (monday) weeks(-1)

Just like days of month, the week number could be expressed either as the number of weeks from the start of the month, or a negative number representing the number of weeks from the end of the month (1 and -1-indexed respectively).

Technically this is just syntactic sugar since both of the above examples could already be expressed as:

days(friday) dom(1..7, 15..21) and days(monday) dom(-7..-1)

but the weeks expression is far more readable and less error prone. It should also be rather trivial to implement.

Weeks should have the aliases: w, week, weeks, weekofmonth, and weeksofmonth. Anticipating this expression was actually the reason for commit 1606847ca8bcd3036e28f006ad3a53f675c3a3f7 a couple months ago.


Full Weeks

What would be more than simply syntax sugar would be to add a fullWeeks expression. Say you want something to run everyday for the first full week of a month, not simply the first seven days

fullweeks(1)

That would run everyday at midnight for seven days starting on the first Sunday of each month.

I can't think of any way to express this with the existing syntax so I think it would be a good addition to the language and still relatively trivial to implement.

Negative numbers would also be supported:

fullweeks(-1) would run for seven days ending on the last Saturday of the month.

Zero and negative zero would also be supported:

fullweeks(0) would run any day of the month which is before the first Sunday, and fullweeks(-0) would run any days of the month after the final Saturday.

Aliases: fw, fullweek, fullweeks, fullweekofmonth, and fullweeksofmonth.

Spiralis commented 8 years ago

I think I like the suggestion for this. It would be useful to me.

Spiralis commented 8 years ago

I have made a suggestion on a change to the proposed syntax. Ref https://github.com/schyntax/schyntax/issues/14.

In short I suggest that:

There were some other suggestions in that post too that may be worth considering.