us-dop-api/internal/helpers/timehelpers.go
maximo tejeda 8dae98db2b
All checks were successful
dev test / test (push) Successful in 23s
dev test / vulnCheck (push) Successful in 29s
dev test / Ci-Lint (push) Successful in 27s
${{ github.actor }} executed Build Push Prod / build (push) Successful in 3m25s
${{ github.actor }} executed Build Push Prod / deploy (push) Successful in 20s
fix timing issue
2024-12-13 11:12:34 -04:00

28 lines
600 B
Go

package helpers
import (
"strconv"
"strings"
"time"
)
func ParseTimeAmount(timeFrame, timeAmount string) (timeSearch time.Duration, err error) {
timeInt, err := strconv.ParseInt(strings.ReplaceAll(timeAmount, "-", ""), 10, 64)
if err != nil {
return timeSearch, err
}
switch timeFrame {
case "hour":
timeSearch = time.Duration(timeInt) * time.Hour
case "day":
timeSearch = 24 * time.Duration(timeInt) * time.Hour
case "week":
timeSearch = (24 * 7 * time.Duration(timeInt)) * time.Hour
case "month":
timeSearch = (24 * 7 * 4) * time.Hour
default:
}
return timeSearch, err
}