Comparing version 3.0.146 to 3.0.147
{ | ||
"name": "fable", | ||
"version": "3.0.146", | ||
"version": "3.0.147", | ||
"description": "A service dependency injection, configuration and logging library.", | ||
@@ -5,0 +5,0 @@ "main": "source/Fable.js", |
@@ -313,3 +313,23 @@ /** | ||
return false; | ||
} | ||
} | ||
/** | ||
* Generate a safe string to use in filenames for a date. Useful for log file uniqueness and temporary outputs. | ||
* | ||
* @static | ||
* @param {Date} pDate - An optional javascript Date object to generate a datestamp for. | ||
* @returns {string} - A string formatted as YYYY-MM-DD-HH-MM-SS | ||
*/ | ||
static generateFileNameDateStamp(pDate) | ||
{ | ||
const tmpDate = pDate || new Date(); | ||
const tmpYear = tmpDate.getFullYear(); | ||
const tmpMonth = String(tmpDate.getMonth() + 1).padStart(2, '0'); | ||
const tmpDay = String(tmpDate.getDate()).padStart(2, '0'); | ||
const tmpHour = String(tmpDate.getHours()).padStart(2, '0'); | ||
const tmpMinute = String(tmpDate.getMinutes()).padStart(2, '0'); | ||
const tmpSecond = String(tmpDate.getSeconds()).padStart(2, '0'); | ||
return `${tmpYear}-${tmpMonth}-${tmpDay}-${tmpHour}-${tmpMinute}-${tmpSecond}`; | ||
} | ||
} | ||
@@ -316,0 +336,0 @@ |
@@ -71,2 +71,13 @@ /** | ||
( | ||
'The static date stamp should work.', | ||
function() | ||
{ | ||
let tmpDateStamp = libFable.generateFileNameDateStamp(); | ||
Expect(tmpDateStamp).to.be.a('string'); | ||
Expect(tmpDateStamp.length).to.equal(19); | ||
Expect(tmpDateStamp).to.match(/^\d{4}-\d{2}-\d{2}-\d{2}-\d{2}-\d{2}$/); | ||
} | ||
); | ||
test | ||
( | ||
'Logging should happen...', | ||
@@ -73,0 +84,0 @@ function(fDone) |
6892191
17235