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

@dexbytes/date-helper

v1.0.0

Published

The `@dexbytes/date-helper` package is a comprehensive utility for handling date and time operations in JavaScript applications. With its intuitive API and robust functionality, it simplifies common tasks such as date validation, formatting, timezone conv

Downloads

5

Readme

date-helper

The @dexbytes/date-helper package is a comprehensive utility for handling date and time operations in JavaScript applications. With its intuitive API and robust functionality, it simplifies common tasks such as date validation, formatting, timezone conversion, and date arithmetic.

Features

  • Date Validation: Check the validity of date strings.
  • Current UTC Date and Time: Obtain the current UTC date and time.
  • Date Scheduling: Schedule dates from the current time.
  • Date Formatting: Format dates according to various formats.
  • Timezone Conversion: Convert dates to different timezones.
  • Date Arithmetic: Add and subtract time intervals from dates.
  • Date Unit Calculation: Compute the start and end of specific date units.
  • Date Difference Calculation: Calculate the difference between two dates.

Installation

To use the DateHelper class in your project, you need to install the @dexbytes/date-helper package. You can install it via npm:

npm install @dexbytes/date-helper

You can visit our repository by using this link https://github.com/dexbytesinfotech/date-helper.git

Usage

Import the DateHelper class into your project:

import { DateHelper, DateFormat } from '@dexbytes/date-helper';

isDate

Check if a string is a valid date:

const dateString = '2024-03-29';

if (DateHelper.isDate(dateString)) {
    console.log(`${dateString} is a valid date.`);
} else {
    console.log(`${dateString} is not a valid date.`);
}
// Expected output: "2024-03-29 is a valid date."

getUtc

Get the current UTC date:

const utcDate = DateHelper.getUtc();
console.log('Current UTC date:', utcDate);
// Expected output: Current UTC date: [Current UTC date and time]

getUtcString

Get the current UTC date as a string:

const utcDateString = DateHelper.getUtcString();
console.log('Current UTC date string:', utcDateString);
// Expected output: Current UTC date string: [Current UTC date and time as a string]

getUtcFormat

Get the current UTC date in a specific format:

const formattedUtcDate = DateHelper.getUtcFormat(DateFormat.YYYY_MM_DD_HH_MM_SS);
console.log('Formatted UTC date:', formattedUtcDate);
// Expected output: Formatted UTC date: [Formatted UTC date and time according to specified format]

scheduleFromNow

Schedule a date from now:

const scheduledDate = DateHelper.scheduleFromNow(1, 'days');
console.log('Scheduled date from now:', scheduledDate);
// Expected output: Scheduled date from now: [Date and time one day from now]

formatDateTime

Format a date time:

const formattedDateTime = DateHelper.formatDateTime('2024-03-29', DateFormat.YYYY_MM_DD_HH_MM_SS);
console.log('Formatted date time:', formattedDateTime);
// Expected output: Formatted date time: [Formatted date and time string]

formatDateTimeRaw

Format a date time without timezone:

const rawFormattedDateTime = DateHelper.formatDateTimeRaw('2024-03-29', DateFormat.YYYY_MM_DD_HH_MM_SS);
console.log('Raw formatted date time:', rawFormattedDateTime);
// Expected output: Raw formatted date time: [Raw formatted date and time string]

getDateTimeForTimezone

Get date time for a specific timezone:

const dateTimeForTimezone = DateHelper.getDateTimeForTimezone('2024-03-29', 'India/Kolkata');
console.log('Date time for timezone:', dateTimeForTimezone);
// Expected output: Date time for timezone: [Date and time adjusted to specified timezone]

addDate

Add days to a date:

const newDate = DateHelper.addDate('2024-03-29', 1, 'days');
console.log('New date after addition:', newDate);
// Expected output: New date after addition: [Date after adding one day]

subtractDate

Subtract days from a date:

const newDate = DateHelper.subtractDate('2024-03-29', 1, 'days');
console.log('New date after subtraction:', newDate);
// Expected output: New date after subtraction: [Date after subtracting one day]

getStartOf

Get the start of a date unit:

const startOfMonth = DateHelper.getStartOf('2024-03-29', 'month');
console.log('Start of month:', startOfMonth);
// Expected output: Start of month: [Start date of the month containing the given date]

getEndOf

Get the end of a date unit:

const endOfMonth = DateHelper.getEndOf('2024-03-29', 'month');
console.log('End of month:', endOfMonth);
// Expected output: End of month: [End date of the month containing the given date]

dateDiff

Calculate date difference:

const difference = DateHelper.dateDiff('2024-03-29T12:00:00', '2024-03-27T12:00:00', 'days');
console.log('Date difference:', difference);
// Expected output: Date difference: [Difference in days between the two dates]

dateDiffFormatted

Calculate formatted date difference:

const formattedDifference = DateHelper.dateDiffFormatted('2024-03-29T12:00:00', '2024-03-27T12:00:00', 'days');
console.log('Formatted date difference:', formattedDifference);
// Expected output: Formatted date difference: [Formatted difference in days between the two dates]

durationFromNowInMinutes

Calculate duration from now in minutes:

const durationInMinutes = DateHelper.durationFromNowInMinutes('2024-03-29');
console.log('Duration from now in minutes:', durationInMinutes);
// Expected output: Duration from now in minutes: [Duration from now to the specified date in minutes]

durationFromNowAsString

Calculate duration from now as a string:

const durationAsString = DateHelper.durationFromNowAsString('2024-03-29');
console.log('Duration from now as string:', durationAsString);
// Expected output: Duration from now as string: [Human-readable duration from now to the specified date]

Contribution

If you have any questions about contributing to this project, feel free to reach out to us at [email protected].