fixed cache Refactoring from app router to page router Refactoring from app router to page router Add authentication with JWT base ui done protect the dashboard added transitions styling type trick added cleanup Add enable-disable logic add transactional emails Improvements on delay and frontend added description on select implement auth with magic link migrate to mariadb webhook signature working Adding async processing with queues Implemented webhook reply functionality Add son execution logs update status logic Add recent activity monitoring to sons show son performance in dashboard add readme implement listmonk connector listmonk-connector-v1 Create CODE_OF_CONDUCT.md Create LICENSE
43 lines
993 B
Go
43 lines
993 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func ParseDuration(durationStr string) (time.Duration, error) {
|
|
// First, try to parse with Go's built-in time.ParseDuration
|
|
duration, err := time.ParseDuration(durationStr)
|
|
if err == nil {
|
|
return duration, nil
|
|
}
|
|
|
|
// If that fails, check for days or weeks
|
|
var numericValue int
|
|
var unit string
|
|
|
|
_, err = fmt.Sscanf(durationStr, "%d%s", &numericValue, &unit)
|
|
if err != nil {
|
|
return 0, fmt.Errorf("invalid duration format: %s", durationStr)
|
|
}
|
|
|
|
switch unit {
|
|
case "d":
|
|
return time.Duration(numericValue) * 24 * time.Hour, nil
|
|
case "w":
|
|
return time.Duration(numericValue) * 7 * 24 * time.Hour, nil
|
|
default:
|
|
return 0, fmt.Errorf("unsupported duration unit: %s", unit)
|
|
}
|
|
}
|
|
|
|
func FormatDuration(d time.Duration) string {
|
|
if d.Hours() >= 24*7 {
|
|
weeks := int(d.Hours() / (24 * 7))
|
|
return fmt.Sprintf("%dw", weeks)
|
|
} else if d.Hours() >= 24 {
|
|
days := int(d.Hours() / 24)
|
|
return fmt.Sprintf("%dd", days)
|
|
}
|
|
return d.String()
|
|
}
|