v0.0.404
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m37s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m37s
This commit is contained in:
parent
f13384d794
commit
102a280dda
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.403"
|
||||
const GoextVersion = "0.0.404"
|
||||
|
||||
const GoextVersionTimestamp = "2024-03-10T12:58:59+0100"
|
||||
const GoextVersionTimestamp = "2024-03-10T15:25:30+0100"
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/bsonrw"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -212,11 +214,48 @@ func (t Date) Format(layout string) string {
|
||||
}
|
||||
|
||||
func (t Date) GoString() string {
|
||||
return t.TimeUTC().GoString()
|
||||
return fmt.Sprintf("rfctime.Date{Year: %d, Month: %d, Day: %d}", t.Year, t.Month, t.Day)
|
||||
}
|
||||
|
||||
func (t Date) String() string {
|
||||
return t.TimeUTC().String()
|
||||
return fmt.Sprintf("%04d-%02d-%02d", t.Year, t.Month, t.Day)
|
||||
}
|
||||
|
||||
func (t *Date) ParseString(v string) error {
|
||||
split := strings.Split(v, "-")
|
||||
if len(split) != 3 {
|
||||
return errors.New("invalid date format: " + v)
|
||||
}
|
||||
year, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
month, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
day, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
|
||||
if year < 0 {
|
||||
return errors.New("invalid date format: " + v + ": year is negative")
|
||||
}
|
||||
|
||||
if month < 1 || month > 12 {
|
||||
return errors.New("invalid date format: " + v + ": month is out of range")
|
||||
}
|
||||
|
||||
if day < 1 || day > 31 {
|
||||
return errors.New("invalid date format: " + v + ": day is out of range")
|
||||
}
|
||||
|
||||
t.Year = int(year)
|
||||
t.Month = int(month)
|
||||
t.Day = int(day)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewDate(t time.Time) Date {
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/rfctime"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -79,24 +77,12 @@ var ConverterRFC339NanoTimeToString = NewDBTypeConverter[rfctime.RFC3339NanoTime
|
||||
var ConverterRFCDateToString = NewDBTypeConverter[rfctime.Date, string](func(v rfctime.Date) (string, error) {
|
||||
return fmt.Sprintf("%04d-%02d-%02d", v.Year, v.Month, v.Day), nil
|
||||
}, func(v string) (rfctime.Date, error) {
|
||||
split := strings.Split(v, "-")
|
||||
if len(split) != 3 {
|
||||
return rfctime.Date{}, errors.New("invalid date format: " + v)
|
||||
d := rfctime.Date{}
|
||||
if err := d.ParseString(v); err != nil {
|
||||
return rfctime.Date{}, err
|
||||
} else {
|
||||
return d, nil
|
||||
}
|
||||
year, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
month, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
day, err := strconv.ParseInt(split[0], 10, 32)
|
||||
if err != nil {
|
||||
return rfctime.Date{}, errors.New("invalid date format: " + v + ": " + err.Error())
|
||||
}
|
||||
|
||||
return rfctime.Date{Year: int(year), Month: int(month), Day: int(day)}, nil
|
||||
})
|
||||
|
||||
var ConverterRFCTimeToString = NewDBTypeConverter[rfctime.Time, string](func(v rfctime.Time) (string, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user