carbon/json.go

676 lines
19 KiB
Go
Raw Normal View History

2021-07-03 15:31:42 +08:00
package carbon
import (
2021-07-19 09:53:30 +08:00
"bytes"
2021-07-03 15:31:42 +08:00
"fmt"
2021-07-19 09:53:30 +08:00
"strconv"
2021-07-03 15:31:42 +08:00
)
// DateTime defines a DateTime struct.
// 定义 DateTime 结构体
2023-10-10 09:47:58 +08:00
type DateTime struct {
Carbon
}
// DateTimeMilli defines a DateTimeMilli struct.
// 定义 DateTimeMilli 结构体
2023-10-10 09:47:58 +08:00
type DateTimeMilli struct {
Carbon
}
// DateTimeMicro defines a DateTimeMicro struct.
// 定义 DateTimeMicro 结构体
2023-10-10 09:47:58 +08:00
type DateTimeMicro struct {
Carbon
}
// DateTimeNano defines a DateTimeNano struct.
// 定义 DateTimeNano 结构体
2023-10-10 09:47:58 +08:00
type DateTimeNano struct {
Carbon
}
// Date defines a Date struct.
// 定义 Date 结构体
2023-10-10 09:47:58 +08:00
type Date struct {
Carbon
}
// DateMilli defines a DateMilli struct.
// 定义 DateMilli 结构体
2023-10-10 09:47:58 +08:00
type DateMilli struct {
Carbon
}
// DateMicro defines a DateMicro struct.
// 定义 DateMicro 结构体
2023-10-10 09:47:58 +08:00
type DateMicro struct {
Carbon
}
// DateNano defines a DateNano struct.
// 定义 DateNano 结构体
2023-10-10 09:47:58 +08:00
type DateNano struct {
Carbon
}
2023-09-21 15:03:35 +08:00
// Time defines a Time struct.
// 定义 Time 结构体
2023-10-10 09:47:58 +08:00
type Time struct {
Carbon
}
2023-09-21 15:03:35 +08:00
// TimeMilli defines a TimeMilli struct.
// 定义 TimeMilli 结构体
2023-10-10 09:47:58 +08:00
type TimeMilli struct {
Carbon
}
2023-09-21 15:03:35 +08:00
// TimeMicro defines a TimeMicro struct.
// 定义 TimeMicro 结构体
2023-10-10 09:47:58 +08:00
type TimeMicro struct {
Carbon
}
2023-09-21 15:03:35 +08:00
// TimeNano defines a TimeNano struct.
// 定义 TimeNano 结构体
2023-10-10 09:47:58 +08:00
type TimeNano struct {
Carbon
}
2023-09-21 15:03:35 +08:00
// Timestamp defines a Timestamp struct.
// 定义 Timestamp 结构体
2023-10-10 09:47:58 +08:00
type Timestamp struct {
Carbon
}
// TimestampMilli defines a TimestampMilli struct.
// 定义 TimestampMilli 结构体
2023-10-10 09:47:58 +08:00
type TimestampMilli struct {
Carbon
}
// TimestampMicro defines a TimestampMicro struct.
// 定义 TimestampMicro 结构体
2023-10-10 09:47:58 +08:00
type TimestampMicro struct {
Carbon
}
// TimestampNano defines a TimestampNano struct.
// 定义 TimestampNano 结构体
2023-10-10 09:47:58 +08:00
type TimestampNano struct {
Carbon
}
// MarshalJSON implements the interface json.Marshal for DateTime struct.
// 实现 MarshalJSON 接口
func (t DateTime) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateTime struct.
// 实现 UnmarshalJSON 接口
func (t *DateTime) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateTime{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateTimeMilli struct.
// 实现 MarshalJSON 接口
func (t DateTimeMilli) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMilliString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMilli struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeMilli) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMilliLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateTimeMilli{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateTimeMicro struct.
// 实现 MarshalJSON 接口
func (t DateTimeMicro) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeMicroString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeMicro struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeMicro) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeMicroLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateTimeMicro{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateTimeNano struct.
// 实现 MarshalJSON 接口
func (t DateTimeNano) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateTimeNanoString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateTimeNano struct.
// 实现 UnmarshalJSON 接口
func (t *DateTimeNano) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateTimeNanoLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateTimeNano{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for Date struct.
// 实现 MarshalJSON 接口
func (t Date) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for Date struct.
// 实现 UnmarshalJSON 接口
func (t *Date) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = Date{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateMilli struct.
// 实现 MarshalJSON 接口
func (t DateMilli) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateMilliString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateMilli struct.
// 实现 UnmarshalJSON 接口
func (t *DateMilli) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMilliLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateMilli{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateMicro struct.
// 实现 MarshalJSON 接口
func (t DateMicro) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateMicroString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateMicro struct.
// 实现 UnmarshalJSON 接口
func (t *DateMicro) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateMicroLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateMicro{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for DateNano struct.
// 实现 MarshalJSON 接口
func (t DateNano) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToDateNanoString())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for DateNano struct.
// 实现 UnmarshalJSON 接口
func (t *DateNano) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), DateNanoLayout, t.Location())
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = DateNano{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
2023-09-21 15:03:35 +08:00
// MarshalJSON implements the interface json.Marshal for Time struct.
// 实现 MarshalJSON 接口
func (t Time) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeString())), nil
2023-09-21 15:03:35 +08:00
}
// UnmarshalJSON implements the interface json.Unmarshal for Time struct.
// 实现 UnmarshalJSON 接口
func (t *Time) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeLayout, t.Location())
2023-09-21 15:03:35 +08:00
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = Time{Carbon: c}
2023-09-21 15:03:35 +08:00
}
return c.Error
}
// MarshalJSON implements the interface json.Marshal for TimeMilli struct.
// 实现 MarshalJSON 接口
func (t TimeMilli) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMilliString())), nil
2023-09-21 15:03:35 +08:00
}
// UnmarshalJSON implements the interface json.Unmarshal for TimeMilli struct.
// 实现 UnmarshalJSON 接口
func (t *TimeMilli) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeMilliLayout, t.Location())
2023-09-21 15:03:35 +08:00
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimeMilli{Carbon: c}
2023-09-21 15:03:35 +08:00
}
return c.Error
}
// MarshalJSON implements the interface json.Marshal for TimeMicro struct.
// 实现 MarshalJSON 接口
func (t TimeMicro) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeMicroString())), nil
2023-09-21 15:03:35 +08:00
}
// UnmarshalJSON implements the interface json.Unmarshal for TimeMicro struct.
// 实现 UnmarshalJSON 接口
func (t *TimeMicro) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeMicroLayout, t.Location())
2023-09-21 15:03:35 +08:00
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimeMicro{Carbon: c}
2023-09-21 15:03:35 +08:00
}
return c.Error
}
// MarshalJSON implements the interface json.Marshal for TimeNano struct.
// 实现 MarshalJSON 接口
func (t TimeNano) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`"%s"`, t.ToTimeNanoString())), nil
2023-09-21 15:03:35 +08:00
}
// UnmarshalJSON implements the interface json.Unmarshal for TimeNano struct.
// 实现 UnmarshalJSON 接口
func (t *TimeNano) UnmarshalJSON(b []byte) error {
2023-10-10 09:47:58 +08:00
c := ParseByLayout(string(bytes.Trim(b, `"`)), TimeNanoLayout, t.Location())
2023-09-21 15:03:35 +08:00
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimeNano{Carbon: c}
2023-09-21 15:03:35 +08:00
}
return c.Error
}
// MarshalJSON implements the interface json.Marshal for Timestamp struct.
// 实现 MarshalJSON 接口
func (t Timestamp) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`%d`, t.Timestamp())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for Timestamp struct.
// 实现 UnmarshalJSON 接口
func (t *Timestamp) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
c := CreateFromTimestamp(ts)
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = Timestamp{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for TimestampMilli struct.
// 实现 MarshalJSON 接口
func (t TimestampMilli) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`%d`, t.TimestampMilli())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMilli struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampMilli) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
c := CreateFromTimestampMilli(ts)
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimestampMilli{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface MarshalJSON for TimestampMicro struct.
// 实现 MarshalJSON 接口
func (t TimestampMicro) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`%d`, t.TimestampMicro())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for TimestampMicro struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampMicro) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
c := CreateFromTimestampMicro(ts)
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimestampMicro{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
// MarshalJSON implements the interface json.Marshal for TimestampNano struct.
// 实现 MarshalJSON 接口
func (t TimestampNano) MarshalJSON() ([]byte, error) {
2023-10-10 09:47:58 +08:00
return []byte(fmt.Sprintf(`%d`, t.TimestampNano())), nil
}
// UnmarshalJSON implements the interface json.Unmarshal for TimestampNano struct.
// 实现 UnmarshalJSON 接口
func (t *TimestampNano) UnmarshalJSON(b []byte) error {
ts, _ := strconv.ParseInt(string(b), 10, 64)
c := CreateFromTimestampNano(ts)
if c.Error == nil {
2023-10-10 09:47:58 +08:00
*t = TimestampNano{Carbon: c}
}
2022-11-04 10:47:29 +08:00
return c.Error
}
2023-09-13 15:41:22 +08:00
// ToDateTimeStruct converts Carbon to DateTime.
// 将 Carbon 结构体转换成 DateTime 结构体
func (c Carbon) ToDateTimeStruct() DateTime {
2023-10-10 09:47:58 +08:00
return DateTime{Carbon: c}
2023-09-11 10:34:30 +08:00
}
2023-09-13 15:41:22 +08:00
// ToDateTimeMilliStruct converts Carbon to DateTimeMilli.
// 将 Carbon 结构体转换成 DateTimeMilli 结构体
func (c Carbon) ToDateTimeMilliStruct() DateTimeMilli {
2023-10-10 09:47:58 +08:00
return DateTimeMilli{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateTimeMicroStruct converts Carbon to DateTimeMicro.
// 将 Carbon 结构体转换成 DateTimeMicro 结构体
func (c Carbon) ToDateTimeMicroStruct() DateTimeMicro {
2023-10-10 09:47:58 +08:00
return DateTimeMicro{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateTimeNanoStruct converts Carbon to DateTimeNano.
// 将 Carbon 结构体转换成 DateTimeNano 结构体
func (c Carbon) ToDateTimeNanoStruct() DateTimeNano {
2023-10-10 09:47:58 +08:00
return DateTimeNano{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateStruct converts Carbon to Date.
// 将 Carbon 结构体转换成 Date 结构体
func (c Carbon) ToDateStruct() Date {
2023-10-10 09:47:58 +08:00
return Date{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateMilliStruct converts Carbon to DateMilli.
// 将 Carbon 结构体转换成 DateMilli 结构体
func (c Carbon) ToDateMilliStruct() DateMilli {
2023-10-10 09:47:58 +08:00
return DateMilli{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateMicroStruct converts Carbon to DateMicro.
// 将 Carbon 结构体转换成 DateMicro 结构体
func (c Carbon) ToDateMicroStruct() DateMicro {
2023-10-10 09:47:58 +08:00
return DateMicro{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToDateNanoStruct converts Carbon to DateNano.
// 将 Carbon 结构体转换成 DateNano 结构体
func (c Carbon) ToDateNanoStruct() DateNano {
2023-10-10 09:47:58 +08:00
return DateNano{Carbon: c}
2023-09-13 15:41:22 +08:00
}
2023-09-21 15:03:35 +08:00
// ToTimeStruct converts Carbon to Time.
// 将 Carbon 结构体转换成 Time 结构体
func (c Carbon) ToTimeStruct() Time {
2023-10-10 09:47:58 +08:00
return Time{Carbon: c}
2023-09-21 15:03:35 +08:00
}
// ToTimeMilliStruct converts Carbon to TimeMilli.
// 将 Carbon 结构体转换成 TimeMilli 结构体
func (c Carbon) ToTimeMilliStruct() TimeMilli {
2023-10-10 09:47:58 +08:00
return TimeMilli{Carbon: c}
2023-09-21 15:03:35 +08:00
}
// ToTimeMicroStruct converts Carbon to TimeMicro.
// 将 Carbon 结构体转换成 TimeMicro 结构体
func (c Carbon) ToTimeMicroStruct() TimeMicro {
2023-10-10 09:47:58 +08:00
return TimeMicro{Carbon: c}
2023-09-21 15:03:35 +08:00
}
// ToTimeNanoStruct converts Carbon to TimeNano.
// 将 Carbon 结构体转换成 TimeNano 结构体
func (c Carbon) ToTimeNanoStruct() TimeNano {
2023-10-10 09:47:58 +08:00
return TimeNano{Carbon: c}
2023-09-21 15:03:35 +08:00
}
2023-09-13 15:41:22 +08:00
// ToTimestampStruct converts Carbon to Timestamp.
// 将 Carbon 结构体转换成 Timestamp 结构体
func (c Carbon) ToTimestampStruct() Timestamp {
2023-10-10 09:47:58 +08:00
return Timestamp{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToTimestampMilliStruct converts Carbon to TimestampMilli.
// 将 Carbon 结构体转换成 TimestampMilli 结构体
func (c Carbon) ToTimestampMilliStruct() TimestampMilli {
2023-10-10 09:47:58 +08:00
return TimestampMilli{Carbon: c}
2023-09-13 15:41:22 +08:00
}
// ToTimestampMicroStruct converts Carbon to TimestampMicro.
// 将 Carbon 结构体转换成 TimestampMicro 结构体
func (c Carbon) ToTimestampMicroStruct() TimestampMicro {
2023-10-10 09:47:58 +08:00
return TimestampMicro{Carbon: c}
2023-09-11 10:34:30 +08:00
}
// ToTimestampNanoStruct converts Carbon to TimestampNano.
// 将 Carbon 结构体转换成 TimestampNano 结构体
func (c Carbon) ToTimestampNanoStruct() TimestampNano {
2023-10-10 09:47:58 +08:00
return TimestampNano{Carbon: c}
}
2023-09-13 15:41:22 +08:00
// Int64 outputs timestamp with second.
// 输出秒级时间戳
func (t Timestamp) Int64() int64 {
2023-10-10 09:47:58 +08:00
return t.Timestamp()
2023-09-13 15:41:22 +08:00
}
// Int64 outputs timestamp with millisecond.
// 输出豪秒级时间戳
func (t TimestampMilli) Int64() int64 {
2023-10-10 09:47:58 +08:00
return t.TimestampMilli()
2023-09-13 15:41:22 +08:00
}
// Int64 outputs timestamp with microsecond.
// 输出微秒级时间戳
func (t TimestampMicro) Int64() int64 {
2023-10-10 09:47:58 +08:00
return t.TimestampMicro()
2023-09-13 15:41:22 +08:00
}
// Int64 outputs timestamp with nanosecond.
// 输出纳秒级时间戳
func (t TimestampNano) Int64() int64 {
2023-10-10 09:47:58 +08:00
return t.TimestampNano()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateTime struct.
// 实现 Stringer 接口
func (t DateTime) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateTimeString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateTimeMilli struct.
// 实现 Stringer 接口
func (t DateTimeMilli) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateTimeMilliString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateTimeMicro struct.
// 实现 Stringer 接口
func (t DateTimeMicro) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateTimeMicroString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateTimeNano struct.
// 实现 Stringer 接口
func (t DateTimeNano) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateTimeNanoString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for Date struct.
// 实现 Stringer 接口
func (t Date) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateMilli struct.
// 实现 Stringer 接口
func (t DateMilli) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateMilliString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateMicro struct.
// 实现 Stringer 接口
func (t DateMicro) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateMicroString()
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for DateNano struct.
// 实现 Stringer 接口
func (t DateNano) String() string {
2023-10-10 09:47:58 +08:00
return t.ToDateNanoString()
2023-09-13 15:41:22 +08:00
}
2023-09-21 15:03:35 +08:00
// String implements the interface Stringer for Time struct.
// 实现 Stringer 接口
func (t Time) String() string {
2023-10-10 09:47:58 +08:00
return t.ToTimeString()
2023-09-21 15:03:35 +08:00
}
// String implements the interface Stringer for TimeMilli struct.
// 实现 Stringer 接口
func (t TimeMilli) String() string {
2023-10-10 09:47:58 +08:00
return t.ToTimeMilliString()
2023-09-21 15:03:35 +08:00
}
// String implements the interface Stringer for TimeMicro struct.
// 实现 Stringer 接口
func (t TimeMicro) String() string {
2023-10-10 09:47:58 +08:00
return t.ToTimeMicroString()
2023-09-21 15:03:35 +08:00
}
// String implements the interface Stringer for TimeNano struct.
// 实现 Stringer 接口
func (t TimeNano) String() string {
2023-10-10 09:47:58 +08:00
return t.ToTimeNanoString()
2023-09-21 15:03:35 +08:00
}
2023-09-13 15:41:22 +08:00
// String implements the interface Stringer for Timestamp struct.
// 实现 Stringer 接口
func (t Timestamp) String() string {
2023-10-10 09:47:58 +08:00
return strconv.FormatInt(t.Timestamp(), 10)
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for TimestampMilli struct.
// 实现 Stringer 接口
func (t TimestampMilli) String() string {
2023-10-10 09:47:58 +08:00
return strconv.FormatInt(t.TimestampMilli(), 10)
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for TimestampMicro struct.
// 实现 Stringer 接口
func (t TimestampMicro) String() string {
2023-10-10 09:47:58 +08:00
return strconv.FormatInt(t.TimestampMicro(), 10)
2023-09-13 15:41:22 +08:00
}
// String implements the interface Stringer for TimestampNano struct.
// 实现 Stringer 接口
func (t TimestampNano) String() string {
2023-10-10 09:47:58 +08:00
return strconv.FormatInt(t.TimestampNano(), 10)
2023-09-13 15:41:22 +08:00
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateTime struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateTime) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateTimeMilli struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateTimeMilli) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateTimeMicro struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateTimeMicro) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateTimeNano struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateTimeNano) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for Date struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t Date) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateMilli struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateMilli) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateMicro struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateMicro) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for DateNano struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t DateNano) GormDataType() string {
return "time"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for Time struct.
// 实现 GormDataTypeInterface 接口
func (t Time) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMilli struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMilli) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeMicro struct.
// 实现 GormDataTypeInterface 接口
func (t TimeMicro) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for TimeNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimeNano) GormDataType() string {
return "time"
}
// GormDataType implements the interface GormDataTypeInterface for Timestamp struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t Timestamp) GormDataType() string {
return "int"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for TimestampMilli struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t TimestampMilli) GormDataType() string {
return "int"
}
2023-09-21 15:03:35 +08:00
// GormDataType implements the interface GormDataTypeInterface for TimestampMicro struct.
2023-09-13 15:41:22 +08:00
// 实现 GormDataTypeInterface 接口
func (t TimestampMicro) GormDataType() string {
return "int"
}
// GormDataType implements the interface GormDataTypeInterface for TimestampNano struct.
// 实现 GormDataTypeInterface 接口
func (t TimestampNano) GormDataType() string {
return "int"
}