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

magic-date

v2.0.6

Published

A simple date utility for javascript

Downloads

4

Readme

MagicDate

N|Solid

A Javascript library for Date manipulation

Without much further ado, I will just jump right into how to use this library. Very pretty straight forward. The library consists of static and instance methods. Depending on what you will like to achieve, so let's jump right into it.

How Tos

Instantiate the Object

Simply instantiate this library, and get instant access to all it properties

// instantiate the library
const dateObject = new MagicDate()  // return the current date as a MagicDate object

// to instantiate a specific date, just create a SimpleDate object
// the Interface accepts (year, month, day, hour, min, sec)
const dateObject = MagicDate.makeDate({year: 2018, month: 3, day: 18})

// in the configuration for instantiation you could add when your week starts, 
// by default week starts on Sunday being 0, in the following line we are 
// starting the weel on Monday being 1
const dateObject = MagicDate.makeDate({year: 2018, month: 3, day: 18}).setWeekStart(1)
Deep Dive Examples

Lets dive deeeper into some other examples

// >>> let get the date object a week from the current date
const dateObject = new MagicDate().next("1 week")

// >>> we will like to know what date it was a 36 days ago
// notice the negative sign used to get a date prior to the reference date object
const dataObject = new MagicDate().next("-36 days")

// >>> lets get a date 3 days prior to January 25, 2018
const dateObject = MagicDate.makeDate({year: 2018, month: 1, day: 25}).next("-3 days")

// >>> we could also retrieve the week number from any given date
const dateObject = new MagicDate()
const weekNum = dateObject.weeknum
// next we will attempt to get the first date of the reference week
const firstDateFromWeek = dateObject.getWeekFirstDate()
// next we will attempt to get the last date of the reference week
const lastDateFromWeek = dateObject.getWeekLastDate()
// we will now retrieve the first date of a given month
const monthFirstDate = dateObject.getMonthFirstDate()
// we can get the last date of the given month in a formated string template
const lastMonthDateStr = dateObject.getMonthLastDate().setCast("%Y-%m-%d").toString()

// >>> we can do some common checks
// check if the current date is from a leapYear
const isLeapYearCurrent = new MagicDate().isLeapYear()
// check if a year is a leap year statically
const isLeapYearReference = MagicDate.isLeapYear(2016)

// >>> get dates between a start and an end date, returns an 
// Array of MagicDate objects
// TODO: this should return a generator
const $start = MagicDate.makeDate({year: 2018, month: 3, day: 18})
const $end = MagicDate.makeDate({year: 2018, month: 6, day: 20})
const datesBetween = MagicDate.getDateFromTo({$start, $end})
// lets return the array in a date formated string
const datesBetweenFormatted = datesBetween.map(v => v.toDateString())

// >>> lets check if date positions are correct, something like the end date
// should be less than the previous date
const $start = MagicDate.makeDate({year: 2018, month: 6, day: 20})
const $end = MagicDate.makeDate({year: 2018, month: 3, day: 18})
const isDateGreater = MagicDate.validatePosition($start, $end)  // should be false
Retrieving Properties

We will now retrieve some properties

// A weekday interface has name, shortName and code e.g. Tuesday, Tue, 02
// you can access any of the objects like so
const weekdayName = dateObject.weekday.name // e.g. Tuesday

Properties and Methods of the MagicDate Object

year: number month: number day: number hour: number minute: number second: number microSecond: number timezone: any weekday: WeekDayInterface weekdayNumeric: number weeknum: number weekStart: WeekDayInterface leapYear: boolean yearStr: string monthStr: string dayStr: string hourStr: string minuteStr: string secondStr: string microSecondStr: string timezoneOffset: number dtTime: number dtObj: Date