Bugfixes: get the unit tests passing again
This commit is contained in:
parent
af69eddd1c
commit
435f4f320f
@ -57,6 +57,7 @@ exports.asString = function(/*format,*/ date, timezoneOffset) {
|
|||||||
var vSecond = addZero(date.getUTCSeconds());
|
var vSecond = addZero(date.getUTCSeconds());
|
||||||
var vMillisecond = padWithZeros(date.getUTCMilliseconds(), 3);
|
var vMillisecond = padWithZeros(date.getUTCMilliseconds(), 3);
|
||||||
var vTimeZone = offset(timezoneOffset);
|
var vTimeZone = offset(timezoneOffset);
|
||||||
|
date.setUTCMinutes(date.getUTCMinutes() + timezoneOffset);
|
||||||
var formatted = format
|
var formatted = format
|
||||||
.replace(/dd/g, vDay)
|
.replace(/dd/g, vDay)
|
||||||
.replace(/MM/g, vMonth)
|
.replace(/MM/g, vMonth)
|
||||||
|
@ -140,11 +140,12 @@ function messagePassThroughLayout (loggingEvent) {
|
|||||||
* Takes a pattern string, array of tokens and returns a layout function.
|
* Takes a pattern string, array of tokens and returns a layout function.
|
||||||
* @param {String} Log format pattern String
|
* @param {String} Log format pattern String
|
||||||
* @param {object} map object of different tokens
|
* @param {object} map object of different tokens
|
||||||
|
* @param {number} timezone offset in minutes
|
||||||
* @return {Function}
|
* @return {Function}
|
||||||
* @author Stephan Strittmatter
|
* @author Stephan Strittmatter
|
||||||
* @author Jan Schmidle
|
* @author Jan Schmidle
|
||||||
*/
|
*/
|
||||||
function patternLayout (pattern, tokens) {
|
function patternLayout (pattern, tokens, timezoneOffset) {
|
||||||
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
|
var TTCC_CONVERSION_PATTERN = "%r %p %c - %m%n";
|
||||||
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdhmnprzxy%])(\{([^\}]+)\})?|([^%]+)/;
|
var regex = /%(-?[0-9]+)?(\.?[0-9]+)?([\[\]cdhmnprzxy%])(\{([^\}]+)\})?|([^%]+)/;
|
||||||
|
|
||||||
@ -178,7 +179,7 @@ function patternLayout (pattern, tokens) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Format the date
|
// Format the date
|
||||||
return dateFormat.asString(format, loggingEvent.startTime);
|
return dateFormat.asString(format, loggingEvent.startTime, timezoneOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
function hostname() {
|
function hostname() {
|
||||||
@ -198,7 +199,7 @@ function patternLayout (pattern, tokens) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startTime(loggingEvent) {
|
function startTime(loggingEvent) {
|
||||||
return "" + loggingEvent.startTime.toLocaleTimeString();
|
return dateFormat.asString('hh:mm:ss', loggingEvent.startTime, timezoneOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startColour(loggingEvent) {
|
function startColour(loggingEvent) {
|
||||||
|
@ -3,11 +3,13 @@ var vows = require('vows')
|
|||||||
, assert = require('assert')
|
, assert = require('assert')
|
||||||
, dateFormat = require('../lib/date_format');
|
, dateFormat = require('../lib/date_format');
|
||||||
|
|
||||||
|
function createFixedDate() {
|
||||||
|
return new Date(2010, 0, 11, 14, 31, 30, 5);
|
||||||
|
}
|
||||||
|
|
||||||
vows.describe('date_format').addBatch({
|
vows.describe('date_format').addBatch({
|
||||||
'Date extensions': {
|
'Date extensions': {
|
||||||
topic: function() {
|
topic: createFixedDate,
|
||||||
return new Date(2010, 0, 11, 14, 31, 30, 5);
|
|
||||||
},
|
|
||||||
'should format a date as string using a pattern': function(date) {
|
'should format a date as string using a pattern': function(date) {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
dateFormat.asString(dateFormat.DATETIME_FORMAT, date),
|
dateFormat.asString(dateFormat.DATETIME_FORMAT, date),
|
||||||
@ -20,13 +22,16 @@ vows.describe('date_format').addBatch({
|
|||||||
'2010-01-11 14:31:30.005'
|
'2010-01-11 14:31:30.005'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'should provide a ISO8601 with timezone offset format': function(date) {
|
'should provide a ISO8601 with timezone offset format': function() {
|
||||||
|
var date = createFixedDate();
|
||||||
|
date.setMinutes(date.getMinutes() - date.getTimezoneOffset() - 660);
|
||||||
date.getTimezoneOffset = function() { return -660; };
|
date.getTimezoneOffset = function() { return -660; };
|
||||||
assert.equal(
|
assert.equal(
|
||||||
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
|
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
|
||||||
"2010-01-11T14:31:30+1100"
|
"2010-01-11T14:31:30+1100"
|
||||||
);
|
);
|
||||||
|
date = createFixedDate();
|
||||||
|
date.setMinutes(date.getMinutes() - date.getTimezoneOffset() + 120);
|
||||||
date.getTimezoneOffset = function() { return 120; };
|
date.getTimezoneOffset = function() { return 120; };
|
||||||
assert.equal(
|
assert.equal(
|
||||||
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
|
dateFormat.asString(dateFormat.ISO8601_WITH_TZ_OFFSET_FORMAT, date),
|
||||||
@ -40,7 +45,9 @@ vows.describe('date_format').addBatch({
|
|||||||
'14:31:30.005'
|
'14:31:30.005'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'should provide a custom format': function(date) {
|
'should provide a custom format': function() {
|
||||||
|
var date = createFixedDate();
|
||||||
|
date.setMinutes(date.getMinutes() - date.getTimezoneOffset() + 120);
|
||||||
date.getTimezoneOffset = function() { return 120; };
|
date.getTimezoneOffset = function() { return 120; };
|
||||||
assert.equal(
|
assert.equal(
|
||||||
dateFormat.asString("O.SSS.ss.mm.hh.dd.MM.yy", date),
|
dateFormat.asString("O.SSS.ss.mm.hh.dd.MM.yy", date),
|
||||||
|
@ -179,7 +179,7 @@ vows.describe('log4js layouts').addBatch({
|
|||||||
topic: function() {
|
topic: function() {
|
||||||
var event = {
|
var event = {
|
||||||
data: ['this is a test'],
|
data: ['this is a test'],
|
||||||
startTime: new Date(2010, 11, 5, 14, 18, 30, 45),
|
startTime: new Date('2010-12-05T14:18:30.045Z'), //new Date(2010, 11, 5, 14, 18, 30, 45),
|
||||||
categoryName: "multiple.levels.of.tests",
|
categoryName: "multiple.levels.of.tests",
|
||||||
level: {
|
level: {
|
||||||
toString: function() { return "DEBUG"; }
|
toString: function() { return "DEBUG"; }
|
||||||
|
Loading…
Reference in New Issue
Block a user