Skip to content

Commit 4f81c36

Browse files
committed
new Date() -> Date.now()
1 parent a927eb2 commit 4f81c36

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

js/server_functions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require("fs");
22
const path = require("path");
33
const Log = require("logger");
44

5-
const startUp = new Date();
5+
const startUp = Date.now();
66

77
/**
88
* Gets the config.

modules/default/calendar/calendar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ Module.register("calendar", {
400400
const timeWrapper = document.createElement("td");
401401

402402
eventWrapper.appendChild(titleWrapper);
403-
const now = new Date();
403+
const now = Date.now();
404404

405405
if (this.config.timeFormat === "absolute") {
406406
// Use dateFormat
@@ -573,7 +573,7 @@ Module.register("calendar", {
573573
const ONE_HOUR = ONE_MINUTE * 60;
574574
const ONE_DAY = ONE_HOUR * 24;
575575

576-
const now = new Date();
576+
const now = Date.now();
577577
const today = moment().startOf("day");
578578
const future = moment().startOf("day").add(this.config.maximumNumberOfDays, "days").toDate();
579579
let events = [];
@@ -906,7 +906,7 @@ Module.register("calendar", {
906906
}
907907
}, ONE_MINUTE);
908908
},
909-
ONE_MINUTE - (new Date() % ONE_MINUTE)
909+
ONE_MINUTE - (Date.now() % ONE_MINUTE)
910910
);
911911
}
912912
});

modules/default/calendar/calendarfetcherutils.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const CalendarFetcherUtils = {
6363
event.start.tz = "";
6464
Log.debug(`ical offset=${current_offset} date=${date}`);
6565
mm = moment(date);
66-
let x = parseInt(moment(new Date()).utcOffset());
66+
let x = parseInt(moment(Date.now()).utcOffset());
6767
Log.debug(`net mins=${current_offset * 60 - x}`);
6868

6969
mm = mm.add(x - current_offset * 60, "minutes");
@@ -141,7 +141,7 @@ const CalendarFetcherUtils = {
141141
Log.debug(`There are ${Object.entries(data).length} calendar entries.`);
142142
Object.entries(data).forEach(([key, event]) => {
143143
Log.debug("Processing entry...");
144-
const now = new Date();
144+
const now = Date.now();
145145
const today = moment().startOf("day").toDate();
146146
const future
147147
= moment()
@@ -323,7 +323,7 @@ const CalendarFetcherUtils = {
323323

324324
// Get the offset of today where we are processing
325325
// This will be the correction, we need to apply.
326-
let nowOffset = new Date().getTimezoneOffset();
326+
let nowOffset = Date.now().getTimezoneOffset();
327327
// For full day events, the time might be off from RRULE/Luxon problem
328328
// Get time zone offset of the rule calculated event
329329
let dateoffset = date.getTimezoneOffset();
@@ -479,7 +479,7 @@ const CalendarFetcherUtils = {
479479
}
480480
} else {
481481
// It's not a fullday event, and it is in the past, so skip.
482-
if (!fullDayEvent && endDate < new Date()) {
482+
if (!fullDayEvent && endDate < Date.now()) {
483483
return;
484484
}
485485

modules/default/calendar/calendarutils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const CalendarUtils = {
116116
if (typeof transform.yearmatchgroup !== "undefined" && transform.yearmatchgroup !== "") {
117117
const yearmatch = [...title.matchAll(needle)];
118118
if (yearmatch[0].length >= transform.yearmatchgroup + 1 && yearmatch[0][transform.yearmatchgroup] * 1 >= 1900) {
119-
let calcage = new Date().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
119+
let calcage = Date.now().getFullYear() - yearmatch[0][transform.yearmatchgroup] * 1;
120120
let searchstr = `$${transform.yearmatchgroup}`;
121121
replacement = replacement.replace(searchstr, calcage);
122122
}

modules/default/weather/providers/weatherbit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ WeatherProvider.register("weatherbit", {
9595
// Implement WeatherDay generator.
9696
generateWeatherDayFromCurrentWeather (currentWeatherData) {
9797
//Calculate TZ Offset and invert to convert Sunrise/Sunset times to Local
98-
const d = new Date();
98+
const d = Date.now();
9999
let tzOffset = d.getTimezoneOffset();
100100
tzOffset = tzOffset * -1;
101101

modules/default/weather/weatherobject.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class WeatherObject {
108108
* @param {number} lon longitude
109109
*/
110110
updateSunTime (lat, lon) {
111-
const now = !this.date ? new Date() : this.date.toDate();
111+
const now = !this.date ? Date.now() : this.date.toDate();
112112
const times = SunCalc.getTimes(now, lat, lon);
113113
this.sunrise = moment(times.sunrise);
114114
this.sunset = moment(times.sunset);

tests/unit/modules/default/calendar/calendar_utils_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe("Calendar utils tests", () => {
146146
describe("titleTransform with yearmatchgroup", () => {
147147
it("should replace the birthday and wrap nicely", () => {
148148
const transformedTitle = CalendarUtils.titleTransform("Luciella '2000", [{ search: "^([^']*) '(\\d{4})$", replace: "$1 ($2.)", yearmatchgroup: 2 }]);
149-
const expectedResult = `Luciella (${new Date().getFullYear() - 2000}.)`;
149+
const expectedResult = `Luciella (${Date.now().getFullYear() - 2000}.)`;
150150
expect(transformedTitle).toBe(expectedResult);
151151
});
152152
});

tests/unit/modules/default/utils_spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("Default modules utils tests", () => {
105105
});
106106

107107
describe("formatTime", () => {
108-
const time = new Date();
108+
const time = Date.now();
109109

110110
beforeEach(async () => {
111111
time.setHours(13, 13);

0 commit comments

Comments
 (0)