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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fagon/ngx-chronox

v1.0.3

Published

Modern Angular date library with smart relative formatting, date utilities, comparison helpers, reactive form validators, and template pipes. Lightweight, type-safe, and Angular v14+ compatible.

Readme

ngx-chronox

npm version npm downloads bundle size Angular TypeScript License Build Status Coverage PRs Welcome Made with Love

A complete date toolkit for Angular Helpers • Pipes • Validators • Types • Constants Angular v14+ compatible

ngx-chronox simplifies date handling across your Angular application with:

  • Static utility helpers
  • Smart relative formatting
  • Angular pipes for templates
  • Reactive form validators
  • Strong typing & utilities
  • Locale-aware formatting
  • Multiple date input formats

Installation

npm install @fagon/ngx-chronox

Import

import { ChronoxHelper } from "ngx-chronox";

Library Building Blocks

Constants

import { CONSTANTS } from "ngx-chronox";

CONSTANTS.ONE_SECOND_IN_MILLISECONDS // 1000 CONSTANTS.ONE_MINUTE_IN_MILLISECONDS // 60000 CONSTANTS.ONE_HOUR_IN_MILLISECONDS // 3600000 CONSTANTS.TWENTY_FOUR_HOURS_IN_MILLISECONDS // 86400000 CONSTANTS.FOURTY_EIGHT_HOURS_IN_MILLISECONDS // 172800000 CONSTANTS.DEFAULT_DATE_FORMAT // 'd MMM, yyyy'

Example

const timeout = 5 \* CONSTANTS.ONE_MINUTE_IN_MILLISECONDS;

RegExps

import { RegExps } from "ngx-chronox";

MONTH_YEAR_REGEX

Validates MM-YYYY format.

RegExps.MONTH_YEAR_REGEX.test('02-2026'); // true RegExps.MONTH_YEAR_REGEX.test('2-2026'); // false

Example: Form Validation

if (!RegExps.MONTH_YEAR_REGEX.test(input)) {
  console.log("Invalid format. Use MM-YYYY");
}

Types & Interfaces

DateStruct

export interface DateStruct {
  year: number;
  month: number;
  day: number;
}

MonthYear

export type MonthYear = {
  year: number;
  month: number;
};

Usage Example

const birthday: DateStruct = {
  year: 2000,
  month: 5,
  day: 12,
};

const expiry: MonthYear = {
  year: 2027,
  month: 11,
};

Global Locale

Default: 'en-US'

Change globally:

ChronoxHelper.setLocale('en-GB'); 🧠 Supported Date Inputs

All helpers, pipes, and validators accept:

✔ Date ✔ Timestamp ✔ ISO string ✔ { year, month, day } ✔ { year, month }

ChronoxHelper (Core Utility)

normalizeDate()

Converts supported formats to a native Date.

Examples ChronoxHelper.normalizeDate(); ChronoxHelper.normalizeDate('2026-02-01'); ChronoxHelper.normalizeDate(1706745600000);

ChronoxHelper.normalizeDate({ year: 2026, month: 2, day: 1 });

ChronoxHelper.normalizeDate({ year: 2026, month: 2 }); // → last day of February

convertToDateStruct()

const struct = ChronoxHelper.convertToDateStruct();
console.log(struct); // { year: 2026, month: 2, day: 27 }

Convert user input

const struct = ChronoxHelper.convertToDateStruct("2026-02-01");

addToDate()

ChronoxHelper.addToDate(7, 'day'); ChronoxHelper.addToDate(2, 'month'); ChronoxHelper.addToDate(30, 'minute'); ChronoxHelper.addToDate(1, 'hour', '2026-02-01');

Real-world: subscription expiry

const expiry = ChronoxHelper.addToDate(1, "month", startDate);

subtractFromDate()

ChronoxHelper.subtractFromDate(7, 'day'); ChronoxHelper.subtractFromDate(1, 'month'); ChronoxHelper.subtractFromDate(15, 'minute');

Example: show last login window

const lastWeek = ChronoxHelper.subtractFromDate(7, "day");

calculateDaysBetweenDates()

ChronoxHelper.calculateDaysBetweenDates('2026-02-01', '2026-02-10'); // "9 days"

Booking duration example

const stay = ChronoxHelper.calculateDaysBetweenDates(checkIn, checkOut);

formatDate()

Uses Angular DatePipe.

