Skip to content

v2.6.18

Choose a tag to compare

@gouguoyin gouguoyin released this 28 Sep 13:22
· 42 commits to master since this release
d9a6370

English

✨ Features

  • Add Kazakh localised 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 Format method handles a trailing escape character: added boundary checks for escape character handling in format2layout method of helper.go to prevent panic caused by out-of-bounds access (by @gouguoyin in #348)
  • Fix incorrect weekday names returned by ToWeekString, ToShortWeekString, and Format when the week starts on a day other than Monday: ToWeekString / ToShortWeekString indexed the name resource by DayOfWeek() % DaysPerWeek, but the resources are ordered absolutely (Sunday first); now indexes by the absolute weekday int(StdTime().Weekday()), matching the resource order and mirroring what Format("l") already does (by @sneha4175 in #371)
  • Fix failure to clear the existing value when scanning NULL from a database into a field that already contains a time value: scanning a SQL NULL into an already populated Carbon value returned success but left the previous date in place; now resets the destination in Carbon.Scan and 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: SetLocale copies the whole cached locale map into every Language instance, so every Carbon instance allocates a fresh 20-entry map; now SetLocale shares the cached map and marks it as shared, SetResources copies before its first write, and everything that only reads resources keeps reading the shared map; per NewCarbon(), 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.Split on every call just to index one element; now a small helper locates the item in place using strings.Count and strings.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 fresh Language for every instance; now defaultLanguage(locale) caches one ready-to-use Language per locale in a sync.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

🚀 CI

  • Improve the CI test 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 to push events; added a dedicated test step using -race across 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 扫描 SQL NULL 时返回成功但保留原日期;现在在 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)

🔧 依赖升级

🚀 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