Skip to content

Commit 13735d6

Browse files
KrayzeeKevmattberther
authored andcommitted
Add localTime option (#52)
1 parent e08086d commit 13735d6

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

index.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var DailyRotateFile = module.exports = function (options) {
7777
this.eol = options.eol || os.EOL;
7878
this.maxRetries = options.maxRetries || 2;
7979
this.prepend = options.prepend || false;
80+
this.localTime = options.localTime || false;
8081

8182
if (this.json) {
8283
this.stringify = options.stringify;
@@ -122,13 +123,21 @@ var DailyRotateFile = module.exports = function (options) {
122123
}.bind(this)();
123124

124125
var now = new Date();
125-
this._year = now.getUTCFullYear();
126-
this._month = now.getUTCMonth();
127-
this._date = now.getUTCDate();
128-
this._hour = now.getUTCHours();
129-
this._minute = now.getUTCMinutes();
130-
this._weekday = weekday[now.getUTCDay()];
131-
126+
if (this.localTime) {
127+
this._year = now.getFullYear();
128+
this._month = now.getMonth();
129+
this._date = now.getDate();
130+
this._hour = now.getHours();
131+
this._minute = now.getMinutes();
132+
this._weekday = weekday[now.getDay()];
133+
} else {
134+
this._year = now.getUTCFullYear();
135+
this._month = now.getUTCMonth();
136+
this._date = now.getUTCDate();
137+
this._hour = now.getUTCHours();
138+
this._minute = now.getUTCMinutes();
139+
this._weekday = weekday[now.getUTCDay()];
140+
}
132141
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhM])\1?/g;
133142
var pad = function (val, len) {
134143
val = String(val);

test/simple.tests.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ describe('winston/transports/daily-rotate-file', function () {
5454
expect(transport._getFilename()).to.equal('prepend-false.log.' + now);
5555
});
5656

57+
it('should have a proper filename when prepend option is false (localtime)', function () {
58+
var now = moment().format('YYYY-MM-DD');
59+
var transport = new DailyRotateFile({
60+
filename: path.join(fixturesDir, 'prepend-false.log'),
61+
localTime: true,
62+
prepend: false
63+
});
64+
65+
expect(transport._getFilename()).to.equal('prepend-false.log.' + now);
66+
});
67+
5768
it('should have a proper filename when prepend options is true', function () {
5869
var now = moment().utc().format('YYYY-MM-DD');
5970
var transport = new DailyRotateFile({

0 commit comments

Comments
 (0)