Parse a grafana-inspired relative date notation into momentjs instances. Where
"relative" means: relative to
Pass in a string in
moment-relativism's relative date notation.
var moment = ;var result = moment;// logs "Thu Aug 04 2016 16:03:28 GMT+0200" when now is "Thu Aug 11 2016 16:03:28 GMT+0200"console;
You can also pass in an object.
moment.relativism will return an object of
the same structure (same fields), but with the values replaced with their
current momentjs equivalent instances.
var moment = ;// I want the date range for exactly the last 7 days (not rounded).var range =from: 'now-7d'to: 'now';var result = moment;// logs "Thu Aug 04 2016 16:03:28 GMT+0200" and "Thu Aug 11 2016 16:03:28 GMT+0200"console;
Check out the
tests directory for more detailed usage.
moment-relativism's notation is based on grafana's relative date parser.
However, grafana's notation does not provide a way to distinguish between
rounding up or rounding down. Instead the rounding character
/ is rounded up
or down based on the context the string is used in. If the string is used as a
"from" date in a date range, it rounds down. Otherwise it rounds down.
moment-relativism differs here, as it adds a
| character for rounding
/ is always used for rounding up.
When adding, subtracting and rounding you can use
moment's shorthand keys
for years, days, etc as found in
||Add one day to now|
||Subtract one day from now|
||Add one day to now, round up to end of day|
||Subtract one day from now, round down to start of day|
||Just returns the date corresponding to now|
||Rounds up to todays end of day.|
||Rounds down to todays start of day.|
This software is copyrighted by Advanced Climate Systems bv, and released under
the Mozilla Public License v2.0. See the
LICENSE file for the entire license.