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

chrono-40k

v1.0.1

Published

A consistent dating system for 'Warhammer 40,000'

Downloads

4

Readme

Chrono 40k

A consistent dating system for "Warhammer 40,000"

If you are not familiar with the imperial dating system in Warhammer 40k please consider to first take a look at https://warhammer40k.fandom.com/wiki/Imperial_Dating_System.

I intentionally diverge from the calculation of the year fraction or chronosegments, more on that in the remark section.

Usage

Installation

Install using npm:

npm i chrono-40k

Basic usage:

Get imperial representations of Date:

import { Chrono, Formats } from 'chrono-40k';

Chrono.classic.format(new Date());
// returns something like "0 227 025.M3"

Chrono.classic.format(new Date(), Formats.CLASSIC_SHORT_FORMAT);
// returns something like "025.M3"

Chrono.indomitus.format(new Date());
// returns something like "974.773 previo TCM.M3"

Chrono.indomitus.format(new Date(), Formats.INDOMITUS_ERA_SHORT_FORMAT);
// returns something like "974.773- TCM.M3"

Get Dates for imperial dates:

let date: Date = Chrono.classic.parse('005.M30').toDate();
// or
date = Chrono.classic.toTerranDate('005.M30');

Use imperial date objects:

const classicDate = Chrono.classic.parse(new Date());

console.log(classicDate.toString());
const date: Date = classicDate.toDate();

const indomitusDate = Chrono.indomitus.parse(classicDate);

Use short access to imperial dates:

let classicDate = Chrono.classic.parse(new Date());
// equals
classicDate = Chrono.parse(new Date());

console.log(Chrono.classic.format(new Date()));
// equals
console.log(Chrono.format(new Date()));

// etc.

Advanced usage

Convert from one imperial dating system the other:

const classicDate = Chrono.classic.parse('0 899 998.M41');
console.log(Chrono.indomitus.format(classicDate));
// outputs "1.101 previo TCM.M42"

Custom formatting

Chrono.classic automatically recognizes imperial dates in the formats

  • c fff yyy.m (Formats.CLASSIC_DEFAULT_FORMAT)
    e. g. "0 550 899.M41" and
  • yyy.m (Formats.CLASSIC_SHORT_FORMAT)
    e. g. "005.M30"

where c = check number, f = year fraction, y = year and m = millenium.

Chrono.indomitus automatically recognizes imperial dates into the formats

  • y.f gg d.m (Formats.INDOMITUS_ERA_DEFAULT_FORMAT)
    e. g. "1.1 previo TCM.M41" and
  • y.fg d.m (Formats.INDOMITUS_ERA_SHOR_FORMAT)
    e. g. "0.110+ TCM.M42"

where y = annual designator, f = chronosegments, g/gg = +/- or post/previo opening of the Cicatrix Maledictum, d = designator initials and m = millenium.

If needed, a custom format can be provided to any method that parses or formats and imperial date string:

Chrono.classic.parse('0123456  M7', 'cfffyyy m');
Chrono.classic.format(new Date(), 'yyy,m');

For more examples please take a look at the chrono.spec.ts

Remark

I intentionally diverge from the calculation of the year fraction (and the respective chronosegments in the "Era Indomitus" dating system) as I see a problem with the lore accurate calculation.

Problem

The first issue is that the fixed Makr constant does not take into account leap years. We need at least one "default" constant and one for leap years.

The second and more fundamental issue is that, even when not considering leap years, the calculation with the Makr constant just does not work.

E. g. calculate the year fractions for December 31, 2025 at 10 pm. December 31st is day number 365 of the year 2025 and 10pm is the 22th hour of that day so we calculate 365 * 24 + 22 = 8782. Then we multiply that with the Makr constant 8782 * 0.11407955 = 1001.84661 and round down the result to get the year fraction = 1001.

This is a problematic result as we just have 1000 year fractions in a year, so even when resolving this problem by just capping the result at 1000 we do not get a consistent way to calculate dates in both directions.

Solution

In my calculation I replace the Makr constant with two variations of the new Marco constant, one "default" and one for leap years.

marco_constant_default = 1 / ( ( 365 * 24 ) / 1000 )
marco_constant_leap_year = 1 / ( ( 366 * 24 ) / 1000 )

With theses adjustments the dating system does not work lore accurate anymore but it allows for a consistent conversion between gregorian and imperial dates.

Copyright

This software is completely unofficial and in no way endorsed by Games Workshop Ltd.