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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rdf-ts

v0.0.4

Published

A typescript library for resolving Relative Date Format (RDF) strings into UNIX values

Readme

range-builder

A typescript library for resolving Relative Date Format (RDF) strings into UNIX values

What is Relative Date Format?

Relative date format is a string based format that encodes a variety of range based time concepts. It provides a structured language to represent as a single string ideas such as;

  • "the last 3 weeks from today"
  • "this quarter"
  • "from Jan 2 until now"

RDF was created to fill the need for a universal expression of relative date range concepts in a succinct manner. Every valid RDF string resolves to a pair of UNIX timestamps which indicate the start and end of the encoded range, relative to the current time.

How does it work?

An RDF string always consists of 3 or more fields, each seperated by a $ symbol. The first field indicates the handler, while the second and third field provide arguments which the handler will use to create the start and end timestamps which together represent a range.

The handler determines how the argument fields will be interpreted, while the argument fields provide either relative or absolute times that are used to resolve the final range.

RDF also provides a number of tokens that represent familiar time related concepts such as intervals of time (days, weeks, months, etc...) and now.

Handlers

Range ( $range$[start]$[end]$ )

The range handler calculates a start and end time in unix given a start and end time in unix. This handler is the most direct representation of a date range.

Examples:

  • "Jan 1, 1970 00:00 until July 7 2019, 12:57:41" -> "$range$0$1562355886$"
  • "July 7 2019, 12:57:41 until now" -> "$range$1562355886$now$"
  • "Two weeks ago until one week ago" -> $range$now-2w$now-1w$"

Trail ( $trail$[end]$[period]$ )

The trail handler calculates a start and end time in unix given a end time and a time period. The start time is calculated as [end] - [period].

Examples:

  • "The last 3 weeks" -> "$trail$now$3w$"
  • "2 days before July 7 2019, 12:57:41" -> $trail$1562355886$2d$"
  • "The last 5 seconds" -> "$trail$now$5$

Period ( $period$[start]$[period]$[ref (optional; defaults to 'now')]$ )

The period handler calculates a start and end date that starts at the beginning of the period occupied by ref and ends at the end of said period.

This is useful for cases such as when you want a range to reset to never represent more than a single (day/month/quarter/year).

Rollover will always occur according to the interval provided:

  • x days - Period will rollover after x days, at the same time of day as the start time provided
  • x weeks - Period will rollover after x weeks, on the same day of the week at the same time of day as the start time provided
  • x months - Period will rollover after x months, on the same date of the month at the same time of day as the start time provided. If the date of the month is not valid (rollover is on the 30th of every 2nd month, but February only has 28 days, rollover will occur on the latest valid day of that month)
  • x quarters - Period will rollover after x quarters , on the same date of the month at the same time of day as the start time provided. If the date of the month is not valid (rollover is on the 30th of every 2nd month, but February only has 28 days, rollover will occur on the latest valid day of that month). A quarter is defined to last 3 months and always start on the same date of the month, following the same rules for invalid rollover dates such as February 30th.

The period will be calculated both backwards and forwards from the provided start date, so start times in the future remain valid

Examples:

  • "From the first of the month at 5:00am until now" -> "$period$1562000400$1M$"
  • "From Jan 3 of the last even number year at 7:31pm until now" -> "$period$1515007860$2Y$"
  • "This quarter (quarter starts Jan 1 and on the first of every 3 months at 00:00am)" -> "$period$1514764800000$1Q$"
  • "Last quarter (quarter starts Jan 1 and on the first of every 3 months at 00:00am)" -> "$period$1514764800000$1Q$now-1Q$"
  • "The year that a reference exactly one month ago was in" -> "$period$1514764800000$1Y$now-1m$"

Tokens

RDF exposes a set of tokens to represent common time centred concepts such as seconds, months, quarters, etc... These tokens do not directly represent a specific duration of time, but rather fluxuates based on the length of the last valid interval.

Addition is indicated with the + symbol, while subtraction is indicated with the - symbol.

Supported Tokens;

  • now - The current UNIX timestamp at time of resolution
  • s - Seconds
  • m - Minutes
  • h - Hours
  • d - Days
  • M - The period between the current date of this month and the month before (~30 days)
  • Y - The period between the current date of this year and the year before (~365 days)
  • Q - The period between the current date of this quarter and the quarter before (~91 days)

Operators

Using operators, it is possible to add or subract both absolute and token based times.

Capitalized tokens are relative to the current time and as such can not be compared using operators.

Examples:

  • "2 hours before July 7 2019, 12:57:41" -> 1562355886-2h
  • "2 hours after July 7 2019, 12:57:41" -> 1562355886+2h
  • "Two hours longer than a quarter" -> 1Q+2h (note that the duration of a quarter depends on the given start date and current time)
  • "Two hours and 15 minutes" -> 2h+15m