From d982c69e807006033796e63df636c628edaf74b1 Mon Sep 17 00:00:00 2001 From: "Stuart P. Bentley" Date: Fri, 3 May 2013 18:59:49 -0400 Subject: [PATCH] Parse colon-separated timestamps --- index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.js b/index.js index 192cd86..cd4adef 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var m = s * 60; var h = m * 60; var d = h * 24; var y = d * 365.25; +var order = ['s','m','h','d','y']; /** * Parse or format the given `val`. @@ -38,6 +39,11 @@ module.exports = function(val, options){ */ function parse(str) { + var segments = str.split(':'); + if(segments.length > 1) { + str = segments.map(function(t,i) { + return t + (order[segments.length-i - 1] || ':')}).join(''); + } var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str); if (!match) return; var n = parseFloat(match[1]);