1.0.11 • Published 24 days ago

next-renew-js v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
24 days ago

next-renew-js

The next-renew-js library efficiently calculates upcoming renewal dates with flexible interval options. It seamlessly handles daily, weekly, monthly, or yearly scenarios, allowing you to customize calculations based on parameters like interval and start date. Ensure accurate results, even in special cases, for precise renewal date integration.

Installation

npm install next-renew-js

Options

OptionTypeDescription
intervalnumberRepresents the interval in which the renewal occurs. Example: An interval of 2 means the renewal occurs every two days, weeks, months, or years. Optional.
fromDateOptional. Specifies the starting date from which the renewal should begin. Default: (current Date).
numberOfRenewalsnumberOptional. Indicates the total number of renewals that should occur.
end_dateDateOptional. Specifies an end date for the renewals.
timezonestringOptional. Specifies the timezone in which the renewals should occur. Default: undefined.
typestringRequired. Specifies the type of renewal. Choose one of the following: day, week, month, year.
weekDaynumberRequired for week type. Specifies the day of the week for weekly renewal (0 for Monday, and so on). Accepted values: 0 to 6.
monthDaynumberRequired for month and year types. Specifies the day of the month when the renewal should happen. Accepted values: 1 to 31.
monthnumberRequired for year type. Specifies the month of the year when the yearly renewal should happen. Accepted values: 0 to 11.

Result

PropertyTypeDescription
dateDateThe date of the next renewal.
listDate[]A list of upcoming renewal dates

Usage

import nextRenew, { NextRenewOptions } from "next-renew-js";

const startingDate = new Date("2023-01-15T00:00:00.000Z")

const options: NextRenewOptions = {
  type: "month",
  monthDay: 25,
  from: startingDate, // Optional (for demonstration purposes)
};

console.log(result.date); // 2023-01-25T00:00:00.000Z
console.log(result.list); // [2023-01-25T00:00:00.000Z, 2023-02-25T00:00:00.000Z, 2023-03-25T00:00:00.000Z, ...]

In some scenarios, special situations may arise that go beyond the basic settings. One such case involves calculating the renewal day when it exceeds the maximum for the current month. In this context, if the specified day exceeds the maximum number of days in the current month, the library behaves in a special way, considering the last day of the month as the renewal day.

For example, if you specify the 31st day for monthly renewal and the current month has fewer than 31 days, the library will automatically adapt the calculation using the last day of the month.

import nextRenew, { NextRenewOptions } from "next-renew-js";

const startingDate = new Date("2023-01-15T00:00:00.000Z")

const options: NextRenewOptions = {
  type: "month",
  monthDay: 31,
  from: startingDate, // Optional (for demonstration purposes)
};

console.log(result.date); // 2023-01-31T00:00:00.000Z
console.log(result.list); // [2023-01-31T00:00:00.000Z, 2023-02-28T00:00:00.000Z, 2023-03-31T00:00:00.000Z, ...]

Utility Functions

The next-renew-js library provides the following utility functions for additional flexibility and convenience.

FunctionDescription
monthsToMillisConverts the specified number of months to milliseconds.
daysToMillisConverts the specified number of days to milliseconds.
hoursToMillisConverts the specified number of hours to milliseconds.
minutesToMillisConverts the specified number of minutes to milliseconds.
cloneDateCreates a new Date object with the same time value as the provided Date object.
convertToLocaleConverts the provided date to the local timezone.
convertToUTCConverts the provided date to Coordinated Universal Time (UTC) based on the specified timezone.
numDaysCalculates the number of days between two given dates.
weekDayDistanceCalculates the distance (number of days) between two weekdays (e.g., Monday to Friday).
1.0.11

24 days ago

1.0.10

24 days ago

1.0.9

4 months ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago