-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
carbon.Date changed after marshal/unmarshal #178
Comments
More compact example: package main
import (
"fmt"
"github.com/golang-module/carbon/v2"
)
func main() {
d1 := carbon.Date{Carbon: carbon.CreateFromDateTime(2000, 1, 1, 0, 0, 0, carbon.UTC)}
d2 := carbon.Date{Carbon: carbon.ParseByLayout(d1.ToDateString(), carbon.DateLayout, carbon.UTC)}
fmt.Println(d1 == d2)
} Output:
|
Date1: carbon.Date{Carbon: carbon.CreateFromDate(2000, 1, 1, carbon.UTC)} The hours, minutes, seconds and nanosecond of func (c Carbon) CreateFromDate(year, month, day int, timezone ...string) Carbon {
now := c.Now(timezone...)
hour, minute, second := now.Time()
return c.create(year, month, day, hour, minute, second, now.Nanosecond(), timezone...)
} |
Thank you. I understand why this is happening. But I think it should be equal: fmt.Println(a.Date1.Carbon2Time().Unix(), b.Date1.Carbon2Time().Unix())
fmt.Println(a.Date2.Time.Unix(), b.Date2.Time.Unix()) |
a := A{
Date1: carbon.Date{Carbon: carbon.CreateFromDate(2000, 1, 1, carbon.UTC)},
Date2: Date{Time: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)},
} The timestamps of Date1: carbon.Date{Carbon: carbon.CreateFromDate(2000, 1, 1, carbon.UTC).StartOfDay()}, or Date1: carbon.Date{Carbon: carbon.CreateFromDateTimeNano(2000, 1, 1, 0, 0, 0, 0, carbon.UTC)}, |
But code from the first post returns: ❯ go run main.go
946743050 946684800
946684800 946684800
❯ cat go.mod
module demo
go 1.21.0
require github.com/golang-module/carbon/v2 v2.2.6 |
I think it should be fixed: https://github.com/golang-module/carbon/issues/178#issuecomment-1695140491 |
Hello,
I encountered an issue with the following code:
golang version: 1.21.0
carbon version: v2.2.3
time zone: Asia/Novokuznetsk
I expected to get:
But I actually get:
Thanks!
The text was updated successfully, but these errors were encountered: