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

shado

v1.5.0

Published

This is a JavaScript Date Comparison Open Source Library to provide precise date and time comparison calculations between two dates for Years, Months, Days, Weeks, Hours, Minutes and Seconds. The aim of this library is to assist JavaScript Developers in t

Downloads

62

Readme

shado.js

This is a JavaScript library to provide precise date and time comparison calculations between two dates for Years, Months, Days, Weeks, Hours, Minutes and Seconds. The aim of this library is to assist JavaScript Developers in taking away the pain of date handling in JavaScript.

Installation

Latest stable version:

npm install shado --save

Instructions on how to use

  1. The set Method (previously named setDates)

    The method takes three parameters for start date and end date with an optional boolean true indicating requirement to use US date format. The default is the UK date format. Both date parameters can be a string or JavaScript Date Object. If using Date Objects the optional boolean parameter is not relevant, because system settings take over the date formatting. The call to the set method does not require the use of the "new" key word to instantiate the object. The namespace pattern is used exposing the methods required. If either parameter is not a string and date type, an exception will be raised with the error message of 'Parameters expected should be of type string or date'. Also if the end date is passed into the start date parameter with the start date as the end data parameter, an error exception is raised with the error message of 'The end date cannot be before the start date'.

    The set method returns the methods through the use of dot notation (method chaining) in one line of code as described in section 3. Functionality remains in place allowing calls to the calculation methods to be made separately as described in section 4.

    Supported Date/Time Formats

    The set method supports the inclusion of the time segment with the date. The ISO-8601 standard is implemented alongside two other formats for both start and end date parameters. An exception is raised with the error message of 'Invalid date/time pattern provided' if a date or time is provided in a different format that is not supported.

    1999-06-10T14:50:25:545Z - IS0-8601 Standard
    01/06/1967 03:34:25:233  - Date with time segment
    29-02-2012               - Date only

    With exception of the IS0-8601 standard, both hyden and forward lash can both be applied as separators

    Example UK Date Format using string parameters:

    var shado = require("shado");
    
    var startDate = "01-01-1970";
    var endDate = "01/01/1986";
    var result = shado.date.set(startDate, endDate).getDays(false);

    Example ISO-8601 Format using string parameters:

    var shado = require("shado");
    
    var startDate = "1999-06-10T14:50:25:545Z";
    var endDate = "2019-04-11T16:34:28:019Z";
    var result = shado.date.set(startDate, endDate).getDays(false);

    Example UK Date/Time Format using string parameters:

    var shado = require("shado");
    
    var startDate = "01-01-1970 03:34:25:233";
    var endDate = "01/01/1986 15:55:45:239";
    var result = shado.date.set(startDate, endDate).getMinutes();

    Example US Date Format using string parameters:

    var shado = require("shado");
    
    var startDate = "02/01/1970";
    var endDate = "10/01/1986";
    var result = shado.date.set(startDate, endDate, true).getDays(true);

    Example of Date Object parameters:

    var shado = require("shado");
    
    var startDate = new Date(2000, 0, 1);
    var endDate = new Date(2014, 3, 22);
    var result = shado.date.set(startDate, endDate).getWeeks();

    Example of mixed types of string and instantiated date object:

    var shado = require("shado");
    
    var startDate = "01/01/1970";
    var endDate = new Date(2014, 3, 27);
    var result = shado.date.set(startDate, endDate).getYears();
  2. The setParams Method (previously named setDatesByUnits)

    This method allows individual date units of Day, Month, Year, Hour, Minute and Seconds to be passed in as separate parameters, providing additional option as to date input. The parameter type can be a number or string. The string numbers can have an optional 0 prefix on them, for example '01'. As with the set method, the setParams method does not require the use of the "new" key word to instantiate the object. If the parameters are not a number and string type, an exception will be raised with the error message of 'Parameters expected should be of type string or date'. Also if the end date is passed into the start date parameter with the start date as the end data parameter, an error exception is raised with the error message of 'The end date cannot be before the start date'.

    The setParams method returns the methods through the use of dot notation (method chaining) in one line of code as seen in the example below calling getYears(). Functionality remains in place allowing calls to the calculation methods to be made separately as described in section 4.

    Example of the setParams method:

    var shado = require("shado");
    
    var startDay = 31;
    var startMonth = 12;
    var startYear = 1899;
    var startHour = 11;
    var startMinute = 5;
    var startSeconds = 10;
    var endDay = 31;
    var endMonth = 12;
    var endYear = 2150;
    var endHour = 11;
    var endMinute = 59;
    var endSeconds = 59;
    var result = shado.date.setParams(startDay, startMonth, startYear, startHour, startMinute, startSeconds, endDay, endMonth, endYear, endHour, endMinute, endSeconds).getYears();
  3. Calling either the set or setParams method. Developers can call methods for Years, Months, Weeks, Days, Hours, Minutes and Seconds to return the calculated difference using dot notation.

    Example:

    var shado = require("shado");
    
    var startDate = new Date(2000, 0, 1);
    var endDate = new Date(2014, 3, 22);
    var years = shado.date.set(startDate, endDate).getYears();
    var months = shado.date.set(startDate, endDate).getMonths();
    var weeks = shado.date.set(startDate, endDate).getWeeks();
    var days = shado.data.set(startDate, endDate).getDays(false);
    var hours = shado.date.set(startDate, endDate).getHours(false);
    var minutes = shado.date.set(startDate, endDate).getMinutes(false);
    var seconds = shado.date.set(startDate, endDate).getSeconds(false);
  4. For calculating Days, Hours, Minutes and Seconds there is one boolean parameter required for the inclusion of the last day in the calculated result. Therefore, true = include last day, false = exclude last day (or not provided). This is not optional for the use of true. This example shows the calculation methods called separately. If using the boolean parameter set to true with a time segment, including last day is adding on 1 day.

    Example:

    var shado = require("shado");
    shado.date.set("1999-06-10T14:50:25:545Z", "2019-04-11T16:34:28:019Z");
    
    var days = shado.date.getDays(false); //exclude last day.
    var days = shado.date.getDays(true);  //include last day.
    
    var hours = shado.date.getHours(false); //exclude last day.
    var hours = shado.date.getHours(true);  //include last day.
    
    var minutes = shado.date.getMinutes(false); //exclude last day.
    var minutes = shado.date.getMinutes(true)); //include last day.
    
    var seconds = shado.date.getSeconds(false); //exclude last day.
    var seconds = shado.date.getSeconds(true);  //include last day.

