mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
refactor: timezone conversion in lib/utils/date.js (#7438)
This commit is contained in:
14
lib/utils/timezone.js
Normal file
14
lib/utils/timezone.js
Normal file
@@ -0,0 +1,14 @@
|
||||
const assert = require("assert").strict;
|
||||
|
||||
const millisInAnHour = 60 * 60 * 1000;
|
||||
const serverTimezone = -new Date().getTimezoneOffset() / 60;
|
||||
|
||||
module.exports = (date, timezone = serverTimezone) => {
|
||||
if (typeof (date) === "string" || date instanceof String) {
|
||||
date = new Date(date);
|
||||
}
|
||||
|
||||
assert(date instanceof Date);
|
||||
|
||||
return new Date(date.getTime() - millisInAnHour * (timezone - serverTimezone));
|
||||
};
|
||||
Reference in New Issue
Block a user