This package has been deprecated

Author message:

Renamed to retail-calendar

merchandise-calendar
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Merchandise Calendar

A configurable merchandising and retail calendar generator. For a given year and configuration, generates merchandising calendar along with Gregorian boundaries.

Installation

Using npm:

 $ npm i --save merchandise-calendar

Usage:

Instantiate MerchandiseCalendarFactory with preferred options.

const {
  WeekCalculation,
  WeekGrouping,
  LastDayOfWeek,
  LastMonthOfYear,
  MerchandiseCalendarFactory,
} = require('merchandise-calendar')

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

A retail calendar either has 52 or 52 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

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 merchandise 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 52 weeks. This complicates comparing months to previous year. This case is handled specially based on given restated option. Number

If restated is true

FIRST week of year is "dropped". It doesn't belong the any month.

// Restated calendar example.
// First week of year has no month.
calendar.numberOfWeeks // 53
calendar.weeks[0].weekOfYear // 0
calendar.weeks[0].weekOfMonth // -1
calendar.weeks[0].monthOfYear // -1

// First month starts from 2nd week

calendar.months[0].weeks[0].weekOfYear // 1

If restated is false

LAST week of year is "dropped".

// Restated calendar example.
// First week of year has no month.
calendar.weeks[52].weekOfYear // 0
calendar.weeks[52].weekOfMonth // -1
calendar.weeks[52].monthOfYear // -1

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

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 merchandise calendar year.

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

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

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

LastMonthOfYear

Specifies the month the year ends. An integer from 0 (January), to 11 (December). Currently last month of retail year is always assumed to be in next calendar year.

For example if last month is January and given year is 2017. The last month of merchandise calendar is January 201 8

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.

restated

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 not effect on 52 week years.

Package Sidebar

Install

npm i merchandise-calendar

Weekly Downloads

2

Version

1.1.0

License

ISC

Unpacked Size

21.3 kB

Total Files

16

Last publish

Collaborators

  • cihantoolio