Skip to content

Migration

Amir Iranmanesh edited this page Aug 11, 2026 · 1 revision

Migration

From yaa110/go-persian-calendar

Change the import path. That is the whole migration for most projects:

-import ptime "github.com/yaa110/go-persian-calendar"
+import ptime "github.com/amiranmanesh/go-persian-calendar"
go mod edit -replace github.com/yaa110/go-persian-calendar=github.com/amiranmanesh/go-persian-calendar@v1.4.0
# or, to change it properly:
grep -rl 'yaa110/go-persian-calendar' . | xargs sed -i '' 's|yaa110/go-persian-calendar|amiranmanesh/go-persian-calendar|g'
go mod tidy

Every exported identifier kept its name and signature, so the code around it does not change.

Requirements

Go 1.21 or newer, up from 1.20.

Three behavior changes

All three are bug fixes. If you have golden files or snapshot tests, these are the ones to look at.

1. Fractional seconds in TimeFormat

The old implementation built the fraction from the decimal digits of the nanosecond field rather than from its value, so the result was off by however many leading zeros the number happened to have.

For a time with 52065090 nanoseconds:

Layout Before Now
.000 .520 .052
.000000 .520650 .052065
.000000000 .52065090 .052065090
.999 .52 .052
.999999 .52065 .052065
.999999999 .5206509 .05206509

The new values match time.Time.Format for the same instant.

2. ZoneOffset with negative half-hour offsets

Offsets west of UTC with a non-zero minute part produced malformed output:

Zone Before Now
UTC−04:30 -04:-30 -04:30
UTC−09:30 -09:-30 -09:30

Whole hour offsets were always correct, which is why this went unnoticed.

3. Time.String()

String() now emits valid RFC 3339. The fractional second is trimmed of trailing zeros and omitted entirely when it is zero, and the zero Time has a fixed rendering instead of one that depended on the host time zone:

Case Before Now
no fraction 1394-07-02T12:59:59.0+03:30 1394-07-02T12:59:59+03:30
with fraction 1394-07-02T12:59:59.52065090+03:30 1394-07-02T12:59:59.05206509+03:30
zero Time depended on the local zone 0000-00-00T00:00:00Z

One deprecation

Time.Since still works, but returns the absolute number of seconds as an int64, which loses both the sign and the precision. Prefer Sub:

-elapsed := b.Since(a)              // int64 seconds, always positive
+elapsed := b.Sub(a)                // time.Duration, signed

What is new

Worth knowing about after you migrate — see the linked pages for detail:

  • Parsing: Parse, ParseInLocation, ParseTimeFormat, ParseTimeFormatInLocation
  • Encoding: JSON, text and SQL support on Time
  • Formatting: AppendFormat, AppendTimeFormat, the layout constants, and .000/.999 fraction patterns
  • Sub, Truncate, Round, UnixMilli, UnixMicro

Versioning

Tags below v1.4.0 in this repository were inherited from the upstream project and declare the old module path, so they were never installable from here. v1.4.0 is the first release published under github.com/amiranmanesh/go-persian-calendar.

Clone this wiki locally