Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion common-lib/utils/TimeUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down