Date Formatting

  1. The format method

    The method requires 3 parameters. The first is the date either has a string or date object. The second is the format pattern used to transform the date into the desired result. The third paramter is a boolean indicating whether the date parameter is in US format (true) or UK format (false or not provided). The date parameter as a string supports both hydens - and forward lash / as separators.

    Example:

    var shado = require("shado");
    
    var result = shado.date.format("02-09-2018 06:15:34:126", "DDDD OI MMMM, yyyy - HH:mm:SS:sss");

    The date must be provided in US format for the format method to create the result correctly with the third parameter set to true.

    Example US Date Format:

    var shado = require("shado");
    
    var result = shado.date.format("09/02/2018", "DDDD OI MMMM, yyyy - HH:mm:SS:sss", true);

    If using Date Objects the optional boolean parameter is not relevant. The Date Object uses system settngs.

    Example using Date Object:

    var shado = require("shado");
    
    var result = shado.date.format(new Date(2018, 8, 2, 6, 15, 34, 126), "DDDD OI MMMM, yyyy - HH:mm:SS:sss");

    The result: Sunday 2nd September, 2018 - 06:15:34:126

    Example using IS0-8601 Standard:

    var shado = require("shado");
    
    var result = shado.date.format("1999-06-10T14:50:25:545Z", "DDDD OI MMMM yyyy, HH:mm:SS:sss");

    The result: Thursday 10th June 1999, 14:50:25:545

  2. Supported formats

    M: Month number (1, 2, 3... 12)
    MM: Month number with leading zero (01, 02, 03... 12)
    MMM: Month abbreviation (Jan, Feb, Mar... Dec)
    MMMM: Month name (January, February, March... December)
    
    yyyy: Year number 1990, 2018, 2000
    yy: 90, 18, 00
    
    dd: 01..09, 10..20, 21..31
    d: 1..9, 10...20, 21..31
    OI: Day number with ordinal indicator (1st, 2nd, 3rd... 12th)
    DDD: Mon, Tues...Sun
    DDDD: Monday, Tuesday...Sunday
    
    HH: Hour number with leading zero (01, 02, 03.... 15,16... 23)
    h: Hour without leading zero (1,2,3.....9,15,16... 23)
    mm: Minute number with leading zero (01, 02, 03... 20,45... 59)
    SS: Second number with leading zero (01, 02, 03... 20,45... 59)
    sss: Milisecond number with two leading zeros (001,002....009,010,011... 999)
    
    Supports Hydens -, forward lash / as separators, commas and blank spaces.

Included with the library is the tests folder containing the js files developed to test drive the design of the shado.js code. The tests can be viewed in the git repository. The Mocha Test Runner from npmjs.org is used to unit test each method.

Feedback:

I am open to receiving feedback from developers that use this library and welcome pull requests that I will review and if accepted. Those persons will be acknowledged for their contribution.

I want to contribute to the open source community. My email address is: [email protected]

Node Version:

From shado.js v1.5.0 onwards is it only supported run on Node.js version 10.0.0 or later.