All contributions

dromara/carbon

dromara/carbon

A Go package for dates and times with a simple, readable API, with helpers such as the start and end of a minute, a day or a century.

Language
Go
GitHub stars
5,225
Merged changes
1
Project site
dromara.org

What we changed

StartOfMinute and EndOfMinute keep the same instant, location and offset, also in the hour that repeats when the clocks go back.

What this work shows

  • Time zones and DST transitions
  • Go's time package
  • LMT offsets with seconds
What was broken

A minute that ended before its own instant

StartOfMinute and EndOfMinute rebuilt the time with time.Date from the year, month, day, hour and minute. In the hour that repeats when the clocks go back, 01:34:49 EST in New York got a minute that ended before that instant.

How we fixed it

Seconds subtracted from the existing instant

Both functions now copy the instance and subtract the local seconds and nanoseconds, so they keep the instant, location and offset. We avoided Truncate(time.Minute), which breaks LMT offsets with seconds, and tests cover New York, Lord Howe and Monrovia from the time of such an offset.

#378

Merged change 1

  1. #378 fix(boundary): preserve instants at minute boundaries Merged 10 October 2026

What it taught us

Rebuilding a time from its parts loses which of two repeated hours was meant. It is safer to subtract the seconds from the existing instant and test it on zones with unusual offsets.

More about this technology: Golang

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.