Git Product home page Git Product logo

node-dates's Introduction

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/.

node-dates's People

Contributors

techniv avatar marsportillo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.