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

date-ops

v2.2.0

Published

Advanced and simple operations with dates and calendars

Downloads

14

Readme

Advanced and simple operations with dates and calendars.

date-ops

NPM version Generic badge CI codecov

Read docs.

This library uses Luxon library to represent dates and times.


Install

npm:

npm install date-ops

Yarn:

yarn add date-ops

How to use

Calendar

import { Calendar } from "date-ops";
import { DateTime } from "luxon";

const calendar = new Calendar();
const date = DateTime.utc(2021, 3, 30);
const check1 = calendar.isWorkday(date); // true
const check2 = calendar.isPublicHoliday(date); // false

calendar.addPublicHoliday(date);
const check3 = calendar.isPublicHoliday(date); // true
const check4 = calendar.isWorkday(date); // false

const date2 = DateTime.utc(2021, 4, 4);
const check5 = calendar.isPublicHoliday(date2); // false
calendar.addPublicHolidayDependsOfYear(easterOf);
const check6 = calendar.isPublicHoliday(date2); // true

Date Retrieval

const date = DateTime.utc(2021, 3, 30); // It's Tuesday
const retrieval1 = nextWeekDay(date, WeekDay.FRIDAY); // 2021 04 02
const retrieval2 = nextWeekDay(date, WeekDay.TUESDAY); // 2021 04 06
const retrieval3 = lastWeekDay(date, WeekDay.SUNDAY); // 2021 03 28
const retrieval4 = lastWeekDay(date, WeekDay.TUESDAY); // 2021 03 23
const retrieval5 = nthWeekDayInMonth(
  2021, Month.MAY, WeekDay.SUNDAY, 2
); // 2nd Sunday of May, 2021: 2021 05 09
const retrieval6 = nthWeekDayInMonth(
  2021, Month.MAY, WeekDay.SUNDAY, 6
); // undefined
const retrieval7 = nthWeekDayInMonthBack(
  2021, Month.MAY, WeekDay.SUNDAY, 1
); // Last Sunday of May, 2021: 2021 05 30
const retrieval8 = mothersDayOf(2021); // (Spain): 2021 05 02
const retrieval9 = easterOf(2021); // 2021 04 04
const retrieval10 = thanksGivingDayOf(2021); // 2021 11 25

Some util functions

const from = DateTime.utc(1970, 1, 1);
const to = DateTime.utc(2021, 3, 30);
const days = daysBetween(from, to); // 18716
const millis = millisBetween(from, to); // 1617062400000
const check = isWeekend(date); // false
const timeStamp = getTimestamp(from); // 19700101T000000

Enums

const {
  MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY,
  SUNDAY
} = WeekDay; // MONDAY=1, SUNDAY=6

const {
  MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY,
  SUNDAY
} = WeekDayJS; // MONDAY=1, SUNDAY=0

const { JANUARY, FEBRUARY, MARCH,
  APRIL, MAY, JUNE, JULY, AUGUST,
  SEPTEMBER, OCTOBER, NOVEMBER,
  DECEMBER
} = Month; // JANUARY = 1, DECEMBER=12

const { JANUARY, FEBRUARY, MARCH,
  APRIL, MAY, JUNE, JULY, AUGUST,
  SEPTEMBER, OCTOBER, NOVEMBER,
  DECEMBER
} = MonthJS; // JANUARY = 0, DECEMBER=11

©2021 Daniel Sales Álvarez [email protected]