Neatly Packaged Magic

    relative-time-parser

    1.0.15 • Public • Published

    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

    Install

    npm i relative-time-parser

    DownloadsWeekly Downloads

    246

    Version

    1.0.15

    License

    MIT

    Unpacked Size

    37 kB

    Total Files

    12

    Last publish

    Collaborators

    • cmaurer