Giter Club home page Giter Club logo

luxon-rrule's Introduction

luxon-rrule: Luxon-based Recurring Interval Sets

npm CircleCI

Recurring interval sets based on iCalendar and Luxon.

Features

  • Parses, canonicalizes, and formats recurring interval sets in iCalendar format.
  • Supports arbitrary time zones naturally, easily, and safely.
  • Safely handles very large or unbounded recurrences (avoiding denial of service).

Installation

npm install luxon-rrule

Usage

import { RecurringIntervalSet } from 'luxon-rrule';

const ris = RecurringIntervalSet.parse(
  `DTSTART:20191231T090000Z
RRULE:FREQ=DAILY;BYDAY=MO,WE,FR;UNTIL=20200110T090000Z
DTSTART:20200113T110000Z
DURATION:PT90M
RRULE:FREQ=DAILY;BYDAY=TU,TH;UNTIL=20200124T110000Z
RDATE:20200128T100000Z,20200130T110000Z
RDATE;VALUE=PERIOD:20200131T100000Z/PT3H
EXDATE:20200116T110000Z,20200117T110000Z`,
  { defaults: { duration: Duration.fromObject({ hours: 2 }) } }
);
console.log('First start:', ris.firstStart?.toISO()); // 2020-01-01T09:00:00.000Z
console.log('Last end:', ris.lastEnd?.toISO()); // 2020-01-31T13:00:00.000Z
console.log('Minimum duration:', ris.minimumDuration?.toISO()); // PT90M
console.log('Maximum duration:', ris.maximumDuration?.toISO()); // PT3H
console.log(
  'Occurrences:',
  ris
    .between(DateTime.fromObject({ year: 2020 }), DateTime.fromObject({ year: 2021 }))
    .map(i => `${i.start.toISO()} - ${i.end.toISO()}`)
    .join('\n')
);
// 2020-01-01T09:00:00.000Z - 2020-01-01T11:00:00.000Z
// 2020-01-03T09:00:00.000Z - 2020-01-03T11:00:00.000Z
// 2020-01-06T09:00:00.000Z - 2020-01-06T11:00:00.000Z
// 2020-01-08T09:00:00.000Z - 2020-01-08T11:00:00.000Z
// 2020-01-10T09:00:00.000Z - 2020-01-10T11:00:00.000Z
// 2020-01-14T11:00:00.000Z - 2020-01-14T12:30:00.000Z
// 2020-01-21T11:00:00.000Z - 2020-01-21T12:30:00.000Z
// 2020-01-23T11:00:00.000Z - 2020-01-23T12:30:00.000Z
// 2020-01-28T10:00:00.000Z - 2020-01-28T11:30:00.000Z
// 2020-01-30T11:00:00.000Z - 2020-01-30T12:30:00.000Z
// 2020-01-31T10:00:00.000Z - 2020-01-31T13:00:00.000Z

License

luxon-rrule is available under the ISC license.

luxon-rrule's People

Contributors

trevorr avatar

Stargazers

Dave Taylor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.