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

@theredhead/dateformat

v0.0.3

Published

Date formatting like the PHP kids

Downloads

2

Readme

@theredhead/dateformat

Purpose

Make working with the built-in Date class a little bit more tolerable.

Features

  • Source code freely available: https://github.com/theredhead/dateformat
  • Provides a dateFormat(date: Date, formatString: string): string function that takes a format just like PHP's date_format function.
  • Format string placeholders:

This is almost straight from the php documentation | Char | Description | |--|--| | d | Day of the month, 2 digits with leading zeros | D | A textual representation of a day, three letters | j | Day of the month without leading zeros | l | A full textual representation of the day of the week | N | ISO-8601 numeric representation of the day of the week | S | English ordinal suffix for the day of the month, 2 characters | w | Numeric representation of the day of the week | z | The day of the year (starting from 0) | W | ISO-8601 week number of year, weeks starting on Monday | F | A full textual representation of a month, such as January or March | m | Numeric representation of a month, with leading zeros | M | A short textual representation of a month, three letters | n | Numeric representation of a month, without leading zeros | t | Number of days in the given month | L | Whether it's a leap year | o | ISO-8601 week-numbering year. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead | Y | A full numeric representation of a year, 4 digits | y | A two digit representation of a year | a | Lowercase Ante meridiem and Post meridiem | A | Uppercase Ante meridiem and Post meridiem | B | Swatch Internet time | g | 12-hour format of an hour without leading zeros | G | 24-hour format of an hour without leading zeros | h | 12-hour format of an hour with leading zeros | H | 24-hour format of an hour with leading zeros | i | Minutes with leading zeros | s | Seconds with leading zeros | u | Microseconds | v | Milliseconds | O | Difference to Greenwich time (GMT) without colon between hours and minutes | P | Difference to Greenwich time (GMT) with colon between hours and minutes | p | The same as P, but returns Z instead of +00:00 | Z | Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. | c | ISO 8601 date | r | RFC 2822 formatted date ("Thu, 21 Dec 2000 16:01:07 +0200") | U | Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

Caveats

My implementation is almost, but not quite entirely, complete. I am still missing a few options that I don't really want to support as it would involve tracking a bunch of data:

| Char | Description | note | |--|--|--| | e | Timezone identifier | NOT IMPLEMENTED | I | Whether or not the date is in daylight saving time | NOT IMPLEMENTED | T | Timezone abbreviation | NOT IMPLEMENTED

Furthermore, the unittests are fairly basic (as of 2021-03-13)

Usage

There are several ways you could use this package:

the dateFormat function

If all you need is a quick formatting of a date here and there, you could get away with just importing the dateFormat funtion and forgetting about everything else.

The function expects two arguments; a Date instance and a string witht he required formatting characters as described above.

  import { dateFormat } from '@theredhead/dateformat';

  const date = new Date();
  console.log("It is " + dateFormat(date, "H:i:s")); // It is 18:43:51

The dateHelper instance

If you might need to do some more Date inspection, you may want to use the same dateHelper instance that the exported function uses

  import { dateHelper } from '@theredhead/dateformat';

  function schedule(dueDate, task) {
    if (! dateHelper.isDate(dueDate)) {
      throw new Error('Expected a Date.');
    }
    // ...
  }
  console.log("It is " + dateFormat(date, "H:i:s")); // It is 18:43:51

the DateHelper class

If you just want to break stuff, import the DateHelper class. Maybe extend it or bend it to your will in some novel way I haven't thought of yet.