ChronoxHelper.formatDate(new Date()); ChronoxHelper.formatDate(new Date(), 'dd/MM/yyyy'); ChronoxHelper.formatDate(new Date(), 'longDate', 'fr-FR');

Example

const label = ChronoxHelper.formatDate(invoiceDate, "MMM d");

smartDateFormat()

Auto Mode ChronoxHelper.smartDateFormat(messageDate);

Outputs:

  • few seconds ago
  • 3 minutes ago
  • 5 hours ago
  • yesterday
  • today
  • tomorrow

formatted date

Unit Mode ChronoxHelper.smartDateFormat(date, 'day'); ChronoxHelper.smartDateFormat(date, 'month', 'MMMM yyyy');

compareDateToNow()

ChronoxHelper.compareDateToNow('2026-01-01', 'day'); // days ago ChronoxHelper.compareDateToNow('2025-01-01', 'month'); // months ago

Date Comparisons

  1. ChronoxHelper.equals(a, b);
  2. ChronoxHelper.before(a, b);
  3. ChronoxHelper.after(a, b);
  4. ChronoxHelper.equalsOrAfter(a, b);
  5. ChronoxHelper.beforeOrEquals(a, b);
  6. ChronoxHelper.isSameDay(a, b);

Example

if (ChronoxHelper.before(expiry, new Date())) {
  console.log("Expired");
}

Angular Pipes

chronoxDate Pipe

Formats a date.

Template

{{ orderDate | chronoxDate }}
{{ orderDate | chronoxDate:'dd/MM/yyyy' }}

Component orderDate = new Date();

chronoxDaysDiff Pipe

Difference between two dates.

{{ startDate | chronoxDaysDiff:endDate }}

Example startDate = '2026-02-01'; endDate = '2026-02-10';

Output: 9 days

chronoxSmartDate Pipe

Smart relative formatting.

{{ postDate | chronoxSmartDate }}
{{ postDate | chronoxSmartDate:'day' }}
{{ postDate | chronoxSmartDate:'month':'MMMM yyyy' }}

Example Feed UI

<li *ngFor="let post of posts">{{ post.createdAt | chronoxSmartDate }}</li>

Validators

DateRangeOrderValidatorFactory

Ensures start date is before end date.

Setup

constructor(
private rangeValidator: DateRangeOrderValidatorFactory
) {}
//Apply
this.form = this.fb.group(
	{
		start: [''],
		end: ['']
	},
	{
	validators: this.rangeValidator.createValidator('start', 'end')
	}
);

Template

<div *ngIf="form.errors?.startDateAfterEndDate">End date must be after start date</div>

dateTimeValidator

Ensures valid date and time input.

dateControl = new FormControl('', dateTimeValidator);

maxDateRangeDifferenceValidator

Restricts date range length.

this.form = this.fb.group(
  {
    start: [""],
    end: [""],
  },
  {
    validators: maxDateRangeDifferenceValidator("start", "end", 3),
  },
);

Use Case

  • booking limits
  • reporting filters
  • subscription windows

noFutureDateValidator

Prevents future dates.

dob = new FormControl("", noFutureDateValidator);

Example

  • birth dates
  • past event entries
  • compliance forms

COMPLETE USAGE EXAMPLES

Chat App Timestamp

<span>{{ message.time | chronoxSmartDate }}</span>

Booking Duration

duration = ChronoxHelper.calculateDaysBetweenDates(booking.start, booking.end);

Payment Expiry Check

if (ChronoxHelper.before(cardExpiry, new Date())) {
  alert("Card expired");
}

Prevent Future Birth Date

birthDate = new FormControl("", noFutureDateValidator);

Subscription Expiry Calculation

nextBilling = ChronoxHelper.addToDate(1, "month", today);

Validate Month-Year Input

if (!RegExps.MONTH_YEAR_REGEX.test(value)) {
  throw new Error("Format must be MM-YYYY");
}

Activity Feed UI

<li *ngFor="let activity of activities">{{ activity.date | chronoxSmartDate }}</li>

Report Filter Form

this.form = this.fb.group(
  {
    from: [""],
    to: [""],
  },
  {
    validators: maxDateRangeDifferenceValidator("from", "to", 6),
  },
);

Best Practices

  • Use pipes for UI formatting
  • Use helpers for business logic
  • Normalize external dates before storage
  • Apply validators at FormGroup level for date relationships
  • Use smartDateFormat for user-friendly timestamps

📄 License

MIT © Fagon Technologies