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

calcudate

v2.0.0

Published

Light weight general date calculation for JavaScript

Downloads

4

Readme

#Calcudate 2.0

##Usage

npm install calcudate

Sum Years, months, days, hours, minutes or seconds to a date:

let date = require('calcudate');

let someDate = new Date('2015-11-12');
//add ten years
date.add(new Date()).years(10)

//returns date '2015-11-12T00:00:00'
date.add(someDate).months(10)

//return date '2016-10-20T10:10:10.000'
date.add(new Date('2016-10-10T10:10:10.000')).days(10)

//add ten hours
date.add(new Date()).hours(10)

//add ten minutess
date.add(new Date()).minutes(10)

//add ten seconds
date.add(new Date()).secs(10)

Subtract Years, months, days, hours, minutes or seconds of a date:

let date = require('calcudate');

let someDate = new Date('2015-11-12');

//subtract ten years
date.sub(new Date()).years(10)

// returns date '2015-01-12T00:00:00'
date.sub(someDate).months(10)

//return date '2016-10-10T10:10:10.000'
date.sub(new Date('2016-10-10T10:10:10.000')).days(10)

//subtract ten hours
date.sub(new Date()).hours(10)

//subtract ten minutess
date.sub(new Date()).minutes(10)

//subtract ten seconds
date.sub(new Date()).secs(10)

Get start time of day or hour (On local time!)

let date = require('calcudate');
let aDate = new Date('2017-02-20T22:02:36:23.296');
let myDate = getStart(aDate).day;
/*
WARNING - return 2017-02-20T00:00:00:00.000 or
2017-02-20T03:00:00:00.000 depeding local time
*/

Get the last day or date of a month:

let date = require('calcudate');
let lastFebLast = date.getLastOf(new Date('2015-02-01 03:00:00')).day;
//return 28
let lastMar = date.getLastOf(new Date('2016-03-01 03:00:00')).day;
//return 29
let lastApr = date.getLastOf(new Date('2016-04-01 03:00:00')).day;
//return 31

Get the integer timezone offset or the string

let date = require('calcudate');

//return local offset integer like 0 for GMT or 180 for BRT
let offset = date.getOffset().int;

//return local offset integer like +0000 for GMT or -0300 for BRT
let offset = date.getOffset().str;

##Main differences from 1.x.x versions: Added support for browser (calcudate/dist/js/calcudate.js)

<script type="text/javascript" src="../dist/js/calcudate.js"></script>

-Fixed several error on add and sub for years ans months that disconsidered minutes and seconds. -Fixed getOffset() for regions with GMT whithout straight hours offset.(-01:30, +04:45, ...)

  • Added aliases to all add and sub methods, becouse the didi not have veri intuitive names
    • Add secconds
    let myDate = new Date();
    let date = require('calcudate');
    let test = date.add(myDate).s(10);
    let test1 = date.add(myDate).secs(10);
    let test2 = date.add(myDate).seconds(10);
    return +test === +test1 && test === test2;
    //returns true
    Alias that works just like it's relative method, both in add and sub. Here ar all of then: - secs -> s, seconds; - minutes -> m, i, mins; - hours -> h; - days -> d; - months -> M, mo; - years -> y, Y; Other alias that works: - getLastOf.day -> getLastOf.d - getStart.day -> getStart.d - getStart.hour -> getStart.h - getOffset.str -> getOffset.string -> getOffset.s - getOffset.int -> getOffset.integer -> getOffset.i