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

@kpajtasev/date-util

v4.1.0

Published

JavaScript date helper

Downloads

4

Readme

date-helper

JavaScript date helper

Still in development. Currently supports only getting formated date.

Instalation

package.json

"date-helper-util": "x.y.z"

Usage

var dateHelper = require("date-helper-util");

With date object

var date = new Date(2015, 1, 3);
date = dateHelper(date);
date.getFormated("DD/MM/YYYY"); // outputs 03/02/2015

With date string and date format string

date = dateHelper("03/02/2015", "DD/MM/YYYY");
date.getFormated("YYYY/MM/DD"); // outputs 2015/02/03

Formats

  • DD - date, if less then 10 prepends with 0
  • D - date, if less then 10 NOT prepended with 0
  • MMM - month as a month name (January, February, ...)
  • MM - month, if less then 10 prepends with 0
  • M - month, if less then 10 NOT prepended with 0
  • YYYY - full year

Setting date values

var date = dateHelper(new Date());

Setting year

date.setYear(2016);

Setting month

date.setMonth(1); // accepts 1-12

Setting date

date.setDate(1);

Getting date values

Getting year

date.getYear();

Getting month

Returns values 1-12 and not like native JavaScript 0-11

date.getMonth();

Getting date

date.getDate();

Adding values to date

Values can be added by calling .add function with type and amount parameters. Type is string day, month or year.

date = dateHelper(new Date());
date.add("day", 1);
date.add("month", 1);
date.add("year", 1);

Subtracting values to date

Values can be subtracted by calling .sub function with type and amount parameters. Type is string day, month or year.

date = dateHelper(new Date());
date.sub("day", 1);
date.sub("month", 1);
date.sub("year", 1);

Is date before other date

isBefore function can be used to check if date is before other.

var date = new Date(2016, 4, 3);
dateHelper(date).isBefore(new Date(2016, 4, 4)); // true

Is date after other date

isAfter function can be used to check if date is after other.

var date = new Date(2016, 4, 3);
dateHelper(date).isAfter(new Date(2016, 4, 2)); // true

Is date same as other date

isSameAs function can be used to check if date at same time as other.

var date = new Date(2016, 4, 3);
dateHelper(date).isSameAs(new Date(2016, 4, 3)); // true

i18n

By using configuration month names can be set

Node module

var dateHelperConfig = require("../dev/dateHelper").config;
dateHelperConfig.setMonthNames(["Sijecan", "Veljaca", "Ozujak", "Travanj",
    "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac"])
var date = new Date(2016, 4, 3);
dateHelper(date).getFormated("DD/MMM/YYYY"); // "03/Svibanj/2016"

Browser

dateHelper.config.setMonthNames(["Sijecan", "Veljaca", "Ozujak", "Travanj",
    "Svibanj", "Lipanj", "Srpanj", "Kolovoz", "Rujan", "Listopad", "Studeni", "Prosinac"])
var date = new Date(2016, 4, 3);
dateHelper(date).getFormated("DD/MMM/YYYY"); // "03/Svibanj/2016"

TODO

  • Tests
  • Hours, minutes and seconds