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

@xassist/xassist-date

v1.2.2

Published

helper functions for date manipulation

Downloads

23

Readme

@xassist/xassist-date

helper functions for date manipulation

Installation

If you use NPM, you can install the module via npm install xassist-date. Otherwise, you can download the latest minified file. Be aware any dependencies are not installed by default; you should consider downloading them yourself. If you want, you can install the complete library from github @xassist, this includes all dependencies you may need.

The module uses UMD and supports AMD, CommonJS and vanilla environments. Using vanilla: the xaglobal is exported:

<script>
xa.date()
</script>

API

date.isValidDateString()

validates a datestring

date.isValidDateString(dateStr::String)

date.isValidDateString() returns nothing.

Parameters for date.isValidDateString()

date.isValidDateString() takes 1 parameters:

  • dateStr [String]:a dateString which must follows the given requirements
    • the format may be DMY (little Endian),YMD (big Endian),MDY (middle Endian, American notation) or YDM (very rare notation, used in eg Latvia)
    • the date delimiters can be "/","","-" or a point (".")
    • timestrings can be appended to the date (when preceded by a space or a "T")
    • the time should be given in 24hrs-notation (eg 00:00:00,000 untill 23:59:59,99999999)
    • every part in the timestamp should be prefixed with a zero
    • every part of the time is optional
    • milliseconds (or even smaller) can be given after the seconds with a delimiter of "." or ","

date.stringToDate()

takes a valid datestring and constructs a new Enhanced Date-instance

date.stringToDate(dateStr::String)

Parameters for date.stringToDate()

date.stringToDate() takes 1 parameters:

  • dateStr [String]:a dateString which must follows the given requirements
    • the format may be DMY (little Endian),YMD (big Endian),MDY (middle Endian, American notation) or YDM (very rare notation, used in eg Latvia)
    • the date delimiters can be "/","","-" or a point (".")
    • timestrings can be appended to the date (when preceded by a space or a "T")
    • the time should be given in 24hrs-notation (eg 00:00:00,000 untill 23:59:59,99999999)
    • every part in the timestamp should be prefixed with a zero
    • every part of the time is optional
    • milliseconds (or even smaller) can be given after the seconds with a delimiter of "." or ","

Result for date.stringToDate()

date.stringToDate() returns a new class instance of the Class XaDate

date.stringToDate(a).constructor.name==="XaDate"

XaDate returns 5 method:

  • isValid(): checks if this is a valid Date
  • getWeekday(): returns the name of the day for the given date
  • month(): returns the name of the month of the given date
  • isLeapYear(): checks if the current date falls in a leapyear
  • daysInMonth(): returns the number of days in the month for the given date.

XaDate has 1 own attributes:

  • this[Date]:The complete instance is an instance of Date so it inherits all methods of the JavaScript Date-object

date()

The base function date() creates a new Class instance which gives access to some helper Date-functions

date();
date(value::number);
date(dateString::string);
date(year::number, month::number[, day::number[, hour::number[, minutes::number[, seconds::number[, milliseconds::number]]]]]);

Parameters for date()

