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

@vieolo/vdate

v2.3.0

Published

Vieolo's Custom JS Date class

Downloads

4

Readme

VDate

Vieolo's Custom JS Date class. VDate is an extension of the standard javascript Date class.

Install

npm install @vieolo/vdate

Usage

In the target package, the class can be imported as followed

import VDate from '@vieolo/vdate';

let now = new VDate();

VDate is an extension of the native javascript Date class. So, the behavior of VDate is completely similar to that of native Date.

VDate gives you the benefit of extra functionalities, both as instance methods and static functions.

Static properties

monthNamesShort

Names of the english months in the short form. e.g. Jan

monthNamesLong

Names of the english months in the long form. e.g. January

weekDayShort

Names of the english week days in the short form starting from sunday, matching the index of the week days in JS. e.g. Su

weekDayLong

Names of the english week days in the long form starting from sunday, matching the index of the week days in JS. e.g. Sunday

Static function

countDown()

Formats the difference between now (can be changed) to the given targe time.

getTimeFromMinuteCount()

Formats the minute count. For example, 80 is converted to "1h 20m"

getMinutesInDay()

Gets the number of minutes passed date according to local time. For example, at 1:15 am, you'll get 75.

getDaysInMonth()

Gets the number of days in a given month.

getDayOfYear()

Returns the number of the given day in the year. For example, 10th February is the 41st day of the year. If no date is provided, the current day is used.

getDaysInYear()

Returns the total number of days in a given year. A normal year will return 365 and a leap year will return 366.

getWeekByWeekNumber()

Returns the data of a week by its number.

Intance methods

setToDateStart()

Returns a new instance of VDate set to start of the day. (00:00)

let dayStart = new VDate().setToDateStart();
setToDateEnd()

Returns a new instance of VDate set to end of the day. (23:59)

let dayEnd = new VDate().setToDateEnd();
setToMonthStart()

Returns a new instance of VDate set to start of the month.

let monthStart = new VDate().setToMonthStart();
setToMonthEnd()

Returns a new instance of VDate set to end of the month.

let monthEnd = new VDate().setToMonthEnd();
setToYearStart()

Returns a new instance of VDate set to start of the year. (Jan 1st)

let yearStart = new VDate().setToYearStart();
setToYearEnd()

Returns a new instance of VDate set to end of the month. (Dec 31st)

let yearEnd = new VDate().setToYearEnd();
formatTime()

Formats the time of the VDate instance. e.g. 10:25 am

formatDate()

Formats the date of the VDate instance. You can pass the language to get the localized name of the month. The available formats are:

  • yyyy-mm-dd : 2022-02-24 (default)
  • dd/mm/yyyy : 24/02/2022
  • dd.mm.yyyy : 24.02.2022
  • mm/dd/yyyy : 02/24/2022
  • mon dd, yyyy : Feb 2, 2022
  • month dd, yyyy : February 2, 2022
let one = new VDate().formatDate(); // 2020-10-25
let two = new VDate().formatDate("dd/mm/yyyy"); // 25/10/2020
formatDateTime()

Formats the date and time of the VDate instance. You can pass the language to get the localized name of the month. e.g. 20/10/2020 10:25 am

formatMonth()

Formats the month and year of the VDate instance. You can pass the language to get the localized name of the month. e.g. June 2019

addSecond()

Returns a new instance of VDate instance with the added seconds.

addMinute()

Returns a new instance of VDate instance with the added minutes.

addHour()

Returns a new instance of VDate instance with the added hours.

addDay()

Returns a new instance of VDate instance with the added days.

addMonth()

Returns a new instance of VDate instance with the added months.

addYear()

Returns a new instance of VDate instance with the added years.

isLeap()

Returns true if the year of the VDate instance is a leap year.

isAfter()

Compares the instance of VDate with another one.

isBefore()

Compares the instance of VDate with another one.

isOnSameDay()

Checks if the instance of VDate is on the same day as the other one

isValid()

Checks the validity of the instance.

getWeek()

Gets the data of the week of the instance. The return object contains the following:

  • start: VDate -> start date of the week
  • end: VDate -> end date of the week
  • weekNumber: number -> the number of the week in the year (Based on ISO)
getMonthName()

Gets the short or long format of the name of the month (default: long). You can set the language to get the name of the month in the target language (default: "EN")

getDayName()

Gets the short or long format of the name of the weekday (default: long) You can set the language to get the name of the weekday in the target language (default: "EN")

getQuarter()

Gets the number of the quarter of the date

Other standalone utility functions

dateDuration()

Calculates the difference between the two given dates. The function returns a duration object that provides the difference in different time frames.

The default duration object presents the total difference in all time frames independently. e.g.

import { dateDuration } from "@vieolo/vdate";

// Both Date and VDate can be used
// Here, the two dates have a 25 hours and 10 minutes difference
let o = new VDate(2020, 0, 1, 1, 1);
let t = new Date(2020, 0, 2, 2, 11); 

let duration = dateDuration(o, t);

// Result:
// {    
//     minutes: 1510
//     hours: 25,
//     days: 1
//     months: 0
//}

This function also receives a third optional boolean to normalize the duration object. When normalized, the duration become human readable. e.g.

import { dateDuration } from "@vieolo/vdate";

// Similar to the example above, the two dates have a 25 hours and 10 minutes difference
let o = new VDate(2020, 0, 1, 1, 1);
let t = new Date(2020, 0, 2, 2, 11); 

// Passing the third boolean will normalize the difference to 1 day, 1 hour, and 10 minutes.
let duration = dateDuration(o, t, true);

// Result:
// {    
//     minutes: 10
//     hours: 1,
//     days: 1
//     months: 0
//}