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

sundial-js

v0.1.1

Published

compare dates in a not-too-painful way

Downloads

3

Readme

Sundial.js npm npm npm

compare dates in a not-too-painful way

v0.1.x has been released with major algorithmic changes to ensure accuracy of sundail Dates. If you are on v0.0.x, please upgrade now.

Most of the time when comparing dates, you don't need to think in units as small as milliseconds.

Oftentimes, you only need to know about days.

In these cases, there are 86,400,000 intervals you'd rather not see. Sundial.js hides this!

Install

You can clone from git

git clone https://www.github.com/nickpalenchar/sundail

or via npm

npm install sundial-js

Add this the sundial.min.js script to your html or improt in your JavaScript to get the Sundial class: Sd.

Usage

Sundial really does one useful thing: return the amount of days since epoch time when invoked.

var howManyDays = Sd();
console.log(howManyDays) // -> 16241

var lastLoggedIn = functionThatReturnsAnEarlierSundial();
var newLoginDay = Sd();

if(lastLoggedIn === newLoginDay){
  // user has logged in before
  alert("You've already logged in today!");
}
else if(newLoginDay - lastLogged === 1){
  // user has logged in consecutively
  alert("Welcome back!");
  streak++;
}
else {
  // user has not logged in for a while
  alert("You've broken your login streak, but we're glad you're back!);
  streak = 1;
}

Main Sd function

Assign sundial numbers to our variable with the following syntax:

Sd();

Or set the number of days based off a predifined time (same syntax as the Date object)

Sd(value);
Sd(dateString);
Sd(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);

Returns a number (sundial number) representing the days since Jan 1, 1970, including that date.

If you need more sophistocated informaton, invoke with new

var allTheInfo = new Sd();

This gives you an object with the following properties:

  • jsDate - The first-class JavaScript Date
  • sdDate - A sundial date. This is the Number primitive that gets returned with Sd()
  • daysThisYear - days passed in the current year. Useful if you don't care about the year and only want to compare only 3 digits

Methods

New in v0.0.3x, use Sd.convertSd to get the inverse function, converting your sundial object/numbers back to native Date objects.

Sd.convertSd(1) // -> Jan 1 1970 (Date)

//Sd() and Sd.convertSd() are true inverses, so invoking one within the other cancels each other out

Sd(Sd.convertSd(x)) // -> x
Sd.convertSd(Sd(x)) // -> x

Anything else?

That's all for now. I really just needed something to compare when it's a new day easily. But if you have other ideas or see other uses feel free to send a pull request or submit an issue :)