From 69c5e20d8e4f8355daa818c9696a87babb3d4559 Mon Sep 17 00:00:00 2001 From: db123 Date: Wed, 24 Jun 2026 10:06:39 +0330 Subject: [PATCH] display date in user's selected calendar on main menu and reports buildStatusText and buildDailyReport now use formatDateForCalendar to convert the stored Gregorian date to the user's calendar type (jalali/hijri/gregorian). --- internal/bot/dateutil.go | 14 ++++++++++++++ internal/bot/handlers.go | 9 ++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/internal/bot/dateutil.go b/internal/bot/dateutil.go index 9eba40c..89b71b6 100644 --- a/internal/bot/dateutil.go +++ b/internal/bot/dateutil.go @@ -276,3 +276,17 @@ func parseGregorianDateKey(key string) (int, int, int) { fmt.Sscanf(key, "%04d-%02d-%02d", &y, &m, &d) return y, m, d } + +func formatDateForCalendar(date, calType string) string { + y, m, d := parseGregorianDateKey(date) + switch calType { + case "jalali": + jy, jm, jd := gregorianToJalali(y, m, d) + return fmt.Sprintf("%04d-%02d-%02d", jy, jm, jd) + case "hijri": + hy, hm, hd := gregorianToHijri(y, m, d) + return fmt.Sprintf("%04d-%02d-%02d", hy, hm, hd) + default: + return date + } +} diff --git a/internal/bot/handlers.go b/internal/bot/handlers.go index e9b4b0c..0203b6f 100644 --- a/internal/bot/handlers.go +++ b/internal/bot/handlers.go @@ -350,7 +350,6 @@ func (h *Handler) handleStart(msg *tgbotapi.Message) { return } slog.Info("start", "user_id", user.ID, "chat_id", msg.Chat.ID) - h.sendText(msg.Chat.ID, "We hope you have a happy day working.") menu := tgbotapi.NewMessage(msg.Chat.ID, h.buildStatusText(msg.Chat.ID)) menu.ReplyMarkup = mainKeyboard() h.Bot.Send(menu) @@ -1224,7 +1223,7 @@ func (h *Handler) buildStatusText(chatID int64) string { return "Welcome. Choose an action:" } - text := fmt.Sprintf("Today: %s", day.Date) + text := fmt.Sprintf("Today: %s", formatDateForCalendar(day.Date, user.Calendar)) if day.IsDayOff { text += "\nDay Off" @@ -1277,16 +1276,16 @@ func (h *Handler) buildDailyReport(user *db.User, day *db.Day, events []db.Event if len(events) == 0 { if day.IsDayOff { - return fmt.Sprintf("%s - Day Off", day.Date) + return fmt.Sprintf("%s - Day Off", formatDateForCalendar(day.Date, user.Calendar)) } - return fmt.Sprintf("%s - No events recorded.", day.Date) + return fmt.Sprintf("%s - No events recorded.", formatDateForCalendar(day.Date, user.Calendar)) } y, m, d := parseGregorianDateKey(day.Date) dayStart := time.Date(y, time.Month(m), d, 0, 0, 0, 0, loc).Unix() dayEnd := time.Date(y, time.Month(m), d, 23, 59, 59, 0, loc).Unix() totals := ComputeDailyTotals(events, day.MinBreakThreshold, dayStart, dayEnd) - lines := fmt.Sprintf("Report for %s", day.Date) + lines := fmt.Sprintf("Report for %s", formatDateForCalendar(day.Date, user.Calendar)) if day.IsDayOff { lines += "\nDay Off: Yes" }