npm.io
3.1.30 • Published 3 weeks ago

@rightcapital/date-helpers

Licence
MIT
Version
3.1.30
Deps
2
Size
20 kB
Vulns
0
Weekly
1.2K
Stars
11

@rightcapital/date-helpers

A utility class providing various date formatting and parsing methods in TypeScript.

Features

  • Convert a date string to Date object with parseDateString.
  • Format dates into various string formats, such as ISO, US locale, and more.
  • Handle a variety of date string formats for both parsing and formatting.

Installation

pnpm add @rightcapital/date-helpers

Usage

Parse Date String

Convert a date string to a Date object using various possible formats.

import { DateHelpers } from '@rightcapital/date-helpers';
const date = DateHelpers.parseDateString('2023/01/01');
Format to ISO Date String

Format a date as an ISO date string.

import { DateHelpers } from '@rightcapital/date-helpers';

const isoDateString = DateHelpers.formatDateLikeToIsoDateString(
  new Date(2023, 0, 1),
);
// Result: Sun Jan 01 2023 00:00:00 GMT+0000 (Coordinated Universal Time)
Format to US Locale

Format a date as a US locale date string.

import { DateHelpers } from '@rightcapital/date-helpers';
const usDateString = DateHelpers.formatDateLikeToUsLocaleDateString(
  new Date(2023, 0, 31),
);
// Result: "01/31/2023"

Formats a date as a US locale time string.

import { DateHelpers } from '@rightcapital/date-helpers';
const usDateString = DateHelpers.formatDateLikeToUsLocaleDateTimeString(
  '2025/10/20 12:00:00',
);
// Result: "10/20/2025 12:00:00"
Format to US Locale Medium Date

Formats a date as a string in the MDY format.

const monthDayYearString = DateHelpers.formatDateLikeToUsLocaleMediumDateString(
  new Date(2023, 0, 1),
);
// Result: "Jan 1, 2023"

API Reference

Here is the API documentation for the modules included in the package.

Keywords