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

todate

v0.0.7

Published

Utility object for formatting dates and manipulating date objects in JavaScript.

Downloads

7

Readme

todate.js

todate.js is a utility module which provides methods for manipulating JavaScript date objects.

##Method

Initialize a date object.

  • When the argument is empty, it will return the date object with current system time (for example today is May 9, 2013).

Example:

dateUtils.date().print('yyyy-mm-dd-day');

Result:

2013-4-9-4
  • When the argument is not empty, it will return the data object with the time and format getting from the object. The data can come as any format as you like, as long as the month comes as an English Word(or first three letters) and it uses the same separator. If the format is not specified, the system will set the format to default (yyyy mm dd).

Example:

dateUtils.date({'format': 'mm dd yyyy', 'dateIn': 'May 13, 2013'}).print('');
dateUtils.date({'format': 'mm-yyyy', 'dateIn': 'May-2013'}).print('');
dateUtils.date({'format': 'dd/mm/yyyy', 'dateIn': '13/January/2013'}).print('');
dateUtils.date({'dateIn': '13/jan/2013'}).print('');

Result:

4 13 2013
4-2013
13/0/2013
2013 1 13

If the argument is empty, return the time string based on its original format. If the argument is not empty, return the time string based on the argument as the new format.

Example:

dateUtils.date({'format': 'mm yyyy', 'dateIn': 'December 2012'}).print();
dateUtils.date({'format': 'mm dd yyyy', 'dateIn': 'December 25, 2012'}).print('yyyy/dd/mm');

Result:

11 2012
2012/25/11

Take a integer number and return a string month.

Example:

dateUtils.date().n2m();   //return the month of current system time
dateUtils.date().n2m(7);

Result:

may
aug

Take a month string and return an integer value.

Example:

dateUtils.date().m2n('DEC')

Result:

11

Set the number as the new year of the date object.

Example:

var today = dateUtils.date();
today.setYear(2010).print();

Result:

2010-4-9

Set the number as the new month of the date object.

Example:

today.setMonth(10).print();

Result:

2010-10-9

Set the number as the new day of the date object.

Example:

today.setDate(23).print();

Result:

2010-10-23

Return the year of the date object.

Example:

today.getYear();

Result:

2010

Return the month of the date object.

Example:

today.getMonth();

Result:

10

Return the day of the date object.

Example:

today.getDate();

Result:

23

If the given date is greater than the new date, return true; otherwise return false.

Example:

dateUtils.date({ 'dateIn': 'september 18, 2012'}).gt(dateUtils.date({'dateIn': 'december 19, 2011'}))

Result:

true

If the given date is greater than the new date, return true; otherwise return false.

Example:

t.equal(dateUtils.date({ 'dateIn': 'september 18, 2012'}).lt(dateUtils.date({'dateIn': 'december 19, 2011'}))

Result:

false

If the given date is greater than the new date, return true; otherwise return false.

Example:

dateUtils.date({ 'dateIn': 'september 18, 2012'}).eq(dateUtils.date({'dateIn': 'september 18, 2012'}))

Result:

true

If the given date is greater than or equal to the new date, return true; otherwise return false.

If the given date is lower than or equal to the new date, return true; otherwise return false.

If the given date is in the range between the start date and the end date, return true; otherwise return false.

Example:

dateUtils.date({'dateIn': [2011]}).inRange(dateUtils.date({'dateIn': [2010]}), dateUtils.date({'dateIn': [ 2013 ]}))

Result:

true

##Install

The source code is available for download from GitHub. Besides that, you can also install using Node Package Manager (npm):

npm install dates

##License

MIT