Socket
Book a DemoInstallSign in
Socket

sainsburys-date

Package Overview
Dependencies
Maintainers
6
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sainsburys-date

Basic functions to convert a Date object into Sainsbury's financial calendar components

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
756
-25.66%
Maintainers
6
Weekly downloads
 
Created
Source

Sainsbury's Date

Basic functions to convert a date object or string into Sainsbury's financial calendar components or vice-versa.

Usage

Run npm install sainsburys-date to install the package into your application, then use import (or require) to bring it in.

import sainsburysDate from 'sainsburys-date'

fromDate(date | dateStr)

This converts a Date object or yyyy-mm-dd string into it's Sainsbury's calendar parts.

const date = sainsburysDate.fromDate('2015-10-05')

console.log(date.year) // 2015
console.log(date.quarter) // 3
console.log(date.period) // 8
console.log(date.week) // 2

toDate({ year, quarter, period, week, day })

This calculates the date represented by the passed Sainsbury's calendar parts. Dates are calculated starting from the year option, offset by the quarter, period, week and day optional parts (summated in their respective order).

const a = sainsburysDate.toDate({ year: 2015, period: 8, week: 2 })
const b = sainsburysDate.toDate({ year: 2015, week: 30 })
const c = sainsburysDate.toDate({ year: 2017, day: 15 })
const d = sainsburysDate.toDate({ year: 2017, quarter: 4 })

console.log(a) // new Date('2015-10-04')
console.log(b) // new Date('2015-10-04')
console.log(c) // new Date('2017-03-26')
console.log(d) // new Date('2017-12-17')

Sainsbury's Leap Week / Period?

At some point Sainsbury's will need to introduce a "leap" week or period otherwise the start of the financial year will fall into the previous year!

However, a decision on how to introduce this hasn't been made yet and this won't be a problem until Sun Dec 31 2073 (which will otherwise be the Q1 for 2074)

Keywords

financial

FAQs

Package last updated on 05 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.