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

civil-date

v1.0.1

Published

Naive date utility for efficient storage of date related data

Readme

civil-date

A lightweight utility (1,398 bytes minified, 655 bytes gzipped) for handling timezone-independent calendar dates.

A "civil date" refers to a standard calendar day (Year-Month-Day) used for administrative and everyday purposes. Unlike a timestamp, it represents a whole day regardless of the time or the user's location.

The Problem

Using standard UTC timestamps for daily data often leads to "off-by-one-day" errors. For example, 2025-12-19T23:00:00Z is the 19th in New York but the 20th in London. Storing this as a single UTC timestamp makes it difficult to query "all records for the 19th" consistently across timezones. Often, users will only care about data for their 'day'.

The Solution

This package converts a local date (e.g., "2025-12-19") into a Unix Day Count (days since the epoch) and encodes it as a compact, sortable Radix 36 string (e.g., FRT).

This is ideal for:

  • Storage Keys: Efficiently storing date-based data in Firestore maps, Redis hashes, or JSON.
  • Daily Metrics: Tracking daily balances, counts, or habits without timezone ambiguity.
  • Compactness: Reducing 2025-12-19 (10 chars) to FRT (3 chars).

Relation to Temporal API

The upcoming JavaScript Temporal API provides a PlainDate class which will become the standard way to represent a date without time or timezone. While excellent for date math, converting a PlainDate to a simple integer (days since epoch) for storage is not yet widely available and surprisingly complex:

// Temporal
const date = Temporal.PlainDate.from('2025-12-19')
const epoch = Temporal.PlainDate.from('1970-01-01')
const days = date.since(epoch).days

civil-date focuses specifically on the storage aspect, providing a direct conversion to a compact, sortable key.

Usage

C'mon, you know the drill, do I really have to say it? Use your favorite package manager to install it. I like pnpm:

pnpm i civil-date

There are low-level tree-shakeable methods you can import and use, or a class if that's what you prefer.

Tree-shakeable methods

You can use the individual functions directly if you don't want to use the class.

import { encode, decode, fromDate, toDate, toISOString } from 'civil-date'

// Convert a Date object to a unix day number (uses local time)
const days = fromDate(new Date()) // 20447

// Encode a unix day number to a Radix 36 string
const key = encode(days) // 'FRT'

// Decode a Radix 36 string to a unix day number
const decodedDays = decode('FRT') // 20447

// Convert a unix day number or Radix 36 string to a Date object (midnight UTC)
const date = toDate(days)
const date2 = toDate('FRT')

// Convert a Date object to an ISO 8601 string (YYYY-MM-DD)
const iso = toISOString(new Date('2025-12-19T23:00:00-06:00')) // '2025-12-19'

// Note: Unlike date.toISOString(), this preserves the local date and avoids
// UTC shifts (which would result in '2025-12-20' in this example).

CivilDate Class

Create a new instance for the current day:

const day = new CivilDate()

Create a new instance from a JavaScript Date object (it will use the local year, month, and day):

const day = new CivilDate(new Date(2025, 11, 19))

Create a new instance from an ISO 8601 / RFC RFC 9557 Date string. Non YYYY-MM-DD format strings and invalid dates will throw an error.

const day = new CivilDate('2025-12-19')

Create a new instance from a Radix 36 encoded string of the number of unix days since the epoch:

const day = new CivilDate('FRT')

Create a new instance from a unix day (days since the unix epoch):

const day = new CivilDate(20447)

The unix day will be available as a .value property of the instance.

const day = new CivilDate('2025-12-19')

console.log(day.value)	// 20441
console.log(day.toString()) // FRT

You can use a previously saved key to restore a date using:

const day = new CivilDate('FRT')

Use .toString() to get the encoded key:

const key = day.toString()

console.log(key)		// 'FRT'

Use .toISOString() to get the ISO 8601 Date string:

const iso = day.toISOString()

console.log(iso)		// '2025-12-19'

Use .toDate() to get a JavaScript Date object (set to midnight UTC):

const date = day.toDate()