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

cftime-ts

v0.1.1

Published

TypeScript implementation of CF-convention calendar datetimes (a port of Python cftime): num2date, date2num, and nine CF calendars.

Readme

cftime-ts

A TypeScript implementation of CF-convention calendar datetimes — a faithful port of the Python cftime library. Zero runtime dependencies, ESM, works in Node and the browser.

It provides the nine CF calendars — standard/gregorian, proleptic_gregorian, julian, tai, noleap/365_day, all_leap/366_day, 360_day — and the netCDF time-encoding functions num2date / date2num, with the same calendar arithmetic, Julian-day handling, 1582 Gregorian-reform gap, and year-zero conventions as the Python original.

Status: early development (0.1.0). API may change before 1.0.

Install

npm install cftime-ts

Usage

import { num2date, date2num, CFDatetime, Timedelta } from "cftime-ts";

// Decode numeric netCDF time values to dates
const d = num2date(0, "days since 2000-01-01", { calendar: "noleap" });
d.isoformat(" "); // "2000-01-01 00:00:00"

// Encode dates back to numbers
date2num(new CFDatetime(2000, 1, 2, 0, 0, 0, 0, { calendar: "noleap" }), "days since 2000-01-01");
// 1

// Calendar-aware arithmetic (JS has no operator overloading, so use methods)
const later = d.add(new Timedelta({ days: 400 }));
const gap = later.sub(d); // a Timedelta

// Comparison across calendars converts automatically
const g = new CFDatetime(1858, 11, 17, 0, 0, 0, 0, { calendar: "proleptic_gregorian" });
g.equals(g.changeCalendar("julian")); // true

Arrays are supported element-wise:

const dates = num2date([0, 1, 2], "days since 2000-01-01", { calendar: "standard" });
// CFDatetime[]  (NaN / Infinity decode to null)

API

  • CFDatetime (aliased datetime) — the calendar-aware datetime. Properties yearmicrosecond, dayofwk (0=Mon), dayofyr, daysinmonth; methods isoformat, strftime, toordinal, static fromordinal, changeCalendar, replace, add, sub, equals/compareTo/isBefore/isAfter, static strptime.
  • Legacy subclasses DatetimeNoLeap, DatetimeAllLeap, Datetime360Day, DatetimeJulian, DatetimeGregorian, DatetimeProlepticGregorian, DatetimeTAI.
  • num2date, date2num, num2pydate — netCDF ⇄ datetime conversion.
  • date2index, time2index — locate indices in a monotonic time axis (exact/before/after/nearest).
  • isLeapYear, Timedelta, strptime, dateparse, parseDate, UNIT_CONVERSION_FACTORS.

Differences from Python cftime

  • Numeric time values are JS number (float64), mirroring Python's "int when exact, float otherwise"; microsecond precision degrades beyond a few hundred years, as in Python without longdouble.
  • Arithmetic and comparison are methods (.add, .sub, .equals, .compareTo) since JS has no operator overloading.
  • Array inputs are plain JS arrays (per element); numpy masked/typed-array machinery is not reproduced. Non-finite values decode to null.

Development

npm install
npm test            # vitest
npm run typecheck
npm run build       # tsc -> dist/

The test suite is differential: scripts/gen_reference.py generates test/fixtures/reference.json from the real Python cftime, and the tests assert the port reproduces those values exactly.

License

MIT. Port of Python cftime (Copyright 2008 Jeffrey Whitaker). See LICENSE.