Skip to content

Commit

Permalink
update byday
Browse files Browse the repository at this point in the history
  • Loading branch information
PeronGH committed Sep 7, 2022
1 parent a4686e0 commit 9bedf74
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"deno.enable": true,
"cSpell.words": [
"BYDAY",
"CALSCALE",
"DTEND",
"DTSTAMP",
Expand Down
1 change: 1 addition & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Calendar, Event } from './main.ts';
export type { EventConfig } from './main.ts';
export type { Day, RecurrenceRule } from './rrule.ts';
6 changes: 5 additions & 1 deletion rrule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ export interface RecurrenceRule {
until?: DateData;
interval?: number;
count?: number;
byDay?: Day[];
}

export function parseRRule(rrule: RecurrenceRule | undefined) {
if (rrule === undefined) return;

const { freq, until, interval, count } = rrule;
const { freq, until, interval, count, byDay } = rrule;

return [
['FREQ', freq],
['UNTIL', parseDate(until)],
['INTERVAL', interval],
['COUNT', count],
['BYDAY', byDay ? byDay.join() : undefined],
]
.filter(line => line[1] !== undefined)
.map(line => `${line[0]}=${line[1]};`)
.join('');
}

export type Day = 'MO' | 'TU' | 'WE' | 'TH' | 'FR' | 'SA' | 'SU';

0 comments on commit 9bedf74

Please sign in to comment.