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

h7-date-utility

v1.0.0

Published

A TypeScript library to work with dates, time zones, and intervals. Includes methods to format, compare, and calculate business days.

Readme

H7 Date Utility

H7 Date Utility is a TypeScript library that provides a set of utility functions for working with dates, time zones, and intervals. It leverages the powerful Luxon library to offer date formatting, conversion, comparison, business day calculation, and more, with full TypeScript support.

Donate

📦 Installation

To install the library, use the following command:

npm install h7-date-utility

🚀 Usage

Here's an example of how to use the DateUtility class for various date operations:

Convert Date to Time Zone

import { DateUtility } from 'h7-date-utility';

const date = "2024-11-21T00:00:00.000Z";
const timeZone = 'America/New_York';

const convertedDate = DateUtility.convertToTimeZone(date, timeZone);
console.log(convertedDate.toString());

Format Date

import { DateUtility } from 'h7-date-utility';

const date = new Date();
const format = 'yyyy LLL dd HH:mm';
const formattedDate = DateUtility.formatDate(date, format);
console.log(formattedDate);

Compare Dates

import { DateUtility } from 'h7-date-utility';

const date1 = "2024-11-21";
const date2 = "2024-11-22";

const comparison = DateUtility.compareDates(date1, date2);
if (comparison === -1) {
  console.log("Date 1 is earlier than Date 2");
} else if (comparison === 1) {
  console.log("Date 1 is later than Date 2");
} else {
  console.log("Both dates are equal");
}

Calculate Business Days

import { DateUtility } from 'h7-date-utility';

const startDate = "2024-11-01";
const endDate = "2024-11-10";

const businessDays = DateUtility.calculateBusinessDays(startDate, endDate);
console.log(`Number of business days: ${businessDays}`);

Add/Subtract Days

import { DateUtility } from 'h7-date-utility';

const date = "2024-11-21";
const timeZone = 'America/New_York';

const newDate = DateUtility.addDays(date, 5, timeZone);
console.log(newDate.toString());

const previousDate = DateUtility.subtractDays(date, 5, timeZone);
console.log(previousDate.toString());

📖 Features

  • Date Conversion: Easily convert a date to any specified time zone.
  • Custom Formatting: Format dates using a custom format.
  • Date Comparison: Compare two dates while considering time zones.
  • Business Day Calculation: Calculate the number of business days between two dates.
  • Add/Subtract Days: Add or subtract days from a given date, considering time zones.
  • Luxon-powered: Leverages the power of the Luxon library for accurate date handling.
  • TypeScript support: Fully typed, ensuring a seamless development experience in TypeScript projects.
  • Lightweight: A simple and efficient library with no dependencies.

🛠️ How it Works

This library utilizes the Luxon library for accurate date handling. It provides methods for converting dates to specific time zones, comparing dates, calculating business days, formatting dates, and more, all while considering the time zone.

📜 Example Use Case

Imagine an application that needs to handle date and time across multiple time zones. You can use this library to manage the conversion and formatting of dates seamlessly:

import { DateUtility } from 'h7-date-utility';

const date = "2024-11-21T00:00:00.000Z";
const timeZone = 'America/New_York';
const formattedDate = DateUtility.formatDate(date, 'yyyy LLL dd HH:mm', timeZone);
console.log(`Formatted date in New York time zone: ${formattedDate}`);

🤝 Contributing

Feel free to contribute to this project by opening issues or submitting pull requests. All contributions are welcome!

👨‍💻 Author

Developed by Herlandio. If you find this library helpful, consider starring the repository on GitHub!

📝 License

This project is licensed under the MIT License. You are free to use, modify, and distribute it as long as you provide proper attribution.