From 5a0a91ec87bd9e1df71c4f11fe1bf2d5c67db5e1 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 2 Jan 2022 14:41:27 +0100 Subject: [PATCH] add timezone --- src/cron.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cron.ts b/src/cron.ts index 2a9ce78..383ee21 100644 --- a/src/cron.ts +++ b/src/cron.ts @@ -6,19 +6,22 @@ import { getLatests } from './routes/status.js' async function fn() { const now = dayjs() + const { fed, clean } = getLatests() + const needsFeeding = !fed || dayjs(fed.timestamp).isBefore(now.subtract(12, 'hours')) + const needsCleaning = !clean || dayjs(clean.timestamp).isBefore(now.subtract(7, 'days')) + for (const user of DB.data?.users ?? []) { - const { fed, clean } = getLatests() - if (!fed || dayjs(fed.timestamp).isBefore(now.subtract(12, 'hours'))) { + if (needsFeeding) { await bot.telegram.sendMessage(user.id, '🥜 You have not fed me in the last 12 hours!') } - - if (!clean || dayjs(clean.timestamp).isBefore(now.subtract(7, 'days'))) { + if (needsCleaning) { await bot.telegram.sendMessage(user.id, '🛁 You have not cleaned me in the last 7 days!') } } } export function init() { - cron.schedule('0 22 * * *', fn) - // cron.schedule('*/10 * * * * *', fn) + const timezone = 'Europe/Berlin' + cron.schedule('0 22 * * *', fn, { timezone }) + // cron.schedule('*/10 * * * * *', fn, {timezone}) }