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

amazon-date-parser

v0.3.0

Published

Parse AMAZON.DATE to a date range

Downloads

2,843

Readme

Amazon Date parser

Software License Build Status

Given an AMAZON.DATE returns an object with the relative start and end date.

Installation

npm install amazon-date-parser

Basic usage

var AmazonDateParser = require('amazon-date-parser');

var date = new AmazonDateParser('2017-01-31');

/*
returns:
{
    startDate: Tue Jan 31 2017 00:00:00 GMT+0000 (GMT),
    endDate: Tue Jan 31 2017 23:59:59 GMT+0000 (GMT)
}
*/

It throws an error when the date is not valid or not supported.

var AmazonDateParser = require('amazon-date-parser');

try {
    var date = new AmazonDateParser('dummy');    
}catch(e) {
    console.log(e.message);
}

// Error: Invalid constructor parameter or parameter not supported.

Input values:

  • right now: PRESENT_REF
  • single day: 2017-11-24
  • week: 2017-W48
  • weekend: 2017-W48-WE
  • month: 2017-11 and 2019-11-XX
  • quarter: 2018-Q2
  • seasons: 2017-SP, 2017-WI, 2017-FA, 2017-SU (see below)
  • year: 2018 and 2020-XX
  • decade: 201X

Seasons

The constructor receives the following optional parameters only valid for season's calculations.

{
    hemisphere: 'N',    //`N` for North, `S` for the South hemisphere (default is `N`)
    seasons: { // see Custom seasons for more info about this parameter
        // ...
        'SU': { // summer
            startDate: [5, 1],  // 1st of June
            endDate: [8, 0]     // 31st of August
        }
        // ...
    }
}

The seasons parameters overrides all the others. For instance, if you provide seasons and hemisphere the latter will be ignored.

Default seasons

The north hemisphere seasons are by default defined as follow:

  • Spring, from the 1st of March to the 31st of May
  • Summer, from the 1st of June to the 31st of August
  • Fall/Autumn, from the 1st of September to the 30th of November
  • Winter, from the 1st of December to the end of February (28th or 29th depending on leap year)

For the south hemisphere you should construct the Amazon date parser as follow:
var date = new AmazonDateParser({hemisphere: 'S'});
and you can get:

  • Spring, from the 1st of September to the 30th of November
  • Summer, from the 1st of December to the end of February (28th or 29th depending on leap year)
  • Fall/Autumn, from the 1st of March to the 31st of May
  • Winter, from the 1st of June to the 31st of August

Custom seasons

You can pass your own seasons representation using the following configurations:

var options = {
    seasons: {
        'SP': {
            startDate: [2, 1],  // 1st of March
            endDate: [3, 0]     // end of March
        },
        'SU': {
            startDate: [5, 1],  // 1st of June
            endDate: [8, 0]     // end of August
        },
        'FA': {
            startDate: [8, 1],  // 1st of September
            endDate: [11, 0]    // end of November
        },
        'WI': {
            startDate: [11, 1], // 1st of December
            endDate: [2, 0]     // end of February (28th or 29th)
        }
}
var AmazonDateParser = require('amazon-date-parser');

var date = new AmazonDateParser('2018-SP', options);
/*
returns something like:
{
    startDate: Thu Mar 01 2018 00:00:00 GMT+0000 (GMT),
    endDate: Sat Mar 31 2018 23:59:59 GMT+0000 (GMT)
}
*/

Credits

License

The MIT License (MIT). Please see License File for more information.