Coder Social home page Coder Social logo

sleavely / next-monthly Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 321 KB

Determine the next monthly occurence of a JS date, falling back on the last day of the month

License: MIT License

JavaScript 97.42% Shell 2.58%
dates javascript monthly nodejs recurring-payments

next-monthly's Introduction

next-monthly

Determine the next monthly occurence, falling back on the last day of the month.

npm version CI status

Installation

npm i next-monthly

Usage

const nextMonthly = require('next-monthly')

// Jan 31, Feb 28 or 29, etc.
const lastDayOfThisMonth = nextMonthly()

// If you want to charge users who signed up on the 30th (but sometimes on Feb 28, etc.)
const nextBillingDate = nextMonthly({
  from: '1990-01-07T01:29:03.999Z',

  // Defaults to Date.now(). Only used here for demo purpose:
  now:  '2022-08-23T12:29:08.551Z',
})
// Date: 2022-09-07T01:29:03.999Z

Options

Property Description
from The basis for the monthly occurrance. Defaults to 0000-01-31T00:00:00.000Z for a classic last-day-of-month experience.
now The point in time from which to look for the next occurance. Defaults to Date.now().

See also

  • rrule - Library for working with recurrence rules for calendar dates according to RFC 5545.

next-monthly's People

Contributors

github-actions[bot] avatar sleavely avatar

Stargazers

 avatar

Watchers

 avatar  avatar

next-monthly's Issues

Add `offset` option

As a consumer of next-monthly I don't want to have to figure out how to add or subtract months to show upcoming or past billing dates.

Suggested additional option and its behavior:

const nextBillingDate = nextMonthly({
  from: '1990-01-07T01:29:03.999Z',
  now:  '2022-08-23T12:29:08.551Z',
  offset: -1, // <- This is new. Could default to 0
})
// 2022-08-07T01:29:03.999Z instead of 2022-09-07T01:29:03.999Z

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.