Simp-O-Matic

Dumb Discord bot in TS.
git clone git://git.knutsen.co/Simp-O-Matic
Log | Files | Refs | README | LICENSE

commit 198fa6084912877920e0a7b393ba4bb1d5759263
parent b9d8b77f74e0689532497466d464d4b6a629a7c8
Author: Demonstrandum <moi@knutsen.co>
Date:   Mon, 23 Mar 2020 13:49:27 +0000

Deal with fractional-houred time-zones.

Diffstat:
Mlib/commands/weather.ts | 9+++++++--
Mlib/extensions.ts | 5+++++
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/lib/commands/weather.ts b/lib/commands/weather.ts @@ -26,8 +26,13 @@ export default (home_scope: HomeScope) => { .then(res => res.json()) .then(d => { const date = new Date(); - const tz = d.timezone / 3600; // TODO: What if `tz` has a fractional part... - const hour = (24 + date.getUTCHours() + tz) % 24; + const tz = d.timezone / 3600; // Now in hours. + const tz_frac = tz % 1; // Fractional part. + + if (tz_frac === 0) + date.setMinutes(date.getMinutes() + tz_frac * 60); + + const hour = (24 + date.getUTCHours() + tz - tz_frac) % 24; const country = !d.sys ? 'somewhere' : d.sys.country; const embed = d.main diff --git a/lib/extensions.ts b/lib/extensions.ts @@ -106,6 +106,7 @@ declare global { interface Number { round_to(dp: number): number; to_metric(figures): string; + truncate(): number; } } @@ -229,6 +230,10 @@ Number.prototype.to_metric = function (figures) { + SI_EXTENSIONS[i].symbol; }; +Number.prototype.truncate = function() { + return Number(this.toFixed()); +}; + // Discord Extensions: declare module 'discord.js' {