date() takes 1 parameters:

  • /*multiple possiblilities*/ [any datatype]:the parameters for date() should be entered in the same manner as for a javascript Date-object. This means it can be one off the following:
    • empty: the function will return the curret datetimestamp
    • value [number]: Numerical value of the milliseconds since 1st Jan 1970 00:00:00UTC
    • dateString [string]: textual representation of the date, it should be in a format that Date.parse()understands.
    • year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]] [[numbers]: the different parts of the datetimestamp

Result for date()

date() returns a new class instance of the Class XaDate

date(a).constructor.name==="XaDate"

XaDate returns 5 method:

  • isValid(): checks if this is a valid Date
  • getWeekday(): returns the name of the day for the given date
  • month(): returns the name of the month of the given date
  • isLeapYear(): checks if the current date falls in a leapyear
  • daysInMonth(): returns the number of days in the month for the given date.

XaDate has 1 own attributes:

  • this[Date]:The complete instance is an instance of Date so it inherits all methods of the JavaScript Date-object

date().isValid()

checks if the date-instance is valid.

date().isValid()

date().isValid() requires no parameters.

Result for date().isValid()

This method returns a Boolean indicating if it is a valid date

date().getWeekday()

returns the weekday of the current date-Instance

date().getWeekday([type::string])

Parameters for date().getWeekday()

date().getWeekday() takes 1 parameters:

  • type [String,defaults to: "long"]:type of the weekday we want to return
    • long : eg Monday
    • short: eg Mon
    • abbreviation: eg M

Result for date().getWeekday()

the method returns a string with the name of the day

date.getWeekday()

gets the name of the day for a given index

date.getWeekday([index::number[,type::string[,startIndexofWeek::number[,zeroBased::boolean]]]])

Parameters for date.getWeekday()

date.getWeekday() takes 4 parameters:

  • index [Number,defaults to: 0]:the index of the day, for which we want to get the dayname (can be negative or larger then 7)
  • type [String,defaults to: "long"]:type of the weekday we want to return
    • long : eg Monday
    • short: eg Mon
    • abbreviation: eg M
  • startIndexofWeek [Number,defaults to: 0]:the week starts normally with Sunday, to change this behaviour we can set a starting index (eg 1 starts the weekday on Monday)
  • zeroBased [Boolean,defaults to: true]:the indexes are normally zerobased, we can set this to falseto get a one-based value

Result for date.getWeekday()

the function returns a string with the name of the day

date().month()

gets the name of the month for the given date-instance

date().month([type::string])

Parameters for date().month()

date().month() takes 1 parameters:

  • type [String,defaults to: "long"]:type of the mothname we want to return
    • long : eg January
    • short: eg Jan
    • abbreviation: eg J

Result for date().month()

the method returns a string with the name of the month

date.month()

gives the name of the month based on an index given.

date.month([index::number[,type::string[,zeroBased::boolean]]])

Parameters for date.month()

date.month() takes 3 parameters:

  • index [Number,defaults to: 0]:the index of the month for which we want to get the name (can be negative or larger then 12)
  • type [String,defaults to: "long"]:type of the mothname we want to return
    • long : eg January
    • short: eg Jan
    • abbreviation: eg J
  • zeroBased [Boolean,defaults to: true]:the indexes are normally zerobased, we can set this to falseto get a one-based value

Result for date.month()

the function returns a string with the name of the month

date().isLeapYear()

checks if the date-instance dalls in a leapyear

date().isLeapYear()

date().isLeapYear() requires no parameters.

Result for date().isLeapYear()

This method returns a Boolean indicating if it the date corresponds to a leap year.

date.isLeapYear()

Checks if the year provided is a leapyear.

date.isLeapYear([year::number])

Parameters for date.isLeapYear()

date.isLeapYear() takes 1 parameters:

  • year [Number,defaults to: current year]:the year for which we want to check if it is leap year.

Result for date.isLeapYear()

This function returns a Boolean indicating if a given year corresponds to a leap year.

date().daysInMonth()

returns the number of days for the current date-instance

date().daysInMonth()

date().daysInMonth() requires no parameters.

Result for date().daysInMonth()

This method returns a Number indicatingthe number of days for the given date.

date.daysInMonth()

returns the number of days in a given month for a given year.

date().daysInMonth([month::number[,year::number]])

Parameters for date.daysInMonth()

date.daysInMonth() takes 2 parameters:

  • month [Number,defaults to: current month (not zerobased!)]:the month for which we want to calulate the number of days
  • year [Number,defaults to: current year]:the year for which we want to calulate the number of days (only needed for February)

Result for date.daysInMonth()

This function returns a Number indicating the number of days for a given month and year.

DevDependencies

  • csv2readme: read csv file with fixed format and parse a readme markdown file
  • rimraf: A deep deletion module for node (like rm -rf)
  • rollup: Next-generation ES6 module bundler
  • tape: tap-producing test harness for node and browsers

License

This module is licensed under the terms of GPL-3.0.