Skip to content
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

use StartOfHour and SetLocation #292

Closed
kamly opened this issue Apr 2, 2025 · 1 comment
Closed

use StartOfHour and SetLocation #292

kamly opened this issue Apr 2, 2025 · 1 comment
Labels
Bug Report a reproducible bug or regression

Comments

@kamly
Copy link

kamly commented Apr 2, 2025

Hello,

I encountered an issue with the following code:

func Demo(t time.Time) {
	fmt.Println(t.Location())

	tt := carbon.CreateFromStdTime(t).
		SetLocation(t.Location()).
		StartOfHour().
		StdTime()

	fmt.Println(tt)

	fmt.Println(time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), 0, 0, 0, t.Location()))
}

func Test_demo2(t *testing.T) {
	loc, _ := time.LoadLocation("Asia/Shanghai")
	Demo(time.Date(2024, 3, 15, 14, 30, 45, 123456789, loc))
}

golang version: go version go1.23.4 darwin/amd64

carbon version: v2.6.1

time zone: Asia/Shanghai

I expected to get:

Asia/Shanghai
2024-03-15 14:00:00 +0800 CST
2024-03-15 14:00:00 +0800 CST

But I actually get:

Asia/Shanghai
2024-03-15 14:00:00 +0000 UTC  --  error, timezone not right
2024-03-15 14:00:00 +0800 CST

Thanks!

@kamly kamly added the Bug Report a reproducible bug or regression label Apr 2, 2025
@kuafuRace
Copy link
Collaborator

kuafuRace commented Apr 2, 2025

use v2.6.2-rc2

go get -u gitee.com/dromara/carbon/v2@v2.6.2-rc2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants