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

@esmilo/vremya

v1.1.2

Published

Easy-to-use date comparison utility

Downloads

1

Readme

vremya

This package was built with the focus of reducing the complexity to compare dates in JavaScript. When you try to compare dates, like for example:

  • Is the date "September 3rd, 2020" today?

It may sound simple, but it's not. Take a look at this example:

// Let's say your local current date/time is:
// "September 3rd, 2020. 01:23 GMT+7"

// Question: Is the date "September 3rd, 2020" today?
// Expected answer: true

const param = new Date('2020-09-03'); // 2020-09-03T00:00:00.000Z
const currentDate = new Date; // 2020-09-02T18:23:00.000Z

console.log(param.getTime() === currentDate.getTime()); // false
console.log(param === currentDate); // false

All of our statements return false because when you create a new Date it will create a date with your local time converted into GMT0. There's a lot of things you have to handle if you want to just compare the dates.

Like most things javascript, the built-in date processing is extremely powerful, but completely non-intuitive. - Joel Coehoorn, stackoverflow answer

Vremya makes your date comparison easier! You just need to import built-in functions from the package and you're good to go.

Usage

Install Vremya

npm install @esmilo/vremya

Use our built-in functions

// Current date/time: "September 3rd, 2020. 01:23 GMT+7"
const { isDate, getCurrentDate } = require('@esmilo/vremya');

// Get current date
console.log(getCurrentDate()); // '2020-09-03'

// Check if date given is today
console.log(isDate('2020-09-03').today()); // true

console.log(isDate(getCurrentDate()).equal('2020-09-03')); // true
console.log(isDate('2020-08-28').equal('2020-08-28')); // true
console.log(isDate('2020-08-28').after('2020-08-20')); // true
console.log(isDate('2021-08-28').before('2020-08-28')); // false

Note: Write your date as strings with ISO 8601 format (yyyy-mm-dd)

Available Methods

  • getCurrentDate(): String Get current date as ISO 8601 format (yyyy-mm-dd)
  • isDate(date: String): Object Date comparison function, can be chained with:
    • after(dateToCompare: String): Boolean
    • afterOrEqual(dateToCompare: String): Boolean
    • before(dateToCompare: String): Boolean
    • beforeOrEqual(dateToCompare: String): Boolean
    • equal(dateToCompare: String): Boolean
    • today(dateToCompare: String): Boolean