Skip to content

Commit d54841f

Browse files
committed
feat: update dispatcher
1 parent a36e47f commit d54841f

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

serverless/dispatcher/internal/handler/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (h *Handler) help(ctx context.Context, b *bot.Bot, _ *models.Update) error
8888
func (h *Handler) today(ctx context.Context, b *bot.Bot, _ *models.Update) error {
8989
chat := getContextChat(ctx)
9090

91-
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, h.nowUTC(chat.BotID))
91+
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, h.now(chat.BotID))
9292
if err != nil {
9393
log.Error("today: get prayer day", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID))
9494
return domain.ErrInternal
@@ -129,7 +129,7 @@ func (h *Handler) next(ctx context.Context, b *bot.Bot, _ *models.Update) error
129129

130130
var (
131131
now = h.now(chat.BotID)
132-
date = h.nowUTC(chat.BotID)
132+
date = now.Truncate(24 * time.Hour)
133133
)
134134

135135
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, date)

serverless/dispatcher/internal/handler/helper.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ func (h *Handler) now(botID int64) time.Time {
5353
return time.Now().In(h.cfg[botID].Location.V()).Truncate(time.Minute)
5454
}
5555

56-
// nowUTC returns the current time in UTC with seconds and nanoseconds set to 0
57-
// Use this function to get prayerDay or current year for a specific botID timezone.
58-
func (h *Handler) nowUTC(botID int64) time.Time {
59-
return time.Now().In(h.cfg[botID].Location.V()).Truncate(time.Minute).UTC()
60-
}
61-
6256
// daysInMonth returns the number of days in a month.
6357
func daysInMonth(month time.Month, year int) int {
6458
// month is incremented by 1 and day is 0 because we want the last day of the month.

serverless/dispatcher/internal/handler/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (h *Handler) monthQuery(ctx context.Context, b *bot.Bot, update *models.Upd
7676
ChatID: chat.ChatID,
7777
MessageID: update.CallbackQuery.Message.Message.ID,
7878
Text: h.lp.GetText(chat.LanguageCode).PrayerDate,
79-
ReplyMarkup: h.daysKeyboard(h.nowUTC(chat.BotID), month),
79+
ReplyMarkup: h.daysKeyboard(h.now(chat.BotID), month),
8080
})
8181
if err != nil {
8282
log.Error("monthQuery: edit message", log.Err(err), log.BotID(chat.BotID), log.ChatID(chat.ChatID))
@@ -98,7 +98,7 @@ func (h *Handler) dayQuery(ctx context.Context, b *bot.Bot, update *models.Updat
9898
parts := strings.Split(update.CallbackQuery.Data, dataSplitterQuery)
9999
month, _ := strconv.Atoi(parts[1])
100100
day, _ := strconv.Atoi(parts[2])
101-
date := domain.DateUTC(day, time.Month(month), h.nowUTC(chat.BotID).Year())
101+
date := domain.DateUTC(day, time.Month(month), h.now(chat.BotID).Year())
102102

103103
prayerDay, err := h.db.GetPrayerDay(ctx, chat.BotID, date)
104104
if err != nil {

0 commit comments

Comments
 (0)