diff --git a/README.en.md b/README.en.md index f54992e..0fbcbe1 100755 --- a/README.en.md +++ b/README.en.md @@ -157,17 +157,17 @@ carbon.Parse("2020-08-05 13:14:15").SetSecond(60).ToDateTimeString() // 2020-08- // Start of the year carbon.Parse("2020-08-05 13:14:15").StartOfYear().ToDateTimeString() // 2020-01-01 00:00:00 // End of the year -carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToEndTimeString() // 2020-12-31 23:59:59 +carbon.Parse("2020-08-05 13:14:15").EndOfYear().ToDateTimeString() // 2020-12-31 23:59:59 // Start of the month carbon.Parse("2020-08-05 13:14:15").StartOfMonth().ToStartTimeString() // 2020-08-01 00:00:00 // End of the month -carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToEndTimeString() // 2020-08-31 23:59:59 +carbon.Parse("2020-08-05 13:14:15").EndOfMonth().ToDateTimeString() // 2020-08-31 23:59:59 // Start of the week -carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToStartTimeString() // 2020-08-03 00:00:00 +carbon.Parse("2020-08-05 13:14:15").StartOfWeek().ToDateTimeString() // 2020-08-03 00:00:00 // End of the week -carbon.Parse("2020-08-05 13:14:15").LastOfWeek().ToEndTimeString() // 2020-08-09 23:59:59 +carbon.Parse("2020-08-05 13:14:15").LastOfWeek().ToDateTimeString() // 2020-08-09 23:59:59 // Start of the day carbon.Parse("2020-08-05 13:14:15").StartOfDay().ToDateTimeString() // 2020-08-05 00:00:00 @@ -584,8 +584,8 @@ user := UserModel { user.ID // 18 user.Name // 勾国印 user.Birthday.ToDateString() // 2012-08-05 -user.CreatedAt.ToTimestamp() // 2012-08-05 13:14:15 -user.DeletedAt.ToDateTimeString() // 1596604455 +user.CreatedAt.ToTimestamp() // 1596604455 +user.DeletedAt.ToDateTimeString() // 2012-08-05 13:14:15 user.GraduatedAt.AddDay().ToDateString() // 2012-09-10 user.UpdatedAt.ToDateString() // 2012-08-05 ``` diff --git a/database.go b/database.go index 6036522..9e0c0cd 100644 --- a/database.go +++ b/database.go @@ -22,6 +22,22 @@ type ToTimestamp struct { Carbon } +type ToTimestampWithSecond struct { + Carbon +} + +type ToTimestampWithMillisecond struct { + Carbon +} + +type ToTimestampWithMicrosecond struct { + Carbon +} + +type ToTimestampWithNanosecond struct { + Carbon +} + func (c *Carbon) Scan(v interface{}) error { value, ok := v.(time.Time) if ok { @@ -59,3 +75,19 @@ func (c ToTimeString) MarshalJSON() ([]byte, error) { func (c ToTimestamp) MarshalJSON() ([]byte, error) { return []byte(fmt.Sprintf(`%d`, c.ToTimestamp())), nil } + +func (c ToTimestampWithSecond) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, c.ToTimestampWithSecond())), nil +} + +func (c ToTimestampWithMillisecond) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, c.ToTimestampWithMillisecond())), nil +} + +func (c ToTimestampWithMicrosecond) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, c.ToTimestampWithMicrosecond())), nil +} + +func (c ToTimestampWithNanosecond) MarshalJSON() ([]byte, error) { + return []byte(fmt.Sprintf(`%d`, c.ToTimestampWithNanosecond())), nil +}