From 89b645b33477d7f1a83813bf9478833f5fe93593 Mon Sep 17 00:00:00 2001 From: Jiiks Date: Sat, 25 Aug 2018 15:57:29 +0300 Subject: [PATCH] 24hour refactor to use new builtin base --- client/src/builtin/24Hour.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/client/src/builtin/24Hour.js b/client/src/builtin/24Hour.js index 1fc794c1..5d2ee577 100644 --- a/client/src/builtin/24Hour.js +++ b/client/src/builtin/24Hour.js @@ -15,23 +15,20 @@ const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`); export default new class TwentyFourHour extends BuiltinModule { - get settingPath() { - return ['ui', 'default', '24-hour']; - } + get settingPath() { return ['ui', 'default', '24-hour'] } + get moduleName() { return 'TwentyFourHour' } - async enabled(e) { - if (Patcher.getPatchesByCaller('BD:TwentyFourHour').length) return; + applyPatches() { + if (this.patches.length) return; const { TimeFormatter } = Reflection.modules; - MonkeyPatch('BD:TwentyFourHour', TimeFormatter).after('calendarFormat', (thisObject, args, returnValue) => { - const matched = returnValue.match(twelveHour); - if (!matched || matched.length != 4) return; - if (matched[3] == 'AM') return returnValue.replace(matched[0], `${matched[1] == '12' ? '00' : matched[1].padStart(2, '0')}:${matched[2]}`) - return returnValue.replace(matched[0], `${parseInt(matched[1]) + 12}:${matched[2]}`) - }); + this.patch(TimeFormatter, 'calendarFormat', this.convertTimeStamps); } - disabled(e) { - Patcher.unpatchAll('BD:TwentyFourHour'); + convertTimeStamps(that, args, returnValue) { + const matched = returnValue.match(twelveHour); + if (!matched || matched.length !== 4) return; + if (matched[3] === 'AM') return returnValue.replace(matched[0], `${matched[1] === '12' ? '00' : matched[1].padStart(2, '0')}:${matched[2]}`) + return returnValue.replace(matched[0], `${parseInt(matched[1]) + 12}:${matched[2]}`) } - + }