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

@clubajax/dates

v2.4.1

Published

A simple utility library for handling dates.

Downloads

34

Readme

dates

A small utility library for managing date objects. Good alternative to Moment and its larger footprint.

The primary use of this library is to support ClubAJAX Date Picker, so functionality may be limited.

Getting Started

To install:

yarn add @clubajax/dates

You may also use bower or npm if you prefer. Or, you can clone the repository with your generic clone commands as a standalone repository or submodule.

git clone git://github.com/clubajax/dates.git

dates has no dependencies.

Support

dates supports all modern browsers, and is tested on IE11 and up.

Docs

  • format(date, delimiterOrPattern) - Formats a date string from a date object, based on the pattern of the third object. If delimiterOrPattern is:

    • One character, it is assumed to be a delimiter, and used to separate the numbers of a default date string (mm/dd/yyyy)
    • Otherwise, the format of the date string is constructed based on some of the common standard patterns, such as what is used in Java Simple Date Format. Examples:
        date based examples:
        'M d, yyyy' => 1 5, 2015
        'MM dd yy' => 01 05 15
        'M-d-yy' => 1-1-15
        'MM-dd-yyyy' => 01-01-2015
        'MM/d/yy' => 12/25/15
           
        day based examples:
        'yyyy/MM/dd, E' => 2016/01/26, Tuesday
        'yyyy/MM/dd, e' => 2016/01/26, Tue
           
        time based examples:
        'yyyy/MM/dd h:m A' => 2016/01/26 04:23 AM
        'h:m:s a' => 4:23:32 pm
        'hh:m:s a' => 04:23:32 pm
        'H:m' => 16:23
           
  • toDate(str) - Returns a date object based on the date string.

  • getNaturalDay(date, compareDate, noDaysOfWeek) - Returns simple natural dates (Yesterday, Today, Tommorrow) or the date. Will add Mon, Tues, etc, unless noDaysOfWeek is true. compareDate is usually the current date.

  • toTimestamp(date) - Returns a timestamp based on the date object.

  • fromTimestamp(string) - Returns a date based on the timestamp - although this is used under the hood, prefer use: toDate

  • isTimestamp(string) - Returns a boolean on whether the argument is a timestamp.

  • subtract(date, amount, dateType) - Subtracts N "something" (day, week, month, year) from a date object.

  • add(date, amount, dateType) - Adds N "something" (day, week, month, year) from a date object.

  • subtractDate(date1, date2, datepart) - Subtracts date1 from date2 and returns the difference based on the increment of the third parameter (in days, weeks, etc).

  • copy(date) - Returns a copy of a date object.

  • isLess(date1, date2) - Returns if first date is less than second date.

  • isGreater(date1, date2) - Returns if first date is greater than second date.

  • min(date1, date2, ...) - Returns the lesser of a number of dates. At least 2 arguments or an array.

  • max(date1, date2, ...) - Returns the greater of a number of dates. At least 2 arguments or an array.

  • diff(date1, date2) - The difference, in days, between two date objects. Always a positive value.

  • isValid(date) - Determines if the date object or date string is a valid date.

  • isValidObject(value) - Determines if the value is a valid date object.

  • isLeapYear(dateOrYear) - Determines if the date or year is a leap year.

  • getMonthIndex(name) - Returns the zero-based index, given a month name, which can be a full name or abbreviation (January or Jan).

  • getFirstSunday(date) - For use in building calendars.

  • getDaysInMonth(date) - For use in building calendars.

  • getDaysInPrevMonth(date) - For use in building calendars.

  • getMonthName(date) - Returns the month name of a date.

  • zeroTime(date) - Sets the time to zero, leaving date intact.

###is()

The is() functionality has simple chaining to make some statements more clear. For example, with dates.isGreater(date1, date2), it's not obvious in what order the dates should be.

  • is(date1).less(date2) - Returns if first date is less than second date.
  • is(date1).greater(date2) - Returns if first date is greater than second date.=
  • is(date1).valid() - alias to isValid.
  • is(date1).timestamp() - alias to isTimestamp.
  • is(date1).equal(date2) - Returns is the two dates are equal.
  • is(date1).equalTime() - Returns is the two objects have equal times, ignoring the date.
  • is(date1).equalDate() - Returns is the two objects have equal dates, ignoring the time.
  • is(date1).time() - If passed string is a valid time.
  • is(date1).date() - If passed string is a valid date.

License

This uses the MIT license. Feel free to use, and redistribute at will.