2023-01-29 20:42:02 +01:00
|
|
|
package rfctime
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
type RFCTime interface {
|
2023-03-15 15:41:55 +01:00
|
|
|
AnyTime
|
|
|
|
|
2023-01-29 20:42:02 +01:00
|
|
|
Time() time.Time
|
|
|
|
Serialize() string
|
|
|
|
|
2023-03-15 15:41:55 +01:00
|
|
|
After(u AnyTime) bool
|
|
|
|
Before(u AnyTime) bool
|
|
|
|
Equal(u AnyTime) bool
|
|
|
|
|
|
|
|
Sub(u AnyTime) time.Duration
|
|
|
|
}
|
|
|
|
|
|
|
|
type AnyTime interface {
|
2023-01-29 20:42:02 +01:00
|
|
|
MarshalJSON() ([]byte, error)
|
|
|
|
|
|
|
|
MarshalBinary() ([]byte, error)
|
|
|
|
|
|
|
|
GobEncode() ([]byte, error)
|
|
|
|
|
|
|
|
MarshalText() ([]byte, error)
|
|
|
|
|
|
|
|
IsZero() bool
|
|
|
|
Date() (year int, month time.Month, day int)
|
|
|
|
Year() int
|
|
|
|
Month() time.Month
|
|
|
|
Day() int
|
|
|
|
Weekday() time.Weekday
|
|
|
|
ISOWeek() (year, week int)
|
|
|
|
Clock() (hour, min, sec int)
|
|
|
|
Hour() int
|
|
|
|
Minute() int
|
|
|
|
Second() int
|
|
|
|
Nanosecond() int
|
|
|
|
YearDay() int
|
|
|
|
Unix() int64
|
|
|
|
UnixMilli() int64
|
|
|
|
UnixMicro() int64
|
|
|
|
UnixNano() int64
|
|
|
|
Format(layout string) string
|
|
|
|
GoString() string
|
|
|
|
String() string
|
2023-03-15 15:41:55 +01:00
|
|
|
|
|
|
|
Location() *time.Location
|
2023-01-29 20:42:02 +01:00
|
|
|
}
|
2023-02-08 18:55:51 +01:00
|
|
|
|
|
|
|
type RFCDuration interface {
|
|
|
|
Time() time.Time
|
|
|
|
Serialize() string
|
|
|
|
|
|
|
|
UnmarshalJSON(bytes []byte) error
|
|
|
|
MarshalJSON() ([]byte, error)
|
|
|
|
|
|
|
|
MarshalBinary() ([]byte, error)
|
|
|
|
UnmarshalBinary(data []byte) error
|
|
|
|
|
|
|
|
GobEncode() ([]byte, error)
|
|
|
|
GobDecode(data []byte) error
|
|
|
|
|
|
|
|
MarshalText() ([]byte, error)
|
|
|
|
UnmarshalText(data []byte) error
|
|
|
|
|
2023-03-15 15:41:55 +01:00
|
|
|
After(u AnyTime) bool
|
|
|
|
Before(u AnyTime) bool
|
|
|
|
Equal(u AnyTime) bool
|
2023-02-08 18:55:51 +01:00
|
|
|
IsZero() bool
|
|
|
|
Date() (year int, month time.Month, day int)
|
|
|
|
Year() int
|
|
|
|
Month() time.Month
|
|
|
|
Day() int
|
|
|
|
Weekday() time.Weekday
|
|
|
|
ISOWeek() (year, week int)
|
|
|
|
Clock() (hour, min, sec int)
|
|
|
|
Hour() int
|
|
|
|
Minute() int
|
|
|
|
Second() int
|
|
|
|
Nanosecond() int
|
|
|
|
YearDay() int
|
2023-03-15 15:41:55 +01:00
|
|
|
Sub(u AnyTime) time.Duration
|
2023-02-08 18:55:51 +01:00
|
|
|
Unix() int64
|
|
|
|
UnixMilli() int64
|
|
|
|
UnixMicro() int64
|
|
|
|
UnixNano() int64
|
|
|
|
Format(layout string) string
|
|
|
|
GoString() string
|
|
|
|
String() string
|
|
|
|
}
|
2023-03-15 15:41:55 +01:00
|
|
|
|
|
|
|
func tt(v AnyTime) time.Time {
|
|
|
|
if r, ok := v.(time.Time); ok {
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
if r, ok := v.(RFCTime); ok {
|
|
|
|
return r.Time()
|
|
|
|
}
|
|
|
|
return time.Unix(0, v.UnixNano()).In(v.Location())
|
|
|
|
}
|