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

simplydate

v1.0.8

Published

Simple date-time manipulation.

Downloads

5

Readme

SimplyDate

This is a basic functional, non-mutating date-time manipulation library implemented in Typescript. It supports time zones and is suitable for simple and basic date formatting and manipulation. Please note that this library is a personal project and is not ready for production use. Use it at your own risk.

Installation:

NPM

npm install --save simplydate

Yarn

yarn add simplydate

Usage Examples:

import {Simply} from "simplydate"

Type definition

type SimplyDate = {
  year: number;
  month: number;
  day: number;
  hour: number;
  minute: number;
  second: number;
  millisecond: number;
};

Ways to initialize:

const simpleDate = Simply.from.date(new Date(`2015-02-29T03:24:00`));
const simpleDateFromMs = Simply.from.msSinceEpoch(1515035460000);
const simpleDateFromString = Simply.from.string("12-25-1995", "MM-DD-YYYY");
const nowDate = Simply.now();

Accessing properties:

console.log(nowDate.day);
console.log(simpleDate.month);

Addition:

const newSimpleDate1 = Simply.add(2).days.to(simpleDate);
const newSimpleDate2 = Simply.add(12).months.to(newSimpleDate1);

Subtraction:

const newSimpleDate1 = Simply.subtract(10).seconds.from(simpleDate);
const newSimpleDate2 = Simply.subtract(12).months.from(simpleDate);

Output to string

const simpleDate = Simply.from.date(new Date(`2017-03-01T03:24:00`));
Simply.format(simpleDate).as("YYYY-MM-DDTHH:mm:ss") === "2017-03-01T03:24:00";
Simply.format(simpleDate).as("YYYY-MM-DD") === "2017-03-01";

With timezones see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat

const options = {
                weekday: "long",
                year: "numeric",
                month: "long",
                day: "numeric",
            };
Simply.format(sDt).as({ locale: "de-DE", options })) === "Mittwoch, 29. März 2017"

The following date formats are supported:

// ISO 8601 format with milliseconds
'YYYY-MM-DDTHH:mm:ss.SSS' => '2017-03-01T03:24:00.000'
// ISO 8601 format without milliseconds
'YYYY-MM-DDTHH:mm:ss' => '2017-03-01T03:24:00'
// ISO 8601 with minutes only
'YYYY-MM-DDTHH:mm' => '2017-03-01T03:24'

// Date-only formats
'YYYY-MM-DD' => '2017-03-01'
'MM/DD/YYYY' => '03/01/2017'
'DD/MM/YYYY' => '01/03/2017'
'MMMM DD, YYYY' => 'March 01, 2017'
'MMM DD, YYYY' => 'Mar 01, 2017'

// Time-only formats
'HH:mm' => '03:24'
'HH:mm:ss' => '13:24:00'
'hh:mm A' => '3:24 PM'
'hh:mm:ss.SSS A' => '01:24:45.123 PM'

// Custom Date-Time with AM/PM
'YY MMM DD h:mm A' => '17 Mar 29 3:24 AM'
'MMMM Do, YYYY [at] h:mm A' => 'March 29th, 2017 at 3:24 AM'

// Date and Time combined
'MM/DD/YYYY HH:mm' => '03/01/2017 03:24'
'DD/MM/YYYY HH:mm:ss' => '01/03/2017 13:24:00'

// Week and Day-of-Year formats
'DDD YYYY' => '88 2017' // Day of year

// 12-hour with optional AM/PM
'hh:mm A' => '3:24 AM'

// Full Date with day of the week
'dddd, MMMM Do YYYY' => 'Wednesday, March 29th 2017'

// ISO 8601 UTC format
'YYYY-MM-DDTHH:mm:ss.SSSZ' => '2017-03-29T13:24:45.123Z'

Get milliseconds since Unix Epoch till now.

Simply.to.msSinceEpoch(Simply.now());