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

dayjs-ext

v2.2.0

Published

2KB immutable date time library alternative to Moment.js with the same modern API

Downloads

28,793

Readme

Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API. If you use Moment.js, you already know how to use Day.js.

dayjs().startOf('month').add(1, 'day').set('year', 2018).format('YYYY-MM-DD HH:mm:ss');
  • 🕒 Familiar Moment.js API & patterns
  • 💪 Immutable
  • 🔥 Chainable
  • 🌐 I18n support
  • 📦 2kb mini library
  • 👫 All browsers supported

Extensions to the original project

  • New plugin "customParseFormat" to parse input strings using custom formats.
  • New plugin "localizableFormat" to format dates according to the chosen locale.
  • New plugin "timeZone" to parse from and format to a date string using a time zone specified by its canonical name.
  • Corrected plugin "relativeTime" honouring grammar rules of the supported languages.
  • "UTC mode" for working in UTC, or for working with date-only values without the time part.
  • Additional locales (cs, ru, sk, uk).
  • Check for dayjs instance by the instanceof operator.

Synopsis

Day.js is usually imported via a "proxy module", which loads required plugins and registers required language packs. For example, via the following dayjs-local.js:

// Load dayjs, plugins and language packs.
import dayjs from 'dayjs-ext'
// import "timeZone-1900-2050", "timeZone-1970-2038"
// or "timeZone-2012-2022" to save your package size
import timeZonePlugin from 'dayjs-ext/plugin/timeZone'
import customParseFormat from 'dayjs-ext/plugin/customParseFormat'
import localizableFormat from 'dayjs-ext/plugin/localizableFormat'
import relativeTime from 'dayjs-ext/plugin/relativeTime'
import 'dayjs-ext/locale/cs'
import 'dayjs-ext/locale/sk'

// Register plugins and language packs; Czech will be the default language.
dayjs.extend(timeZonePlugin)
     .extend(customParseFormat)
     .extend(localizableFormat)
     .extend(relativeTime)
     .locale('cs')

export default dayjs

Typical usage scenarios:

import dayjs from './dayjs-local'

// Load a date+time from a storage and show it to the user.
const dateTime = dayjs('2018-10-28T18:45:00.000Z')
console.log(dateTime.format({ format: 'L LT', timeZone: 'Europe/Prague' }))
// Prints "28.10.2018 19:45".
console.log(dateTime.fromNow())
// Prints "před 5 hodinami" (5 hours ago).

// Read a date+time from the user and format it for the storage.
const dateTime = dayjs('28.10.2018 19:45', { format: 'L LT', timeZone: 'Europe/Prague' })
console.log(dateTime.toISOString())
// Prints "2018-10-28T18:45:00.000Z".

// Set only the date; zero the time and prevent local time zone conversion.
const dateOnly = dayjs('2018-10-28', { utc: true })
console.log(dateOnly.format({ format: 'YYYY-MM-DD' }))
// Prints "2018-10-28" anytime and anywhere.

If used in the browser, the following scripts would be needed:

<-- include "index-1900-2050", "index-1970-2038"
    or "index-2012-2022" to save your package size -->
<script arc="https://unpkg.com/timezone-support/dist/index.umd.js"></script>
<script arc="https://unpkg.com/fast-plural-rules/dist/index.umd.js"></script>
<script arc="https://unpkg.com/dayjs-ext/dayjs.min.js"></script>
<script arc="https://unpkg.com/dayjs-ext/plugin/timeZone.js"></script>
<script arc="https://unpkg.com/dayjs-ext/plugin/customParseFormat.js"></script>
<script arc="https://unpkg.com/dayjs-ext/plugin/localizableFormat.js"></script>
<script arc="https://unpkg.com/dayjs-ext/plugin/relativeTime.js"></script>

Getting Started

Installation

npm install dayjs-ext --save

📚Installation Guide

API

It's easy to use Day.js APIs to parse, validate, manipulate, and display dates and times.

dayjs('2018-08-08') // parse

dayjs().format('{YYYY} MM-DDTHH:mm:ss SSS [Z] A') // display

dayjs().set('month', 3).month() // get & set

dayjs().add(1, 'year') // manipulate

dayjs().isBefore(dayjs()) // query

📚API Reference

I18n

Day.js has great support for internationalization.

But none of them will be included in your build unless you use it.

import 'dayjs-ext/locale/es' // load on demand

dayjs.locale('es') // use Spanish locale globally

dayjs('2018-05-05').locale('zh-cn').format() // use Chinese Simplified locale in a specific instance

📚Internationalization

Plugin

A plugin is an independent module that can be added to Day.js to extend functionality or add new features.

import timeZone from 'dayjs-ext/plugin/timeZone' // load on demand

dayjs.extend(timeZone) // use plugin

dayjs().format('D.M.YYYY H:mm',
  { timeZone: 'Europe/Berlin' }) // convert to CET before formatting

📚Plugin List

Sponsors

See the sponsor list at the original project. Thank you for your support!

Contributors

See the contributor list at the original project. Thank you for your help!

License

Day.js is Extended licensed under a MIT License.