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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user