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

cronus

v0.5.6

Published

Simple javascript Date manipulation, parsing and printing library.

Downloads

20

Readme

Cronus

Javascript Date manipulation and parsing module.

Simplistic, tiny (~5KB gzip) and rather fast library inspired by moment.js and Carbon (PHP). Can be used both as a node.js module and require.js module.

How to use

define('app', ['cronus'], function(cronus) {

  // Creates new instance of cronus with date set to crrent moment.
  var date = new cronus();

  // Parsing will create new instance with set date and time.
  // In this case 12th of May, 2014 at current time (not at the beginning of the day).
  var dateP = new cronus('2014-05-12 12:05:45');

  // Add one day to the instance turning it into '2014-05-13 12:05:45'.
  dateP.add(1, 'day');

  // Subtract 2 days turning it into '2014-05-11 12:05:45'.
  dateP.sub(2, 'day');
  // OR
  // dateP.sub(2, 'days');
  // OR
  // dateP.sub(2, 'd');

  // Set date to tomorrow - time will be set to the beginning of the day:
  // turning it into '2014-05-12 00:00:00'.
  dateP.tomorrow();
});

Format

Formatting cronus date instance into the human-readable form. You can either use format method without any arguments which will return date in an ISO format or you can specify your own format.


var date = new cronus();
date.format(); // Will return date in an ISO format: '2014-03-12T15:12:22-08:00'.

date.format('{YYYY}-{MM}-{DD}'); // Specify your own format. Will return '2014-03-12'.

List of special symbols convertable with format:

  • S milliseconds
  • SS milliseconds with leading zeroes
  • s seconds
  • ss seconds with leading zero
  • m minutes
  • mm minutes with leading zero
  • h hours in AM/PM format
  • hh hours in AM/PM format with leading zero
  • H hours in 00-23 format
  • HH hours in 00-23 format with leading zero
  • a lower case form of meridiem (AM/PM)
  • A meridiem in upper case format
  • D day of month
  • DD day of month with leading zero
  • DDD day of year,
  • DDDD day of year with leading zero
  • M month - number starting from 1 to 12
  • MM month number with leading zero 01 to 12
  • MMM short name of the month
  • MMMM long name of the month
  • w day of week
  • ww day of week with leading zero
  • www short name of the weekday
  • wwww long name of the weekday
  • W week number in the year from 1 to 52 with locale dependancy
  • WW week number in the year from 01 to 52
  • WWW week number in the year from 1 to 52 without locate dependency
  • WWWW week number in the year with leading zero from 01 to 52 without locate dependency
  • Y short form of the year - 1995 = 95, 2014 = 14
  • YY same as above
  • YYYY full year
  • Z timezone in a format +01:00 or -08:00
  • ZZ timezone in a format +0100 -0800

Using list of symbols above, create formats like:

{D} of {MMMM}, {YYYY}
{DD} {MMMM}, {YYYY} - {HH}:{mm}
{DD} {MMMM}, {YYYY} - {HH}:{mm} {Z}

Default ISO-8601 format for dates looks like that: {YYYY}-{MM}-{DD}T{hh}:{mm}:{ss}{Z}

Formatting symols should always be wrapped in {}. Anything outside will be treated as normal text and won't be formatted.

UTC Mode

Cronus has a very useful feature when working with multiple timezones - UTC mode. When this mode is enabled, current datetime object will be altered to show UTC time without any timezone modifications.

Usually, UTC mode is used whenever you need to return correct datestring with format

// Turn new instance into UTC date.
var date = new cronus().utc();
// OR
var date = cronus.utc();
// OR
var date = cronus.utc('2014-05-13 12:05:45');

// To convert current UTC date to the current local time use `local`
date.local();

Diff

You can calculate difference between two dates in various units.

var date1 = new cronus();
var date2 = new cronus().sub(5, 'days');

// Will return difference in milliseconds.
var diff = date1.diff(date2);

// Get difference in seconds.
var diffS = date1.diff(date2, 'seconds'); // Yuo can also use unit aliases such as 's' or 'second'

// Get difference in hours.
var diffH = date1.diff(date2, 'hours'); // Yuo can also use unit aliases such as 'h' or 'hour'

Besides getting difference in one unit type only, you can ask cronus to return an object containing all differences.

var date1 = new cronus();
var date2 = new cronus().sub(5, 'days');

var diff = date1.diff(date2, 'all');
// That will return following object:
/**
  {
    // Object with rounded absolutely formatted numbers.
    relative: {
      S: 432000000, // Milliseconds
      s: 432000,    // Seconds
      m: 7200,      // Minutes
      h: 120,       // Hours
      d: 5,         // days
      M: 0,         // Months
      y: 0          // Years
    },
    // Strict difference be it posizive or negative numbers.
    strict: {
      S: 432000000,
      s: 432000,
      m: 7200,
      h: 120,
      d: 5,
      M: 0.16666...,
      y: 0.01369...
    }
  }
*/