New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

nice-time

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nice-time

Lose implementation of Golang's time.format

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

Nice Time

CircleCI

A lose implementation of Golang's Time.format method.

It's (mostly) a single function to format a date after a given string that describes what the format should look like, using a specific date: Mon Jan 2 15:04:05 2006 and pm to describe am/pm.

The library currently does not care for timezones. Sorry. PRs welcome.

Examples

var niceTime = require('nice-time')

var date = new Date('2017-06-21 16:45:57')
date.toString()
'Wed Jun 21 2017 16:45:57 GMT+0200 (CEST)'

// Simple date
niceTime('Mon Jan 2 15:04:05 2006', date)
'Wed Jun 21 16:45:57 2017'

// For the people across the pond
niceTime('Mon Jan 2 3:04pm 2006', date)
'Wed Jun 21 4:45pm 2017'

// Formatting <3
niceTime('On the second day of the month at the fifteenth hour', date)
'On the twentyfirst day of the month at the sixteenth hour'

// You can prepend numbers with 0, _ or nothing for different formats.
niceTime('Hour: "3"', date)
'Hour: "4"'
niceTime('Hour: "03"', date)
'Hour: "04"'
niceTime('Hour: "_3"', date)
'Hour: " 4"'

// You can also add patterns.
niceTime.addPattern({
  pattern: 'MANY SECONDS',
  get: function (d, lang) {
    return d.getTime()
  }
})
niceTime('This is now: MANY SECONDS', date)
This is now: 1498056357000'

Notice that the last example takes a lang argument. The lang argument contains the object defined in lang/en.json, and can be changed at will if you have your own lang file by giving providing it to the format function as a third parameter:

var da = require('./lang/da.json') // because I created my own
niceTime('Minutes: 4th', date, en)
'Minutes: femogfyrrende' // "fourtyfifth" in Danish

Keywords

time

FAQs

Package last updated on 13 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts