diff options
author | nea <romangraef@gmail.com> | 2021-08-19 23:41:53 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2021-08-19 23:41:53 +0200 |
commit | bb6202dcc3e96a97853a36e65da361c5a32d6dd4 (patch) | |
tree | 345127b3da4c8c8d1eb977307087ac9b8fccdb0b /transformation.jsx | |
parent | dc20f2ccb947b5bb2898a9989e8d38c937f97061 (diff) | |
download | powercord-timezone-bb6202dcc3e96a97853a36e65da361c5a32d6dd4.tar.gz powercord-timezone-bb6202dcc3e96a97853a36e65da361c5a32d6dd4.tar.bz2 powercord-timezone-bb6202dcc3e96a97853a36e65da361c5a32d6dd4.zip |
Diffstat (limited to 'transformation.jsx')
-rw-r--r-- | transformation.jsx | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/transformation.jsx b/transformation.jsx index a355f97..417a7df 100644 --- a/transformation.jsx +++ b/transformation.jsx @@ -1,5 +1,7 @@ const { splitSegments } = require('./util'); const { React } = require('powercord/webpack'); +const { open } = require('powercord/modal'); +const { getLabel } = require('./popup.jsx'); const { timezones, lookup @@ -8,30 +10,26 @@ const { const timezonePattern = new RegExp('(\\d+):(\\d+) *(' + timezones.map(it => `(?:${it.code})`).join('|') + ')', 'g'); function transformMessage (userTimezoneProvider, msgConstruct) { - if (!('content' in msgConstruct)) { - return msgConstruct; + if (!('content' in msgConstruct) || !('flatMap' in msgConstruct.content)) { + return msgConstruct; } return Object.assign({}, msgConstruct, { - content: msgConstruct.content.flatMap(it => transformPart(userTimezoneProvider, it)) + content: msgConstruct.content.flatMap(it => transformPart(userTimezoneProvider, it)) }); } function transformPart (userTimezoneProvider, part) { if (typeof part === 'string') { - return splitSegments(part, timezonePattern).map(it => { - if (typeof it === 'string') { - return it; - } - let [ _, hour, minute, tz ] = it.match; - let timezone = lookup(tz); - let time = hour * 60 + minute; - let userTimezone = userTimezoneProvider(); - let offset = userTimezone.offsetminutes - timezone.offsetminutes; - let adjusted = (time + offset) % (24 * 60); - return (<> - {hour}:{minute} {timezone.code} -> {adjusted / 60}:{adjusted % 60} {userTimezone.code} - </>); - }); + return splitSegments(part, timezonePattern).map(it => { + if (typeof it === 'string') { + return it; + } + let [ _, hour, minute, tz ] = it.match; + let timezone = lookup(tz); + let time = hour * 60 + minute; + let userTimezone = userTimezoneProvider(); + return getLabel(time, timezone, userTimezone); + }); } return [ part ]; } |