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

retail-calendar

v4.1.2

Published

A configurable retail calendar

Downloads

3,294

Readme

Retail Calendar

A configurable merchandising and retail calendar generator. For a given year and configuration, generates merchandising calendar along with Gregorian boundaries. It can be used for generating all calendar types, including NRF 4-5-4 calendar, 4-4-5 calendar or Gregorian calendar.

Installation

Using npm:

 $ npm i --save retail-calendar

Usage:

Instantiate RetailCalendarFactory with preferred options.

const {
  WeekCalculation,
  WeekGrouping,
  LastDayOfWeek,
  LastMonthOfYear,
  RetailCalendarFactory,
} = require('retail-calendar')

const calendar = new RetailCalendarFactory(
  {
    weekCalculation: WeekCalculation.LastDayNearestEOM,
    weekGrouping: WeekGrouping.Group454,
    lastDayOfWeek: LastDayOfWeek.Saturday,
    lastMonthOfYear: LastMonthOfYear.January,
  },
  2017,
)

A retail calendar either has 52 or 53 weeks.

calendar.numberOfWeeks
calendar.year // Given year, 2017 in this case

A retail calendar always has 12 months.

calendar.months
calendar.months[0].monthOfYear // Starts from 1, up to 12

A retail calendar has quarter of year and week of quarter

Both Month and Week has quarter information

calendar.months[0].quarterOfYear // from 1 to 4
calendar.weeks[0].quarterOfYear // from 1 to 4

The week also has week of quarter:

calendar.weeks[0].weekOfQuarter

Each month consist of complete weeks. Month boundaries are always at the end of week. End of week is given in lastDayOfWeek option. Number of weeks for each month is defined in weekGrouping option.

// Week grouping is 454 which means
calendar.months[0].numberOfWeeks // 4
calendar.months[1].numberOfWeeks // 5
calendar.months[2].numberOfWeeks // 4

calendar.months[3].numberOfWeeks // 4
calendar.months[4].numberOfWeeks // 5
calendar.months[5].numberOfWeeks // 4
// Each quarter repeats the same pattern.

// Each month has an array of weeks it contains.
calendar.months[0].weeks

Each month start and end boundaries expressed in Gregorian calendar.

// Date time of beginning of month.
// In this case Feb 5, 2017 12:00 AM
calendar.months[0].gregorianStartDate
// Date time of end of month.
// In this case March 5, 2017 11:59.999 PM
calendar.months[0].gregorianEndDate

All weeks in a retail calendar are also directly accessible. Each week also has boundaries available in Gregorian calendar.

calendar.weeks // All weeks in calendar.
calendar.weeks[0].gregorianStartDate // Date
calendar.weeks[0].gregorianEndDate // Date

53 week years

Based on given configuration, a year may contain 53 weeks.

Restated

previous versions of this library used the LeapYearStrategy option to configure restated behavior. This is no longer supported. All 53 week calendars are not restated

Dropping Last Week

LAST week of year is "dropped" for 53-week years. This is the default behavior.

// Last week of year has no month.
calendar.weeks[52].weekOfYear // 52
calendar.weeks[52].weekOfMonth // -1
calendar.weeks[52].monthOfYear // -1

// First month starts from 1st week
calendar.months[0].weeks[0].weekOfYear // 0

previous versions of this library returned weekOfYear as -1, this is no longer the case. Last week's weekOfYear is 52

Add Leap Week to Month

If addLeapWeekToMonth is 11,

extra week is "added" to the ELEVENTH month

// AddToPenultimateMonth calendar example for 445 Calendar.
// 11th Month has 5 weeks instead of 4
calendar.months[10].weeks.length //5

previous versions of this library supported leapYearStrategy option value LeapYearStrategy.AddToPenultimateMonth for the same behavior. leapYearStrategy is no longer supported

Options

LastDayOfWeek

Positive integer from 1 (Monday) to 7 (Sunday). Identifies on which day of week the calendar weeks end. Years, months, weeks of the retail calendar always ends on this day of week.

WeekCalculation

Identifies which method to use when calculating end of the retail calendar year.

See 4-4-5 Calendar article for how both of these methods work.

  • WeekCalculation.LastDayNearestEOM: Use the last end of retail week, nearest the end of last Gregorian month in the year.

  • WeekCalculation.LastDayBeforeEOM: Use the last end of retail week, before the end of last Gregorian month in the year.

  • WeekCalculation.LastDayBeforeEomExceptLeapYear: Use the last end of retail week, before the end of last Gregorian month in the year. If next year is leap year (has 53 weeks), make this year leap year by moving end of this year by 1 week forward.

  • WeekCalculation.FirstBOWOfFirstMonth: Use the first, beginning of week day, of the start month as the start day of year.

LastMonthOfYear

Specifies the month the year ends. Plan year is the Gregorian year of the first month.

For example if last month is January and given year is 2017. The last month of retail calendar is January 2018 If last month is December and given year is 2017. The last month of retail calendar is December 2017.

WeekGrouping

Specifies how many weeks each month has in a quarter.

  • WeekGrouping.Group454: 1st month has 4 weeks, 2nd has 5, 3rd has 4. Repeats for each quarter.
  • WeekGrouping.Group544: 1st month has 5 weeks, 2nd has 4, 3rd has 4. Repeats for each quarter.
  • WeekGrouping.Group445: 1st month has 4 weeks, 2nd has 4, 3rd has 5. Repeats for each quarter.

addLeapWeekToMonth

If addLeapWeekToMonth is set to 10, then the penultimate month will not abide this rule, as it will have an extra week. This value is zero-indexed.

leapYear, leapYearEndDate, leapYearFrequency

Overrides how leap years are calculated. Used only if weekCalculation is set to WeekCalculation.CustomLeapYear. If these options are set, given leapYearEndDate will be the end of calendar year of leapYear. Then remaining leap years will be calculated using leapYearFrequency option.

For given { yearEndDate: '2006-03-11', calendarYear: 2006, leapYearFrequency: 6 } customLeapYearOptions, 2006 will be a leap year and the last day of the year will be 2006-03-11. Following leap years will be 2012, 2018, 2024 and so on.

LeapYearStrategy [Removed]

enum

If the year is a leap year (in the context of a retail calendar that means it has 53 weeks)

  • And LeapYearStrategy.Restated is selected, the first week is not included in any month.
  • And LeapYearStrategy.DropLastWeek is selected, the last week is not included in any month.
  • And LeapYearStrategy.AddToPenultimateMonth is selected, the extra week is added to the 11th month

This option has no effect on 52 week years.

restated [Removed]

This option has been superseded by LeapYearStrategy

boolean. If true, in leap years, first week is not included in any month. Otherwise, in leap years, last week is not included in any month.

Has no effect on 52 week years.