2019-08-12 12:11:16 +02:00
|
|
|
package testutils
|
|
|
|
|
|
|
|
|
|
import (
|
2021-07-27 17:39:21 +02:00
|
|
|
"github.com/go-jet/jet/v2/internal/utils/throw"
|
2019-08-12 12:11:16 +02:00
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
2019-08-17 18:32:01 +02:00
|
|
|
// Date creates time from t string
|
2019-08-12 12:11:16 +02:00
|
|
|
func Date(t string) *time.Time {
|
|
|
|
|
newTime, err := time.Parse("2006-01-02", t)
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
throw.OnError(err)
|
2019-08-12 12:11:16 +02:00
|
|
|
|
|
|
|
|
return &newTime
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:32:01 +02:00
|
|
|
// TimestampWithoutTimeZone creates time from t
|
2019-08-12 12:11:16 +02:00
|
|
|
func TimestampWithoutTimeZone(t string, precision int) *time.Time {
|
|
|
|
|
|
|
|
|
|
precisionStr := ""
|
|
|
|
|
|
|
|
|
|
if precision > 0 {
|
|
|
|
|
precisionStr = "." + strings.Repeat("9", precision)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newTime, err := time.Parse("2006-01-02 15:04:05"+precisionStr+" +0000", t+" +0000")
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
throw.OnError(err)
|
2019-08-12 12:11:16 +02:00
|
|
|
|
|
|
|
|
return &newTime
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:32:01 +02:00
|
|
|
// TimeWithoutTimeZone creates time from t
|
2019-08-12 12:11:16 +02:00
|
|
|
func TimeWithoutTimeZone(t string) *time.Time {
|
|
|
|
|
newTime, err := time.Parse("15:04:05", t)
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
throw.OnError(err)
|
2019-08-12 12:11:16 +02:00
|
|
|
|
|
|
|
|
return &newTime
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:32:01 +02:00
|
|
|
// TimeWithTimeZone creates time from t
|
2019-08-12 12:11:16 +02:00
|
|
|
func TimeWithTimeZone(t string) *time.Time {
|
|
|
|
|
newTimez, err := time.Parse("15:04:05 -0700", t)
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
throw.OnError(err)
|
2019-08-12 12:11:16 +02:00
|
|
|
|
|
|
|
|
return &newTimez
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-17 18:32:01 +02:00
|
|
|
// TimestampWithTimeZone creates time from t
|
2019-08-12 12:11:16 +02:00
|
|
|
func TimestampWithTimeZone(t string, precision int) *time.Time {
|
|
|
|
|
|
|
|
|
|
precisionStr := ""
|
|
|
|
|
|
|
|
|
|
if precision > 0 {
|
|
|
|
|
precisionStr = "." + strings.Repeat("9", precision)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newTime, err := time.Parse("2006-01-02 15:04:05"+precisionStr+" -0700 MST", t)
|
|
|
|
|
|
2021-07-27 17:39:21 +02:00
|
|
|
throw.OnError(err)
|
2019-08-12 12:11:16 +02:00
|
|
|
|
|
|
|
|
return &newTime
|
|
|
|
|
}
|