Socket
Socket
Sign inDemoInstall

moment-parser

Package Overview
Dependencies
4
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    moment-parser

moment parser that supports natural language expressions


Version published
Maintainers
3
Install size
5.39 MB
Created

Readme

Source

moment-parser

Build Status Join the chat at https://gitter.im/juttle/moment-parser

Natural language time parser for moment.js strings

Quick start

npm install moment-parser

var parser = require('moment-parser');

// durations
console.log(parser.parse('1 hour')); //{ type: 'MomentDuration', value: 1, unit: 'hour' }
console.log(parser.parseDuration('2 months and 1 day')); // a momentjs duration of { days: 1, months: 2 }

// moments
console.log(parser.parse('2015-01-01')); //{ type: 'ISODateLiteral', value: '2015-01-01T00:00:00' }
console.log(parser.parseMoment('day 5 of next month')); // a momentjs moment at the start of next month plus 4 days

More Examples In Tests

Running Unit Tests

npm test

More examples

(proper grammar docs coming soon!)

Absolute Moments

All times are UTC0 unless a time zone is specified by appending it to an ISO-8601 string. ​ ​

  • Midnight on a specific date (UTC0):
2014-09-21

2014-09-22T11:39:17.993

  • The same date and time, as Pacific Standard Time:
2014-09-22T03:39:17.993-08:00

Durations

  • One second, minute, hour, day, week, and so on:
second
minute
hour
day
week
month
year

​ Note that month and year are special "calendar" durations that do not have fixed length but instead advance whole months or years relative to a fixed moment. ​

  • Abbreviations for 0 seconds, 1 minute, 2 hours, 3 days, 4 weeks, 5 months, 6 years:
0s
1m
2h
3d
4w
5M
6y

  • Two ways to write one hour and twenty-three minutes:
 1 hour and 23 minutes
 01:23:00

  • Additional examples:
 1 second
 20 minutes

Relative Moments

  • The moment at which the program started running:
now

  • Midnight yesterday, today, or tomorrow:
yesterday
today
tomorrow

  • Seven hours after midnight on the current day:
07:00:00 after today

  • One minute from the start of the program's execution:
 1 minute from now

  • Shorter way to write 2 minutes from now:
+2m

  • Shorter way to write 1 hour and 10 minutes before now:
-01:10:00

  • Now minus 72 hours:
 3 days ago

  • Now minus 22 days:
 3 weeks and 1 day ago

  • Midnight of the first day of the current calendar month:
this month

  • Midnight of the first day of the previous calendar month:
last month

  • Midnight of the 20th day of the previous calendar month:
day 20 of last month

  • The minute in which the program began executing:
this minute

  • The next even hour after the start of the program's execution:
next hour

  • The day in which the program began executing:
this day
today

  • The day before the day in which the program began executing:
last day
yesterday

Keywords

FAQs

Last updated on 05 Jan 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc