Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public shouldRoll(): boolean {
let lastTime = this.lastTimeWeWroteSomething,
thisTime = format.asString(this.pattern, new Date(this.now()));
debug("DateRollingFileStream.shouldRoll with now = " +
this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
this.lastTimeWeWroteSomething = thisTime;
this.previousTime = lastTime;
return thisTime !== lastTime;
}
this.filename = filename;
this.options = options || { encoding: "utf8", mode: parseInt("0644", 8), flags: "a" };
debug("Now is " + now);
if (pattern && typeof (pattern) === "object") {
now = options;
options = pattern;
pattern = null;
}
this.pattern = pattern || ".yyyy-MM-dd";
this.now = now || Date.now;
if (fs.existsSync(filename)) {
let stat = fs.statSync(filename);
this.lastTimeWeWroteSomething = format.asString(this.pattern, stat.mtime);
} else {
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
}
this.baseFilename = filename;
this.alwaysIncludePattern = false;
if (options) {
if (options.alwaysIncludePattern) {
this.alwaysIncludePattern = true;
filename = this.baseFilename + this.lastTimeWeWroteSomething;
}
delete options.alwaysIncludePattern;
if (Object.keys(options).length === 0) {
options = null;
}
this.options = options || { encoding: "utf8", mode: parseInt("0644", 8), flags: "a" };
debug("Now is " + now);
if (pattern && typeof (pattern) === "object") {
now = options;
options = pattern;
pattern = null;
}
this.pattern = pattern || ".yyyy-MM-dd";
this.now = now || Date.now;
if (fs.existsSync(filename)) {
let stat = fs.statSync(filename);
this.lastTimeWeWroteSomething = format.asString(this.pattern, stat.mtime);
} else {
this.lastTimeWeWroteSomething = format.asString(this.pattern, new Date(this.now()));
}
this.baseFilename = filename;
this.alwaysIncludePattern = false;
if (options) {
if (options.alwaysIncludePattern) {
this.alwaysIncludePattern = true;
filename = this.baseFilename + this.lastTimeWeWroteSomething;
}
delete options.alwaysIncludePattern;
if (Object.keys(options).length === 0) {
options = null;
}
}
debug("this.now is " + this.now + ", now is " + now);