Repository navigation
v2.6.18
English
✨ Features
- Add
Kazakhlocalised language support (lang/kk.json): month names, short month names, weekday names and short weekday names are taken verbatim from the Kazakh locale of PHP Carbon, which follows CLDR; relative time phrases follow Kazakh grammar where nouns do not inflect for number after a numeral; seasons and constellations are translated directly using traditional Kazakh names (by @darakanoit in #355)
🐛 Fixes
- Fix possible out-of-bounds access when the
Formatmethod handles a trailing escape character: added boundary checks for escape character handling informat2layoutmethod ofhelper.goto preventpaniccaused by out-of-bounds access (by @gouguoyin in #348) - Fix incorrect weekday names returned by
ToWeekString,ToShortWeekString, andFormatwhen the week starts on a day other than Monday:ToWeekString/ToShortWeekStringindexed the name resource byDayOfWeek() % DaysPerWeek, but the resources are ordered absolutely (Sunday first); now indexes by the absolute weekdayint(StdTime().Weekday()), matching the resource order and mirroring whatFormat("l")already does (by @sneha4175 in #371) - Fix failure to clear the existing value when scanning
NULLfrom a database into a field that already contains a time value: scanning a SQLNULLinto an already populated Carbon value returned success but left the previous date in place; now resets the destination inCarbon.Scanand the layout, format, and timestamp scanner wrappers (by @vitalivo in #360)
⚡ Performance
- Optimize language instance and resource caching and sharing through copy-on-write to reduce memory allocation:
SetLocalecopies the whole cached locale map into everyLanguageinstance, so every Carbon instance allocates a fresh 20-entry map; nowSetLocaleshares the cached map and marks it as shared,SetResourcescopies before its first write, and everything that only reads resources keeps reading the shared map; perNewCarbon(), allocation drops from 1600 B / 13 allocs to 232 B / 4 allocs (by @darakanoit in #350) - Optimize localized resource lookups for months, weekdays, seasons, and constellations to avoid splitting strings on every call: six methods read a "|" separated language resource and call
strings.Spliton every call just to index one element; now a small helper locates the item in place usingstrings.Countandstrings.IndexByte, zero allocations per call;Constellation-61.54%,ToShortWeekString-47.35%,ToWeekString-44.13%,Season-40.65%,ToMonthString-37.66%,ToShortMonthString-35.88% (by @darakanoit in #352) - Share one language instance per locale:
NewCarbon()built a freshLanguagefor every instance; nowdefaultLanguage(locale)caches one ready-to-useLanguageper locale in async.Map; constructing a Carbon goes from 4 allocations to 1 (by @darakanoit in #354) - Optimize lunar date conversion by precomputing tables for days per year and cumulative days: both lunar conversions walked the year table instead of indexing it, costing O(years since 1900); now derives the number of days in each supported year and the running total once at package initialisation; 2020 date to lunar 1009 ns -> 282 ns (-72%), back to gregorian 738 ns -> 23 ns (-97%) (by @darakanoit in #357)
🔧 Dependencies
- Upgrade
github.com/stretchr/testifyfromv1.11.1tov1.12.1(by @dependabot[bot] in #341 #344) - Upgrade
github/codeql-actionfromv4.37.4tov4.38.1(by @dependabot[bot] in #340 #342 #345 #346 #362 #369)
🚀 CI
- Improve the
CItest workflow to run the full test suite and race detection on PRs, and generate and upload coverage only on push: test commands now target all packages via./...instead of only the root package; coverage file generation and Codecov upload are gated topushevents; added a dedicated test step using-raceacross all packages (by @gouguoyin in #361)
中文
✨ 新功能
- 新增对
哈萨克语的本地化语言支持(lang/kk.json):月份名称、短月份名称、星期名称和短星期名称取自 PHP Carbon 的哈萨克语本地化文件(遵循 CLDR);相对时间短语遵循哈萨克语语法,名词在数字后不变格;季节和星座使用传统哈萨克名称直译(by @darakanoit in #355)
🐛 修复
- 修复
Format方法处理末尾转义字符时可能发生越界访问的 bug:在helper.go的format2layout方法中为转义字符处理添加边界检查,防止越界访问导致的panic(by @gouguoyin in #348) - 修复设置非周一为一周开始日期时,
ToWeekString、ToShortWeekString和Format方法返回星期名称错误的 bug:ToWeekString/ToShortWeekString曾通过DayOfWeek() % DaysPerWeek索引名称资源,但资源按绝对顺序(周日优先)排列;现在改用int(StdTime().Weekday())按绝对星期索引,与Format("l")行为一致(by @sneha4175 in #371) - 修复向已有时间值的数据库字段扫描
NULL时未清空原值的 bug:向已包含时间值的 Carbon 扫描 SQLNULL时返回成功但保留原日期;现在在Carbon.Scan及布局、格式和时间戳扫描器包装器中重置目标值(by @vitalivo in #360)
⚡ 性能优化
- 优化语言实例和语言资源的缓存与共享机制,通过写时复制减少内存分配:
SetLocale此前将完整的缓存语言映射复制到每个Language实例,导致每个 Carbon 实例分配全新的 20 项映射;现在SetLocale共享缓存映射并标记为共享,SetResources在首次写入前复制,只读资源的方法继续使用共享映射;每个NewCarbon()的分配从 1600 B / 13 次降至 232 B / 4 次(by @darakanoit in #350) - 优化月份、星期、季节和星座本地化资源查询,避免每次调用分割字符串:六个方法每次调用都读取 "|" 分隔的语言资源并使用
strings.Split分割,仅为了索引一个元素;现在使用小型辅助函数通过strings.Count和strings.IndexByte原地定位元素,每次调用零分配;Constellation-61.54%,ToShortWeekString-47.35%,ToWeekString-44.13%,Season-40.65%,ToMonthString-37.66%,ToShortMonthString-35.88%(by @darakanoit in #352) - 每个 locale 共享一个语言实例:
NewCarbon()此前为每个实例构建全新的Language;现在defaultLanguage(locale)在sync.Map中缓存每个 locale 一个即用型Language;构造 Carbon 的分配从 4 次降至 1 次(by @darakanoit in #354) - 优化农历日期转换,预计算年度天数和累计天数表:农历转换此前遍历年份表而非索引,时间复杂度为 O(1900年以来的年数);现在在每个支持的年份和累计总数在包初始化时推导一次;2020 日期转农历 1009 ns -> 282 ns(-72%),转回公历 738 ns -> 23 ns(-97%)(by @darakanoit in #357)
🔧 依赖升级
- 将
github.com/stretchr/testify从v1.11.1升级到v1.12.1(by @dependabot[bot] in #341 #344) - 将
github/codeql-action从v4.37.4升级到v4.38.1(by @dependabot[bot] in #340 #342 #345 #346 #362 #369)
🚀 CI
- 完善
CI测试流程,在PR上运行完整测试和竞态检测,并仅在push时生成和上传覆盖率:测试命令现在通过./...覆盖所有包,而非仅根包;覆盖率文件生成和 Codecov 上传限制为push事件;新增使用-race的全包竞态检测步骤(by @gouguoyin in #361)
What's Changed
-
build(deps): bump github/codeql-action from 4.37.4 to 4.37.6 by @dependabot[bot] in #340
-
build(deps): bump github.com/stretchr/testify from 1.11.1 to 1.12.0 by @dependabot[bot] in #341
-
build(deps): bump github/codeql-action from 4.37.6 to 4.37.7 by @dependabot[bot] in #342
-
build(deps): bump github.com/stretchr/testify from 1.12.0 to 1.12.1 by @dependabot[bot] in #344
-
build(deps): bump github/codeql-action from 4.37.7 to 4.37.8 by @dependabot[bot] in #345
-
build(deps): bump github/codeql-action from 4.37.8 to 4.37.9 by @dependabot[bot] in #346
-
Fix possible out-of-bounds access when formatting time by @gouguoyin in #348
-
perf(language): Copy locale resources on write instead of on every SetLocale by @darakanoit in #350
-
perf(i18n): Look up language resources without splitting them on every call by @darakanoit in #352
-
perf(language): Share one language instance per locale by @darakanoit in #354
-
Add Kazakh Language Support by @darakanoit in #355
-
perf(lunar): Derive the day tables once instead of recounting them per call by @darakanoit in #357
-
Clear previous date values when scanning SQL NULL by @vitalivo in #360
-
CI: run full Go test suite on PRs; gate coverage upload to push by @gouguoyin in #361
-
build(deps): bump github/codeql-action from 4.37.9 to 4.38.0 by @dependabot[bot] in #362
-
build(deps): bump github/codeql-action from 4.38.0 to 4.38.1 by @dependabot[bot] in #369
-
fix(outputer): name the weekday independently of the week start by @sneha4175 in #371
Full Changelog: v2.6.17...v2.6.18