npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kinaxis/calendar-math

v2.0.5

Published

Helper functions for manipulating dates using RapidResponse calendars.

Downloads

15

Readme

calendar-math

Helper functions for manipulating dates using RapidResponse calendars.

Documentation

Types

Calendar

A collection of dates which define the intervals of the calendar. Example RapidResponse calendars are Week, Month, Workday, and Everyday.

|Property |Type |Description| |----------|----------------|-----------| |Dates |CalendarDate[]|Dates in the calendar, each representing the beginning of intervals. For example, the month calendar contains a CalendarDate for the first day of each month.|


CalendarDate

A date in a Calendar, representing the start of an interval.

|Property |Type |Description| |----------|------|-----------| |Value |Date|Date value|


To use RapidResponse calendars in an embedded algorithm, the algorithm must have appropriate dependencies on the Calendar and CalendarDate tables.

For more information on RapidResponse calendars, see https://help.kinaxis.com/20162/GlobalHelp/Content/RR_DataModel/Calendar_and_date_calcs/Calendar_tables.htm.

Functions

addCalendarToDate(date, amount[, calendar])

Offset a date by the specified number of calendar intervals, according to RapidResponse date arithmetic rules.

For example, to return the first day of the next week you would use the Week calendar and specify amount as 1. To return the first day of the previous week you would use the Week calendar and specify amount as -1. Adding 0 returns the beginning of the the specified date's current interval for the specified calendar. For example, adding 0 using the Week calendar returns the first day of the date's week. Doing the same with the Month calendar returns the first day of the date's month.

|Argument |Type |Description| |----------|--------|-----------| |date |Date |The date to offset. Date.Past and Date.Future are sticky, meaning that any addition on them results in the same date. Using an invalid date will return Date.Undefined.| |amount |number|The number of calendar integer intervals to offset date by| |calendar |Calendar|Optional calendar to use for the calculation. If no calendar is specified or the calendar has no dates, amount is interpreted in days. If the calendar only has one date, then any result less than that date returns Date.Past and any result greater than or equal to that date returns Date.Future.|

Return value: The Date obtained by adding amount intervals in the specified calendar to date. If the result is less than the first valid date in the calendar, Date.Past is returned. If the result is greater than the last valid date in the calendar, Date.Future is returned.

CAUTION: When using a date constant (i.e., Date.PAST, Date.FUTURE, or Date.UNDEFINED), do so using the globally available date constants instead of manually creating the dates. Future versions of the library or the embedded algorithms runtime may change the values of these date constants.

CAUTION: Do not modify calendar in code after calling this function. For performance reasons, data structures based on the data in calendar are generated and cached internally. Calling this function with the same Calendar object will use the same internal cache regardless of whether or not the contents of that object have changed. This will lead to incorrect results if it is modified. To modify calendar data, do so in RapidResponse.


subtractDates(date1, date2[, calendar])

Calculate the number of intervals in calendar between date1 and date2, according to RapidResponse date arithmetic rules.

For example, new Date("2020-09-14T00:00:00.000Z") - new Date("2020-06-12T00:00:00.000Z") using the month calendar returns 3.

|Argument |Type |Description| |----------|--------|-----------| |date1 |Date |The first date| |date2 |Date |The second date| |calendar |Calendar|Optional calendar to use for the calculation. If no calendar is specified or the calendar has no dates then result will be in days. If the calendar only has one date, the result will be 65535.|

Return value: The span of time between date1 and date2 in intervals of calendar. If date1 or date2 are invalid, equal to Date.Past, Date.Future, or Date.Undefined, or if the result of the calculation is outside of the bounds of the specified calendar then the result will be 65535 (if date1 is larger) or -65535 (if date2 is larger). If the calendar only has one date, then the result will always be 65535.

CAUTION: When using a date constant (i.e., Date.PAST, Date.FUTURE, or Date.UNDEFINED), do so using the globally available date constants instead of manually creating the dates. Future versions of the library or the embedded algorithms runtime may change the values of these date constants.

CAUTION: Do not modify calendar in code after calling this function. For performance reasons, data structures based on the data in calendar are generated and cached internally. Calling this function with the same Calendar object will use the same internal cache regardless of whether or not the contents of that object have changed. This will lead to incorrect results if it is modified. To modify calendar data, do so in RapidResponse.


For more information on RapidResponse date arithmetic rules, see https://help.kinaxis.com/20162/GlobalHelp/Content/RR_DataModel/Calendar_and_date_calcs/Date_calculation_rules.htm.

Please contact [email protected] if you experience any issues.

Copyright © 2022 Kinaxis. All Rights Reserved.