diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:10:37 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-24 15:11:17 +0200 |
commit | 7a3df06eb573d36142bd1a8e03c5ce8752d300b3 (patch) | |
tree | 70bfaea8884c374876f607774850a3a51c0cb381 /node_modules/time-stamp/index.js | |
parent | aca1143cb9eed16cf37f04e475e4257418dd18ac (diff) |
fix build issues and add typedoc
Diffstat (limited to 'node_modules/time-stamp/index.js')
-rw-r--r-- | node_modules/time-stamp/index.js | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/node_modules/time-stamp/index.js b/node_modules/time-stamp/index.js index 1a400adc1..0c9304825 100644 --- a/node_modules/time-stamp/index.js +++ b/node_modules/time-stamp/index.js @@ -1,8 +1,8 @@ /*! * time-stamp <https://github.com/jonschlinkert/time-stamp> * - * Copyright (c) 2015, Jon Schlinkert. - * Licensed under the MIT License. + * Copyright (c) 2015-2017, Jon Schlinkert. + * Released under the MIT License. */ 'use strict'; @@ -16,32 +16,41 @@ * @return {String} */ -module.exports = function timestamp(pattern, date) { +module.exports = function(pattern, date) { if (typeof pattern !== 'string') { date = pattern; pattern = 'YYYY:MM:DD'; } - date = date || new Date(); - return pattern.replace(/([YMDHms]{2,4})(:\/)?/g, function(_, key, sep) { - var increment = method(key); - if (!increment) return _; - sep = sep || ''; - - var res = '00' + String(date[increment[0]]() + (increment[2] || 0)); - return res.slice(-increment[1]) + sep; - }); + + if (!date) date = new Date(); + + function timestamp() { + var regex = /(?=(YYYY|YY|MM|DD|HH|mm|ss|ms))\1([:\/]*)/; + var match = regex.exec(pattern); + + if (match) { + var increment = method(match[1]); + var val = '00' + String(date[increment[0]]() + (increment[2] || 0)); + var res = val.slice(-increment[1]) + (match[2] || ''); + pattern = pattern.replace(match[0], res); + timestamp(); + } + } + + timestamp(pattern); + return pattern; }; function method(key) { return ({ - YYYY: ['getFullYear', 4], - YY: ['getFullYear', 2], - // getMonth is zero-based, thus the extra increment field - MM: ['getMonth', 2, 1], - DD: ['getDate', 2], - HH: ['getHours', 2], - mm: ['getMinutes', 2], - ss: ['getSeconds', 2], - ms: ['getMilliseconds', 3] + YYYY: ['getFullYear', 4], + YY: ['getFullYear', 2], + // getMonth is zero-based, thus the extra increment field + MM: ['getMonth', 2, 1], + DD: ['getDate', 2], + HH: ['getHours', 2], + mm: ['getMinutes', 2], + ss: ['getSeconds', 2], + ms: ['getMilliseconds', 3] })[key]; } |