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).
This commit is contained in:
2026-06-24 10:06:39 +03:30
parent 07306cb0f0
commit 69c5e20d8e
2 changed files with 18 additions and 5 deletions

View File

@@ -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
}
}

View File

@@ -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"
}