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

datezen

v0.2.1

Published

Lightweight, native-independent date utility library supporting full-range calculations — from 0001-01-01 to 275760-09-13, with no dependencies.

Downloads

53

Readme

📅 DateZen

DateZen is a lightweight date manipulation library for JavaScript, written from scratch without relying on the native Date object. It enables full-range date operations, plugin-based extensibility, and consistent UTC behavior — ideal for applications requiring precision across historical or future timestamps. Handles timestamps from 0001-01-01 through 275760-09-13 with full mathematical precision.

NPM Version License: MIT

📖 Table of Contents

✨ Features

  • ⚖️ Zero dependency & fully native-independent
  • 🪶 Works from 0001-01-01T00:00:00.000Z to 275760-09-13T00:00:00.000Z
  • 🔢 Pure mathematical timestamp handling (no Date under the hood)
  • 🧩 Plugin system for extensibility (e.g. formatting, diffing, comparing)
  • 🧪 Tested against native JS behavior (via benchmarks and precision tests)

🚀 Installation

npm install datezen

or

yarn add datezen

🛠 Usage

You can create a DateZen instance in various ways depending on your input format:

import dz from 'datezen';

/**
 * From an ISO string
 */
const a = dz('2024-06-01T12:00:00Z');

/**
 * From a timestamp in milliseconds
 */
const b = dz(1717243200000);

/**
 * From a value + unit object
 * Type: { value: number; unit: 'ms' | 's' | 'm' | 'h' | 'd' }
 */
const c1 = dz({ value: 86400, unit: 's' }); // → 1 day in seconds
const c2 = dz({ value: 86400000, unit: 'ms' }); // → 1 day in milliseconds
const c3 = dz({ value: 1440, unit: 'm' }); // → 1 day in minutes
const c4 = dz({ value: 24, unit: 'h' }); // → 1 day in hours
const c5 = dz({ value: 1, unit: 'd' }); // → 1 day

/**
 * From a full date object
 * Type: { year: number; month: number (1–12); day: number; hour?: number; minute?: number; second?: number; millisecond?: number }
 */
const d = dz({
  year: 2024,
  month: 6, //June
  day: 1,
  hour: 12,
  minute: 0,
  second: 0,
  millisecond: 0,
});

/**
 * From a date object using monthIndex
 * Type: { year: number; monthIndex: number (0–11); day: number; hour?: number; minute?: number; second?: number; millisecond?: number }
 */
const e = dz({
  year: 2024,
  monthIndex: 4, // May
  day: 1,
});

/**
 * From current time (default)
 */
const now = dz();

🧪 Unit Tests

DateZen is covered by comprehensive unit tests.
To run them locally:

npm test

Tests are located in: __tests__/*/*.test.ts

💼 In Practice

Need to validate input, format it, and calculate a range? No problem:

const from = dz('2024-01-01');
const to = dz('2025-01-01');

console.log(from.format('MMM YYYY')); // "Jan 2024"
console.log(to.diff(from, 'days'));   // 366 (leap year)

🧩 API Reference (Table View)

| Method | Return Type | Description | |--------------------------------|----------------------|---------------------------------------------------------| | toMilliseconds() | number | Returns the timestamp in milliseconds. | | toSeconds() | number | Returns the timestamp in seconds. | | milliseconds() | number | Milliseconds part of the time (0–999). | | seconds() | number | Seconds part of the time (0–59). | | minutes() | number | Minutes part of the time (0–59). | | hours() | number | Hours part of the time (0–23). | | weekday() | number | Day of the week (0–6, where 0 is Sunday). | | year() | number | Returns the full year. | | monthIndex() | number | Month (0–11). | | month() | number | Month (1–12). | | day() | number | Day of the month (1–31). | | isLeapYear() | boolean | Checks if the year is a leap year. | | toParts() | object | Returns all components of the date. | | toISOString() | string | Returns ISO string if valid; otherwise "Invalid Date".| | toString() | string | Same as toISOString(). | | add({...}) | DateZen | Returns a new instance with time added. | | sub({...}) | DateZen | Returns a new instance with time subtracted. | | isInvalid() | boolean | Returns true if the date is invalid. | | isSame(other) | boolean | Checks if the given date is equal. | | isBefore(other) | boolean | Checks if the date is before the given date. | | isAfter(other) | boolean | Checks if the date is after the given date. | | isBetween(a, b) | boolean | Returns true if date is strictly between a and b. | | format(pattern) (plugin) | string | Formats the date according to the pattern. | | | | Requires format plugin. | | diff(other, unit) (plugin) | number or object | Calculates time difference. Requires diff plugin. | | use(type, fn) | void | Registers a plugin for the instance. |

🔌 Plugin System

DateZen supports plugins that extend its functionality in a modular way. You can use them globally via dz.use() or locally via instance.use().

Register plugin globally:

import dz from 'datezen';
import formatPlugin from 'datezen/format';
import diffPlugin from 'datezen/diff';

dz.use('format', formatPlugin)
  .use('diff', diffPlugin);

const date = dz('2024-06-01T12:00:00Z');
console.log(date.format('YYYY-MM-DD')); // → "2024-06-01"

/**
 * To override or apply plugins only to the current instance, use the .use() method.
 * This allows per-instance plugin behavior without affecting global configuration.
 * @param {{ year: number; month: number; day: number; hours: number; minutes: number; seconds: number; milliseconds: number }} - Time to subtract
 * @param {string} - pattern
 */
data.use('format', function (data: PartDate, pattern: string) {
  return pattern;
});

🧱 Architecture

  • Internally uses millisecond-based math to calculate date/time
  • Day calculations are performed using purely mathematical functions without iteration
  • Binary search optimizations for month lookup
  • No reliance on Date, Intl, or locale-specific behavior
  • Memory-safe design with local memoization

💡 Why DateZen?

Working with dates in JavaScript is often complex and unpredictable. Native date handling lacks clear formatting support and often fails when dealing with negative timestamps (i.e., dates before 1970). This inconsistency leads to cumbersome workarounds and increased code complexity.

Most libraries are simply wrappers over native Date behavior. My goal was to build a fully independent and transparent UTC-based timestamp library — built entirely from scratch — that behaves consistently across all valid inputs.

If your goal is extreme performance, native solutions might be better suited and should be tailored for your needs. However, if your priorities are clarity, formatting, manipulation, and consistent behavior across all ranges, DateZen is for you.

⚙️ Math-Powered Precision

All core calculations in DateZen — including conversion from timestamps to date parts — are built upon pure mathematical formulas with O(1) complexity, ensuring reliable and fast computations at scale.

🧪 Benchmarks (vs Native Date)

Performance is not the primary goal. DateZen focuses on range, predictability, and extensibility over raw speed.

🛠 Planned Features

The following improvements are planned to enhance DateZen's capabilities:

  • 🕐 Timezone Parsing Support
    Add native support for parsing ISO strings with timezone offsets (e.g., +02:00, Z).

  • 🌐 Timezone Plugin
    A plugin to allow conversion between UTC and arbitrary IANA timezones (e.g., Europe/Berlin, America/New_York).

  • 📊 Compare Plugin
    Enables sorting and comparison operations across date instances (e.g., .compare(a, b)).

  • 📦 CDN Support
    Coming soon via jsDelivr or unpkg.

    You’ll be able to use DateZen directly in the browser via:

    <script src="https://cdn.jsdelivr.net/npm/datezen"></script>

💬 Community / Contributing

Contributions are welcome! Feel free to open issues or PRs.

📄 License

MIT License © 2025 Maksym Cherniavskyi