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

@web-atoms/date-time

v1.1.1

Published

DateTime library for Web Atoms

Downloads

282

Readme

Action Status npm version

@web-atoms/date-time

Immutable DateTime library for Web Atoms in JavaScript similar to .Net DateTime and TimeSpan

Features

  1. Immutable DateTime
  2. Support for TimeSpan (differences between dates)
  3. Simple Add/Difference
  4. Support for properties
  5. Support for Comparison
  6. Support for valueOf which makes it easier to compare and sort dates
  7. Backward compatibility with JavaScript's Date

Compatibility

In order to make usage simple, you can pass DateTime to any method that uses Date and everything will still work. To prevent intellisense from listing all Date's methods, we have used a hack to create new Date object in constructor of DateTime.

For easy access, all to*String methods of Date are available in intellisense.

   const d = DateTime.now();
   console.log(d instance of Date); // prints true..

   // however intellisense does not
   // show up for Date methods except for toLocaleDateString etc
   d.year

Usage

Properties

Year, Month, Day, Hour, Minute, Second and Millisecond are all properties.

   const d = DateTime.now();

   console.log(`${d.year}-${d.month}-${d.day}`);

Trim Time

   const d = DateTime.now();

   // returns new instance of DateTime
   // with time part trimmed...
   const day = d.date;

Comparison

   const d1 = new DateTime(2010, 1, 1, 20, 50);
   const d2 = new DateTime(2010, 2, 1, 20, 50);
   const dt1 = new Date(d1.msSinceEpoch);
   const dt2 = new Date(d1.msSinceEpoch);
   // DateTime comparison works correctly
   Assert.isTrue(d1 < d2);
   // Date comparison does not work as expected
   Assert.isFalse(dt1 < dt2);

TimeSpan

   const d = DateTime.now();

   const t = d.time;

   console.log(t); // prints 10.00 PM (local time)

Difference in TimeSpan


   const d1 = new DateTime(2010, 1, 1);
   const d2 = new DateTime(2012, 1, 1);

   // returns TimeSpan
   const diff = d2.diff(d1);

   // prints 730
   console.log(diff.totalDays);

Add TimeSpan

   
   const t = TimeSpan.fromDays(2);
   const d1 = new DateTime(2010, 1, 1);

   const d2 = d1.add(t);

   // prints 2010-01-03
   console.log(d2);