Created
September 28, 2018 21:55
-
-
Save nbdd0121/da7c140af7afab74d7763f1a8fbae114 to your computer and use it in GitHub Desktop.
Bilibili Timeline Timezone Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let timezoneOffset = 8 * 60; // in minutes | |
function timeshift(date) { | |
return new Date(+date + timezoneOffset * 60000); | |
} | |
// Seconds and Milliseconds are always same as timezone offset is always multiple of 0.5 | |
for (let name of ['Date', 'Day', 'FullYear', 'Hours', 'Minutes', 'Month']) { | |
Date.prototype['get' + name] = function () { | |
return timeshift(this)['getUTC' + name](); | |
} | |
if (name === 'Day') continue; | |
Date.prototype['set' + name] = function (arg) { | |
let date = timeshift(this); | |
date['setUTC' + name](arg); | |
this.setTime(+date - timezoneOffset * 60000); | |
} | |
} | |
Date.prototype.getTimezoneOffset = function () { | |
return -timezoneOffset; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment