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

universal-date-format

v1.0.0

Published

Easy way to display dates using a common human languaje

Downloads

141

Readme

Universal Date Format

The Universal Date Format is a library that aims to provide an easy way to format the date to make it easier for human users to understand.

Prerequisites

use node 16.9.0 or lastest

Developer Setup

 npm i universal-date-format

Quickstart

  import UniversalDateFormat from 'universal-date-format'

  const dateFormater = new UniversalDateFormat(new Date(2020, 0, 15))

  dateFormater.getDateFormat()

getDateFormat return Date as format YYYYMMDD.

  2020/1/15

Usage

Universal Date Format can be created using 2 way, you can give a Date or String.

new UniversalDateFormat(new Date(2020, 0, 15))
new UniversalDateFormat(new Date('2020-01-15T00:00:00.000Z'))

Create instance using a own configuration All elements into the configuration are optional, if you want change the config, you may change it using the public functions of the class.

  new UniversalDateFormat(
    new Date(2020, 0, 15),
    {
      defaultFormat: 'MMDDYYYY',
      div: '/',
      useMeridianFormat: true,
      useMonthName: true,
      days: [
        'Sun', 'Mon', 'Tue',
        'Wed', 'Thu', 'Fri',
        'Sat'
      ],
      months: [
        'Jan', 'Feb', 'Mar',
        'Apr', 'May', 'Jun',
        'Jul', 'Aug', 'Sep',
        'Oct', 'Nov', 'Dec'
      ]
    }
  )

Set MMDDYYYY as default

  dateFormater.setMMDDYYYYAsDefault()
  // 1/15/2020

Set DDMMYYYY as default

  dateFormater.setDDMMYYYYAsDefault()
  // 15/1/2020

Set YYYYMMDD as default

  dateFormater.setYYYYMMDDAsDefault()
  // 2020/1/15

Change mounths using names

  dateFormater.useMonthName()
  // 2020/January/15

Change months using number of month

  dateFormater.useMonthNumber()
  // 2020/1/15

Change mounths name

  dateFormater.modifyMonthsName(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'])
  dateFormater.useMonthNumber()
  // 2020/Jan/15

Get day of month

  dateFormater.getDayName()
  // Wednesday

Change mounths name

  dateFormater.modifyDaysName(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
  dateFormater.getDayName()
  // Wed

Change divisions Universal Date Format have to way to change de division of date, modifyDiv recive a String or an array of two Strings, and the second paramether is a boolean if you want use spaces between of the division.

  dateFormater.modifyDiv('-')
  // 2020-1-15

the array is used for other idioms like the spanish.

  dateFormater.setDDMMYYYYAsDefault()
  dateFormater.modifyMonthsName(['Ene.','Feb.','Mar.','Abr.','May.','Jun.','Jul.','Ago.','Sep.','Oct.','Nov.','Dec.'])
  dateFormater.modifyDiv(['de', 'del'], true)
  // 15 de Ene. del 2020

Get hour

  dateFormater.getHourFormat()
  // 17:08

To receive the the seconds you can send a boolean when you call getHourFormat().

  dateFormater.getHourFormat(true)
  // 17:08:58

Get hour as meridian format

  dateFormater.useMeridianFormat()
  dateFormater.getHourFormat()
  // 05:08 PM

Execute a own function

  const ownFunction = (dateFormater: DateFormater): string => {
    dateFormater.useMeridianFormat()
    const hours = dateFormater.getHourFormat()
    const date = dateFormater.getDateFormat()

    return `${hours} ${date}`
  }

  dateFormater.execute(ownFunction)
  // 05:08 PM 2020/1/15

Examples

React: card-users-udf-react-example