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 🙏

© 2024 – Pkg Stats / Ryan Hefner

relative-time-parser

v1.0.15

Published

A moment.js plugin to convert relative time string into a moment.js object

Downloads

819

Readme

Relative Time Parser Plugin for Moment.js

This plugin converts a simple string to a manipulated moment object. The string format is inspired by Graphite's relative time format.

Badges

NPM npm downloads Build Status Dependency Status devDependency Status Maintainability Test Coverage Known Vulnerabilities

Install - NPM

npm install relative-time-parser

Usage

Using the string -7d would be equivalent of moment().subtract(7, 'days');, and similarly, using the string +7d would be equivalent of moment().add(7, 'days');. The specific abbreviations are listed in the table below.

var moment = require('relative-time-parser');
moment().relativeTime('-6h').format();

Patterns

ms - milliseconds

subtract milliseconds
moment().relativeTime('-6ms');
add milliseconds
moment().relativeTime('+6ms');

s - seconds

subtract seconds
moment().relativeTime('-6s');
add seconds
moment().relativeTime('+6s');

sec - seconds

subtract seconds
moment().relativeTime('-6sec');
add seconds
moment().relativeTime('+6sec');

second - seconds

subtract seconds
moment().relativeTime('-6second');
add seconds
moment().relativeTime('+6second');

seconds - seconds

subtract seconds
moment().relativeTime('-6seconds');
add seconds
moment().relativeTime('+6seconds');

m - minutes

subtract minutes
moment().relativeTime('-6m');
add minutes
moment().relativeTime('+6m');

min - minutes

subtract minutes
moment().relativeTime('-6min');
add minutes
moment().relativeTime('+6min');

minute - minutes

subtract minutes
moment().relativeTime('-6minute');
add minutes
moment().relativeTime('+6minute');

minutes - minutes

subtract minutes
moment().relativeTime('-6minutes');
add minutes
moment().relativeTime('+6minutes');

h - hours

subtract hours
moment().relativeTime('-6h');
add hours
moment().relativeTime('+6h');

hour - hours

subtract hours
moment().relativeTime('-6hour');
add hours
moment().relativeTime('+6hour');

hours - hours

subtract hours
moment().relativeTime('-6hours');
add hours
moment().relativeTime('+6hours');

d - days

subtract days
moment().relativeTime('-6d');
add days
moment().relativeTime('+6d');

day - days

subtract days
moment().relativeTime('-6day');
add days
moment().relativeTime('+6day');

w - weeks

subtract weeks
moment().relativeTime('-6w');
add weeks
moment().relativeTime('+6w');

week - weeks

subtract weeks
moment().relativeTime('-6week');
add weeks
moment().relativeTime('+6week');

weeks - weeks

subtract weeks
moment().relativeTime('-6weeks');
add weeks
moment().relativeTime('+6weeks');

mon - months

subtract months
moment().relativeTime('-6mon');
add months
moment().relativeTime('+6mon');

month - months

subtract months
moment().relativeTime('-6month');
add months
moment().relativeTime('+6month');

months - months

subtract months
moment().relativeTime('-6months');
add months
moment().relativeTime('+6months');

M - months

subtract months
moment().relativeTime('-6M');
add months
moment().relativeTime('+6M');

Q - quarters

subtract quarters
moment().relativeTime('-6Q');
add quarters
moment().relativeTime('+6Q');

Quarter - quarters

subtract quarters
moment().relativeTime('-6Quarter');
add quarters
moment().relativeTime('+6Quarter');

Quarters - quarters

subtract quarters
moment().relativeTime('-6Quarters');
add quarters
moment().relativeTime('+6Quarters');

y - years

subtract years
moment().relativeTime('-6y');
add years
moment().relativeTime('+6y');

year - years

subtract years
moment().relativeTime('-6year');
add years
moment().relativeTime('+6year');

years - years

subtract years
moment().relativeTime('-6years');
add years
moment().relativeTime('+6years');

now - now

moment().relativeTime('now');

Is Relative Time String Format

Tests a String to determine if it is in the RelativeTimeFormat

moment().isRelativeTimeFormat('-2y'); // should === true
moment().isRelativeTimeFormat('xxx'); // should === false
moment().isRelativeTimeFormat('now'); // should === true

Resources

Graphite URL Api Reference