Created
August 20, 2013 01:36
-
-
Save tleen/6276174 to your computer and use it in GitHub Desktop.
Using the moment.js time duration shorthand to get number of seconds from a string. Say the inputString is '3y' or '5M' or '2d', this would give you the respective time from now in seconds.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I don't love this but its a quick/dirty create of cache duration using moment's nice date add format | |
// parse cache duration as [integer][unit] via http://momentjs.com/docs/#/manipulating/add/ shorthand | |
var durations = /^([\d]+)([\w]+)/.exec(inputString); | |
var invalidateSeconds = moment(0).add(durations[2],durations[1]).unix(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment