Socket
Book a DemoInstallSign in
Socket

human-pretty-date

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

human-pretty-date

Format dates for humans

latest
Source
npmnpm
Version
1.0.8
Version published
Weekly downloads
107
22.99%
Maintainers
1
Weekly downloads
 
Created
Source

-----------------------------------------------------

➤ Human Pretty Date

human-pretty-date is a Javascript library that helps you collect common and not-so-common informations about your application user.

-----------------------------------------------------

➤ Installation

Use the package manager npm to install human-pretty-date.

npm i human-pretty-date --save

-----------------------------------------------------

➤ Usage

If you are using human-pretty-date with Typescript, you can import the package with the import sintax

import * as humanPrettyDate from 'human-pretty-date';

The usage will be like this:

console.log(formatDate(new Date(new Date() - -2 * 365 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -365 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -2 * 30 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -30 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -2 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -2 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -2 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - -60 * 1000)));
console.log(formatDate(new Date(new Date() - -2 * 1000)));
console.log(formatDate(new Date(new Date() - -1 * 1000)));
console.log(formatDate(new Date()));
console.log(formatDate(new Date(new Date() - 1 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 1000)));
console.log(formatDate(new Date(new Date() - 60 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 30 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 30 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 365 * 24 * 60 * 60 * 1000)));
console.log(formatDate(new Date(new Date() - 2 * 365 * 24 * 60 * 60 * 1000)));

This is the complete output:

2 years from now
1 year from now
2 month from now
1 months from now
2 day from now
tomorrow
2 hours from now
1 hour from now
2 minutes from now
1 minute from now
2 seconds from now
1 second from now
just now
1 second ago
2 seconds ago
1 minute ago
2 minutes ago
1 hour ago
2 hours ago
yesterday
2 day ago
1 months ago
2 month ago
1 year ago
2 years ago

-----------------------------------------------------

➤ i18n

To use the i18n provided by the package, you just need to past the desired locale in the config object:

console.log(formatDate(new Date(), { locale: 'pt_BR' })); // agora

Supported locales

CodeLocale
enEnglish
pt_BRPortuguese (Brazil)

-----------------------------------------------------

➤ Contributors

Caio Rolla
Caio Rolla
Linkedin Badge Twitter Badge Profile Views
You don't need state management if you use global variables. :bug:

-----------------------------------------------------

➤ Contributing

Pull requests are welcome, specially for new locales. For major changes, please open an issue first to discuss what you would like to change.

-----------------------------------------------------

➤ License

MIT

This package is based on node-prettydate

Keywords

date

FAQs

Package last updated on 18 Sep 2020

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