Skip to content

Commit

Permalink
fix: add logs to util
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedorrychkov committed Jan 21, 2024
1 parent 84ceb49 commit 34a7790
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/modules/telegram/scenarios/mealEvent/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { Logger } from '@nestjs/common'
import { time } from 'src/helpers'

export const getTimeInfoForNotifications = () => {
const logger = new Logger('getTimeInfoForNotifications')
const currentDateInstance = time().tz('Europe/Moscow')

const currentDate = currentDateInstance.format('MM/DD/YYYY')

const formattedStartNotificationTime = '10:00:00'
const formattedEndNotificationTime = '22:00:00'
const formattedCurrentForStartNotificationDatetime = `${currentDate} ${formattedStartNotificationTime}`
const formattedCurrentForEndNotificationDatetime = `${currentDate} ${formattedEndNotificationTime}`
const formattedCurrentForStartNotificationDatetime = currentDateInstance.hour(10).minute(0).second(0)
const formattedCurrentForEndNotificationDatetime = currentDateInstance.hour(22).minute(0).second(0)

const isNeedToPushNotification =
time(formattedCurrentForStartNotificationDatetime).tz('Europe/Moscow').isBefore(currentDateInstance) &&
time(formattedCurrentForEndNotificationDatetime).tz('Europe/Moscow').isAfter(currentDateInstance)
time(formattedCurrentForStartNotificationDatetime).isBefore(currentDateInstance) &&
time(formattedCurrentForEndNotificationDatetime).isAfter(currentDateInstance)

logger.log('[Current Time]', {
before: time(formattedCurrentForStartNotificationDatetime).isBefore(currentDateInstance),
after: time(formattedCurrentForEndNotificationDatetime).isAfter(currentDateInstance),
beforeTime: time(formattedCurrentForStartNotificationDatetime).format('MM/DD/YYYY HH:mm:ss'),
afterTime: time(formattedCurrentForEndNotificationDatetime).format('MM/DD/YYYY HH:mm:ss'),
current: time(currentDateInstance).format('MM/DD/YYYY HH:mm:ss'),
})

return { isNeedToPushNotification, currentDate, currentDateInstance }
}

0 comments on commit 34a7790

Please sign in to comment.