From 25ea4a20c8b7a1cd3d8ca15f82a0efcc8198bda7 Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Tue, 26 Nov 2024 15:29:02 +0530 Subject: [PATCH 1/3] [MM-339]: Added support for lower case meridiems(AM/PM) --- calendar/engine/daily_summary.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/calendar/engine/daily_summary.go b/calendar/engine/daily_summary.go index a08d9768..15f08c5e 100644 --- a/calendar/engine/daily_summary.go +++ b/calendar/engine/daily_summary.go @@ -5,6 +5,7 @@ package engine import ( "fmt" + "strings" "time" "github.com/pkg/errors" @@ -44,7 +45,7 @@ func (m *mscalendar) SetDailySummaryPostTime(user *User, timeStr string) (*store return nil, err } - t, err := time.Parse(time.Kitchen, timeStr) + t, err := time.Parse(time.Kitchen, convertToUpperCaseTime(timeStr)) if err != nil { return nil, errors.New("Invalid time value: " + timeStr) } @@ -291,3 +292,17 @@ func getTodayHoursForTimezone(now time.Time, timezone string) (start, end time.T end = start.Add(24 * time.Hour) return start, end } + +func convertToUpperCaseTime(timeStr string) string { + if len(timeStr) < 2 { + return timeStr + } + + period := timeStr[len(timeStr)-2:] + + if strings.ToLower(period) == "am" || strings.ToLower(period) == "pm" { + return timeStr[:len(timeStr)-2] + strings.ToUpper(period) + } + + return timeStr +} From 2dea7dcaad4733bd6e3028f17dfef6bff256fb32 Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Thu, 28 Nov 2024 14:35:26 +0530 Subject: [PATCH 2/3] [MM-339]: Updated function name to more specific to meridiems --- calendar/engine/daily_summary.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/calendar/engine/daily_summary.go b/calendar/engine/daily_summary.go index 15f08c5e..a9c146dd 100644 --- a/calendar/engine/daily_summary.go +++ b/calendar/engine/daily_summary.go @@ -45,7 +45,7 @@ func (m *mscalendar) SetDailySummaryPostTime(user *User, timeStr string) (*store return nil, err } - t, err := time.Parse(time.Kitchen, convertToUpperCaseTime(timeStr)) + t, err := time.Parse(time.Kitchen, convertMeridiemToUpperCase(timeStr)) if err != nil { return nil, errors.New("Invalid time value: " + timeStr) } @@ -293,7 +293,7 @@ func getTodayHoursForTimezone(now time.Time, timezone string) (start, end time.T return start, end } -func convertToUpperCaseTime(timeStr string) string { +func convertMeridiemToUpperCase(timeStr string) string { if len(timeStr) < 2 { return timeStr } From fe3c4357da6ddea689b6766473c7666a1d97591b Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Mon, 2 Dec 2024 19:01:18 +0530 Subject: [PATCH 3/3] [MM-339]: review fixes --- calendar/engine/daily_summary.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/calendar/engine/daily_summary.go b/calendar/engine/daily_summary.go index a9c146dd..80f8e307 100644 --- a/calendar/engine/daily_summary.go +++ b/calendar/engine/daily_summary.go @@ -298,10 +298,10 @@ func convertMeridiemToUpperCase(timeStr string) string { return timeStr } - period := timeStr[len(timeStr)-2:] + meridiem := strings.ToUpper(timeStr[len(timeStr)-2:]) - if strings.ToLower(period) == "am" || strings.ToLower(period) == "pm" { - return timeStr[:len(timeStr)-2] + strings.ToUpper(period) + if meridiem == "AM" || meridiem == "PM" { + return timeStr[:len(timeStr)-2] + meridiem } return timeStr