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

Display minutes for time #388

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry=https://npm.pkg.github.com/pulsarplatform
LeoRosse marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "rrule",
"version": "2.6.4",
"name": "@pulsarplatform/rrule",
LeoRosse marked this conversation as resolved.
Show resolved Hide resolved
"version": "1.0.3",
"description": "JavaScript library for working with recurrence rules for calendar dates.",
"homepage": "http://jakubroztocil.github.io/rrule/",
"license": "BSD-3-Clause",
"keywords": [
"dates",
Expand All @@ -17,18 +16,21 @@
"typings": "dist/esm/src/index.d.ts",
"repository": {
"type": "git",
"url": "git://github.com/jakubroztocil/rrule.git"
"url": "git://github.com/pulsarplatform/rrule.git"
},
"husky": {
"hooks": {
"pre-commit": "yarn lint"
"pre-commit": "npm run lint"
}
},
"scripts": {
"build": "yarn lint && tsc && webpack && tsc dist/esm/**/*.d.ts",
"lint": "yarn tslint --project . --fix --config tslint.json",
"build": "npm run lint && tsc && webpack && tsc dist/esm/**/*.d.ts",
"lint": "tslint --project . --fix --config tslint.json",
"test": "TS_NODE_PROJECT=tsconfig.test.json mocha **/*.test.ts",
"test-ci": "TS_NODE_PROJECT=tsconfig.test.json nyc mocha **/*.test.ts"
"test-ci": "TS_NODE_PROJECT=tsconfig.test.json nyc mocha **/*.test.ts",
"no-can-do": "echo \"Cannot bump version automatically on branch master. Please run 'npm version [major|minor|patch]' manually.\"",
"build-version": "if [ $(git symbolic-ref --short HEAD) = master ]; then npm run --silent no-can-do; else npx version-from-git; fi",
"publish-version": "npm publish --tag $(if [ $(git symbolic-ref --short HEAD) = master ]; then echo latest; else echo $(git symbolic-ref --short HEAD); fi)"
},
"nyc": {
"extension": [
Expand Down
95 changes: 55 additions & 40 deletions src/nlp/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,78 @@ export interface Language {
dayNames: string[]
monthNames: string[]
tokens: {
[k: string]: RegExp
[k: string]: RegExp;
}
}

const ENGLISH: Language = {
dayNames: [
'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday'
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
],
monthNames: [
'January', 'February', 'March', 'April', 'May',
'June', 'July', 'August', 'September', 'October',
'November', 'December'
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
],
tokens: {
'SKIP': /^[ \r\n\t]+|^\.$/,
'number': /^[1-9][0-9]*/,
'numberAsText': /^(one|two|three)/i,
'every': /^every/i,
SKIP: /^[ \r\n\t]+|^\.$/,
number: /^[0-9][0-9]*/,
numberAsText: /^(one|two|three)/i,
every: /^every/i,
'day(s)': /^days?/i,
'weekday(s)': /^weekdays?/i,
'week(s)': /^weeks?/i,
'hour(s)': /^hours?/i,
'minute(s)': /^minutes?/i,
'month(s)': /^months?/i,
'year(s)': /^years?/i,
'on': /^(on|in)/i,
'at': /^(at)/i,
'the': /^the/i,
'first': /^first/i,
'second': /^second/i,
'third': /^third/i,
'nth': /^([1-9][0-9]*)(\.|th|nd|rd|st)/i,
'last': /^last/i,
'for': /^for/i,
on: /^(on|in)/i,
at: /^(at)/i,
the: /^the/i,
first: /^first/i,
second: /^second/i,
third: /^third/i,
nth: /^([1-9][0-9]*)(\.|th|nd|rd|st)/i,
last: /^last/i,
for: /^for/i,
'time(s)': /^times?/i,
'until': /^(un)?til/i,
'monday': /^mo(n(day)?)?/i,
'tuesday': /^tu(e(s(day)?)?)?/i,
'wednesday': /^we(d(n(esday)?)?)?/i,
'thursday': /^th(u(r(sday)?)?)?/i,
'friday': /^fr(i(day)?)?/i,
'saturday': /^sa(t(urday)?)?/i,
'sunday': /^su(n(day)?)?/i,
'january': /^jan(uary)?/i,
'february': /^feb(ruary)?/i,
'march': /^mar(ch)?/i,
'april': /^apr(il)?/i,
'may': /^may/i,
'june': /^june?/i,
'july': /^july?/i,
'august': /^aug(ust)?/i,
'september': /^sep(t(ember)?)?/i,
'october': /^oct(ober)?/i,
'november': /^nov(ember)?/i,
'december': /^dec(ember)?/i,
'comma': /^(,\s*|(and|or)\s*)+/i
until: /^(un)?til/i,
monday: /^mo(n(day)?)?/i,
tuesday: /^tu(e(s(day)?)?)?/i,
wednesday: /^we(d(n(esday)?)?)?/i,
thursday: /^th(u(r(sday)?)?)?/i,
friday: /^fr(i(day)?)?/i,
saturday: /^sa(t(urday)?)?/i,
sunday: /^su(n(day)?)?/i,
january: /^jan(uary)?/i,
february: /^feb(ruary)?/i,
march: /^mar(ch)?/i,
april: /^apr(il)?/i,
may: /^may/i,
june: /^june?/i,
july: /^july?/i,
august: /^aug(ust)?/i,
september: /^sep(t(ember)?)?/i,
october: /^oct(ober)?/i,
november: /^nov(ember)?/i,
december: /^dec(ember)?/i,
comma: /^(,\s*|(and|or)\s*)+/i,
colon: /^(\s*:\s*)/i
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/nlp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import RRule from '../index'
import ENGLISH, { Language } from './i18n'

/*!
* rrule.js - Library for working with recurrence rules for calendar dates.
* https://github.com/jakubroztocil/rrule
*
* Copyright 2010, Jakub Roztocil and Lars Schoning
* Licenced under the BSD licence.
* https://github.com/jakubroztocil/rrule/blob/master/LICENCE
*
*/
* rrule.js - Library for working with recurrence rules for calendar dates.
* https://github.com/jakubroztocil/rrule
*
* Copyright 2010, Jakub Roztocil and Lars Schoning
* Licenced under the BSD licence.
* https://github.com/jakubroztocil/rrule/blob/master/LICENCE
*
*/

/**
*
Expand Down Expand Up @@ -110,16 +110,21 @@ const common = [
ToText.IMPLEMENTED = []
ToText.IMPLEMENTED[RRule.HOURLY] = common
ToText.IMPLEMENTED[RRule.MINUTELY] = common
ToText.IMPLEMENTED[RRule.DAILY] = ['byhour'].concat(common)
ToText.IMPLEMENTED[RRule.WEEKLY] = common
ToText.IMPLEMENTED[RRule.MONTHLY] = common
ToText.IMPLEMENTED[RRule.DAILY] = ['byhour', 'byminute'].concat(common)
ToText.IMPLEMENTED[RRule.WEEKLY] = ['byhour', 'byminute'].concat(common)
ToText.IMPLEMENTED[RRule.MONTHLY] = ['byhour', 'byminute'].concat(common)
ToText.IMPLEMENTED[RRule.YEARLY] = ['byweekno', 'byyearday'].concat(common)

// =============================================================================
// Export
// =============================================================================

const toText = function (rrule: RRule, gettext?: GetText, language?: Language, dateFormatter?: DateFormatter) {
const toText = function (
rrule: RRule,
gettext?: GetText,
language?: Language,
dateFormatter?: DateFormatter
) {
return new ToText(rrule, gettext, language, dateFormatter).toString()
}

Expand Down
60 changes: 45 additions & 15 deletions src/nlp/parsetext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Parser {
this.value = null
return
}
// @ts-ignore
// @ts-ignore
} while (bestSymbol === 'SKIP')

// @ts-ignore
Expand Down Expand Up @@ -119,6 +119,7 @@ export default function parseText (text: string, language: Language = ENGLISH) {
options.freq = RRule.DAILY
if (ttr.nextSymbol()) {
AT()
COLON()
F()
}
break
Expand All @@ -127,21 +128,19 @@ export default function parseText (text: string, language: Language = ENGLISH) {
// DAILY on weekdays is not a valid rule
case 'weekday(s)':
options.freq = RRule.WEEKLY
options.byweekday = [
RRule.MO,
RRule.TU,
RRule.WE,
RRule.TH,
RRule.FR
]
options.byweekday = [RRule.MO, RRule.TU, RRule.WE, RRule.TH, RRule.FR]
ttr.nextSymbol()
AT()
COLON()
F()
break

case 'week(s)':
options.freq = RRule.WEEKLY
if (ttr.nextSymbol()) {
ON()
AT()
COLON()
Comment on lines +142 to +143
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main draw back with this approach is that lists of times are not supported though that may be intentional.

For example in the list case you would have to list all permutation for this to work

// Invalid
every day at 9:00 and 11:30 => RRULE:FREQ=DAILY;BYHOUR=9,11;BYMINUTE=0,30
// valid
every day at 9:00, 9:30, 11:00 and 11:30 => RRULE:FREQ=DAILY;BYHOUR=9,11;BYMINUTE=0,30

Personally, I think it's reasonable to limit this to one hour time combo to prevent confusion

F()
}
break
Expand All @@ -166,6 +165,8 @@ export default function parseText (text: string, language: Language = ENGLISH) {
options.freq = RRule.MONTHLY
if (ttr.nextSymbol()) {
ON()
AT()
COLON()
F()
}
break
Expand All @@ -186,7 +187,9 @@ export default function parseText (text: string, language: Language = ENGLISH) {
case 'saturday':
case 'sunday':
options.freq = RRule.WEEKLY
const key: WeekdayStr = ttr.symbol.substr(0, 2).toUpperCase() as WeekdayStr
const key: WeekdayStr = ttr.symbol
.substr(0, 2)
.toUpperCase() as WeekdayStr
options.byweekday = [RRule[key]]

if (!ttr.nextSymbol()) return
Expand All @@ -197,7 +200,9 @@ export default function parseText (text: string, language: Language = ENGLISH) {

let wkd = decodeWKD() as keyof typeof RRule
if (!wkd) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected weekday')
throw new Error(
'Unexpected symbol ' + ttr.symbol + ', expected weekday'
)
}

// @ts-ignore
Expand Down Expand Up @@ -231,7 +236,9 @@ export default function parseText (text: string, language: Language = ENGLISH) {

let m = decodeM()
if (!m) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected month')
throw new Error(
'Unexpected symbol ' + ttr.symbol + ', expected month'
)
}

options.bymonth.push(m)
Expand Down Expand Up @@ -294,13 +301,17 @@ export default function parseText (text: string, language: Language = ENGLISH) {
ttr.nextSymbol()
let n = ttr.acceptNumber()
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + ', expected week number')
throw new Error(
'Unexpected symbol ' + ttr.symbol + ', expected week number'
)
}
options.byweekno = [parseInt(n[0], 10)]
while (ttr.accept('comma')) {
n = ttr.acceptNumber()
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday')
throw new Error(
'Unexpected symbol ' + ttr.symbol + '; expected monthday'
)
}
options.byweekno.push(parseInt(n[0], 10))
}
Expand Down Expand Up @@ -329,13 +340,30 @@ export default function parseText (text: string, language: Language = ENGLISH) {
while (ttr.accept('comma')) {
n = ttr.acceptNumber()
if (!n) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected hour')
throw new Error(
'Unexpected symbol ' + ttr.symbol + '; expected hour'
)
}
options.byhour.push(parseInt(n[0], 10))
}
} while (ttr.accept('comma') || ttr.accept('at'))
}

function COLON () {
const colon = ttr.accept('colon')
if (!colon) return

do {
let m = parseInt(ttr.acceptNumber()[0], 10)
if (!m) {
throw new Error(
'Unexpected symbol ' + ttr.symbol + ', expected minutes'
)
}
options.byminute = m
} while (ttr.accept('colon'))
}

function decodeM () {
switch (ttr.symbol) {
case 'january':
Expand Down Expand Up @@ -421,7 +449,9 @@ export default function parseText (text: string, language: Language = ENGLISH) {
while (ttr.accept('comma')) {
nth = decodeNTH()
if (!nth) {
throw new Error('Unexpected symbol ' + ttr.symbol + '; expected monthday')
throw new Error(
'Unexpected symbol ' + ttr.symbol + '; expected monthday'
)
}

options.bymonthday.push(nth)
Expand Down
Loading