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

dates

v1.1.0

Published

A date formater with caching system for decoded format string

Downloads

115

Readme

DATES

This is date formatter with caching system for decoded format string for Node.JS

Examples

var dates = require('dates');

// Format a date without cache using a standard format.
console.log(dates.format(dates.standardFormat.ISO8601), new Date());

// Format a date with cache and custom format.
var formatter = dates.createFormatter("The date is: ddd dd MMMM yyyy - hh:mm:ss.sss $a");
console.log(formatter.format(new Date));

// Format a date with a different local (here french).
formatter = dates.createFormatter("La date est : www dd MMMM yyyy - HH:mm:ss.sss", 'fr');
console.log(formatter.format(new Date));

API

  • format( {string} formatString [, {Date} date ] [, {string} local ]) -> {string} - format a date.
  • createFormatter( {string} formatString [, {string} local ]) -> {DateFormatter} - return a date formatter.
  • DateFormatter::format( {Date} date ) -> {string} - format a date.

Patterns

  • dd: The day in the month with 0 before if necessary.

  • ww: The number of the day in the week (from 1 to 7).

  • www: The day in the week in 3 letters (Sun for Sunday).

  • wwww: The day in the week in full letter.

  • MM: The month with 0 before if necessary.

  • MMM: The month in 3 letters (Jan for January).

  • MMMM: The month in full letters.

  • yy: The year on 2 digits (14 for 2014 or 1914).

  • yyyy: The full year.

  • hh: The hour in official 12 hours system (12 for midnight an midday).

  • HH: The hour in 24 hours system (0 for midnight).

  • $a: The day period indicator in lower case (am or pm).

  • $A: The day period indicator in upper case (AM or PM).

  • mm: The minutes.

  • ss: The seconds.

  • sss: The milliseconds.

The standard formats

  • ISO8601: "yyyy-MM-ddThh:mm:ss.sssZ"
  • DATETIME: "yyyy-MM-dd hh:mm:ss"

How work the cache

When you create a formatter the format string is read to extract the format process and compile it in an array.

The compiler search two type of element:

  • date symbols: referenced previously
  • user string: string not recognized

The user string is store as it in the array and the date symbols are converted in formatting functions what referenced in dictionary.js.

When you call the method format, the array is read to concatenate the user string and the result of formatting functions.

Your original format string is never read again as long you keep the same formatter object.

Internationalization

You can change the local of the name of the days and mouths with the local parameter. The available locals are stored at ./libs/i18n/.