From a53e551ab6df1da3776a3bc75e567a7fb6c110c8 Mon Sep 17 00:00:00 2001 From: Shivam-nagar23 Date: Tue, 7 Oct 2025 17:18:56 +0530 Subject: [PATCH] last 24 hours --- common-lib/utils/TimeUtils.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common-lib/utils/TimeUtils.go b/common-lib/utils/TimeUtils.go index 09311be36..372765014 100644 --- a/common-lib/utils/TimeUtils.go +++ b/common-lib/utils/TimeUtils.go @@ -25,7 +25,7 @@ import ( type TimeRangeRequest struct { From *time.Time `json:"from" schema:"from"` To *time.Time `json:"to" schema:"to"` - TimeWindow *TimeWindows `json:"timeWindow" schema:"timeWindow" validate:"omitempty,oneof=today yesterday week month quarter lastWeek lastMonth lastQuarter last7Days last30Days last90Days"` + TimeWindow *TimeWindows `json:"timeWindow" schema:"timeWindow" validate:"omitempty,oneof=today yesterday week month quarter lastWeek lastMonth lastQuarter last24Hours last7Days last30Days last90Days"` } func NewTimeRangeRequest(from *time.Time, to *time.Time) *TimeRangeRequest { @@ -59,6 +59,7 @@ const ( LastMonth TimeWindows = "lastMonth" Year TimeWindows = "year" LastQuarter TimeWindows = "lastQuarter" + Last24Hours TimeWindows = "last24Hours" Last7Days TimeWindows = "last7Days" Last30Days TimeWindows = "last30Days" Last90Days TimeWindows = "last90Days" @@ -143,6 +144,9 @@ func (timeRange *TimeRangeRequest) ParseAndValidateTimeRange() (*TimeRangeReques case Year: start := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location()) return NewTimeRangeRequest(&start, &now), nil + case Last24Hours: + start := now.Add(-24 * time.Hour) + return NewTimeRangeRequest(&start, &now), nil case Last7Days: start := now.AddDate(0, 0, -7) return NewTimeRangeRequest(&start, &now), nil