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

month-utils

v0.8.2

Published

Time slot scheduling classes relative to months as storage units

Downloads

4

Readme

Month Utils

This is a short collection of methods for working with months and timestamps.

This is not a formatting library. It helps switch between Date objects and timestamps for such needs as finding the first timestamp of the first day of a month when the some later day is known. It is just a few of these kinds of methods.

  • Since the small number of methods are common occurring requirements the module proves useful to have for a number of projects.

  • Since the number of methods is few, the module is very short and uses less than 8K of space uncompressed and 4K compressed by terser.

Install

For use in node.js projects:

npm install i --save month-utils

In your node.js program you can access classes in the following manner:

const month_utils = require('month-utils')

Web Page Use

A rollup.config.js file has been added to the package. The npm package should be released after running npm run build. (That is best effort.)

Builds that use rollup may simply include event-days in their devDependencies field within package.json. It may help to run a second npm install a such:

npm install i --save-dev month-utils

Example: This class is being used in a Svelte project. The module is included in an App.svelte file as follows:

import month_utils from 'month-utils'

Constants

  • TWENTY_FOUR
  • ONE_WEEK
  • ONE_MONTH
  • MIN15
  • MIN30
  • HOUR

Methods

prev midnight

  • Date -> timestamp

Given a date object for a time on a pariticular day, returns the timestamp of the preceding midnight.

next midnight

  • Date -> timestamp

Given a date object for a time on a pariticular day, returns the timestamp of the midnight for the end of the day.

part of day

  • Date, number -> timestamp

Given a date object for a time on a pariticular day, returns the timestamp equal to the partial mutiplied by the difference between the next midnight and the prev midnight added to the preceding midnight. That is, the timestamp of a fraction of the day.

hours of

  • timestamp -> number

Given a timestamp representing a duration, returns the number of hours.

calc days

  • timestamp -> number

Given a timestamp representing a duration, returns the number of days.

in interval

  • timestamp, timestamp, timestamp -> boolean

Given a timestamp representing an instant of time, a start time and an end time for an interval, returns true if the instant is in the interval.

first day of month

  • Date-> timestamp

Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the month containing the point in time.

first day of month ts

  • timestamp-> timestamp

The same as first day of month but this takes a timestamp representation of the point in time.

lower month bounday

  • timestamp-> timestamp

Alias for first day of month ts.

first day of next month

  • Date-> timestamp

Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the next month not containing the point in time.

first day of next month ts

  • timestamp-> timestamp

The same as first day of next month but this takes a timestamp representation of the point in time.

lower month bounday

  • timestamp-> timestamp

Alias for first day of next month ts.

first day of relative month

  • Date, number -> timestamp

Given a Date representation of a point in time, returns the timestamp of the midnight starting the first day of the nth (number) beyond the month containing the point in time.

first day of relative month ts

  • timestamp, number-> timestamp

The same as first day of relative month but this takes a timestamp representation of the point in time.

same day

  • timestamp, timestamp-> boolean

Returns true if the two timestamps have the same date.

day is clock day

  • number, number, number, Date -> boolean

(day, year month, Date) returns true if the day given is the same day as the Date's day.

day is before clock day

  • number, number, number, Date -> boolean

(day, year month, Date) returns true if the day given is less than the day that is the Date's day where the time is taken from the midnight before the day.

day is after clock day

  • number, number, number, Date -> boolean

(day, year month, Date) returns true if the day given is greater than the day that is the Date's day where the time is taken from the midnight ending the day.