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

nice-time

v1.0.1

Published

Lose implementation of Golang's time.format

Downloads

61

Readme

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