tz fix + allow spaces

0 is falsy, who would have thunk. Will now accept spaces like "UTC - 7" because people do write like this.
This commit is contained in:
Mute 2022-11-10 12:07:51 +00:00
parent 1cc9ac18d7
commit 247c908f46

View File

@ -39,7 +39,7 @@
RE_PREF_ACTIVITY_ME: /^@/, RE_PREF_ACTIVITY_ME: /^@/,
RE_PREF_ACTIVITY: /^@@/, RE_PREF_ACTIVITY: /^@@/,
RE_ACT_CIDS: /^<(\d+)?:(\d+)?>/, RE_ACT_CIDS: /^<(\d+)?:(\d+)?>/,
RE_TZ: /(?:GMT|UTC)([+-]\d\d?)/i, RE_TZ: /(?:GMT|UTC)\s*([+-])\s*(\d\d?)/i,
RE_ALL_LEFT: /^<+$/, RE_ALL_LEFT: /^<+$/,
RE_ALL_RIGHT: /^>+$/, RE_ALL_RIGHT: /^>+$/,
RE_SPACES: /\s{2,}/g, RE_SPACES: /\s{2,}/g,
@ -385,10 +385,11 @@
return(false) return(false)
}, },
find_timezone: function(char) { find_timezone: function(char) {
let timezones = this.settings("timezones") const timezones = this.settings("timezones")
if (timezones && timezones[char.cid]) return(timezones[char.cid]) if (timezones && "number" === typeof timezones[char.cid]) return(timezones[char.cid])
let match = (char.Description) ? char.Description.match(this.RE_TZ) : null const match = (char.Description) ? char.Description.match(this.RE_TZ) : null
if (match) return(Number.parseInt(match[1])) const int = match ? Number.parseInt(match[1] + match[2]) : 42
if (this.in(int, -12, 12)) return(int)
return(null) return(null)
}, },
player_enters_room: function() { // or if the mod is loaded while player is in the room player_enters_room: function() { // or if the mod is loaded while player is in the room
@ -624,7 +625,7 @@
let colour = (C.MBCHC.VERSION === window.Player.MBCHC.VERSION) ? window.MBCHC.RGB_POLLY : window.MBCHC.RGB_MUTE let colour = (C.MBCHC.VERSION === window.Player.MBCHC.VERSION) ? window.MBCHC.RGB_POLLY : window.MBCHC.RGB_MUTE
window.DrawRect(CharX + 175 * Zoom, CharY, 50 * Zoom, 50 * Zoom, colour) window.DrawRect(CharX + 175 * Zoom, CharY, 50 * Zoom, 50 * Zoom, colour)
} }
if ((window.ChatRoomHideIconState < 1) && C.MBCHC_LOCAL && C.MBCHC_LOCAL.TZ) { if ((window.ChatRoomHideIconState < 1) && C.MBCHC_LOCAL && "number" === typeof C.MBCHC_LOCAL.TZ) {
let hours = new Date(window.CommonTime() + window.MBCHC.UTC_OFFSET + C.MBCHC_LOCAL.TZ * 60 * 60 * 1000).getHours() let hours = new Date(window.CommonTime() + window.MBCHC.UTC_OFFSET + C.MBCHC_LOCAL.TZ * 60 * 60 * 1000).getHours()
let text = (hours < 10) ? "0" + hours.toString() : hours.toString() let text = (hours < 10) ? "0" + hours.toString() : hours.toString()
window.DrawTextFit(text, CharX + 200 * Zoom, CharY + 25 * Zoom, 46 * Zoom, "white", "black") window.DrawTextFit(text, CharX + 200 * Zoom, CharY + 25 * Zoom, 46 * Zoom, "white", "black")