lestrrat-go / strftime

Fast strftime for Go
MIT License
117 stars 22 forks source link

Fix week number. #33

Closed ncruces closed 1 year ago

ncruces commented 1 year ago

Hi!

I created an alternative strftime implementation because I needed some additional things that'd be out of scope for this. I lifted some of your tests (so thanks!) and was comparing performance, and noticed a mismatch in week number handling.

This PR adds my (exhaustive) unit test and fixes it here.

Without the fix the output is:

$ go test                        
--- FAIL: TestFormat_WeekNumber (0.00s)
    strftime_test.go:396: Format("%U", 978307200) = "01", want "00"
    strftime_test.go:396: Format("%U", 978393600) = "01", want "00"
    strftime_test.go:396: Format("%U", 978480000) = "01", want "00"
    strftime_test.go:396: Format("%U", 978566400) = "01", want "00"
    strftime_test.go:396: Format("%U", 978652800) = "01", want "00"
    strftime_test.go:396: Format("%U", 978739200) = "01", want "00"
    strftime_test.go:396: Format("%U", 978825600) = "02", want "01"
    strftime_test.go:399: Format("%W", 1009843200) = "01", want "00"
    strftime_test.go:399: Format("%W", 1009929600) = "01", want "00"
    strftime_test.go:399: Format("%W", 1010016000) = "01", want "00"
    strftime_test.go:399: Format("%W", 1010102400) = "01", want "00"
    strftime_test.go:399: Format("%W", 1010188800) = "01", want "00"
    strftime_test.go:399: Format("%W", 1010275200) = "01", want "00"
    strftime_test.go:399: Format("%W", 1010361600) = "02", want "01"
    strftime_test.go:396: Format("%U", 1167609600) = "01", want "00"
    strftime_test.go:396: Format("%U", 1167696000) = "01", want "00"
    strftime_test.go:396: Format("%U", 1167782400) = "01", want "00"
    strftime_test.go:396: Format("%U", 1167868800) = "01", want "00"
    strftime_test.go:396: Format("%U", 1167955200) = "01", want "00"
    strftime_test.go:396: Format("%U", 1168041600) = "01", want "00"
    strftime_test.go:396: Format("%U", 1168128000) = "02", want "01"
    strftime_test.go:399: Format("%W", 1199145600) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199232000) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199318400) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199404800) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199491200) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199577600) = "01", want "00"
    strftime_test.go:399: Format("%W", 1199664000) = "02", want "01"
    strftime_test.go:399: Format("%W", 1356998400) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357084800) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357171200) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357257600) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357344000) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357430400) = "01", want "00"
    strftime_test.go:399: Format("%W", 1357516800) = "02", want "01"
    strftime_test.go:396: Format("%U", 1514764800) = "01", want "00"
    strftime_test.go:396: Format("%U", 1514851200) = "01", want "00"
    strftime_test.go:396: Format("%U", 1514937600) = "01", want "00"
    strftime_test.go:396: Format("%U", 1515024000) = "01", want "00"
    strftime_test.go:396: Format("%U", 1515110400) = "01", want "00"
    strftime_test.go:396: Format("%U", 1515196800) = "01", want "00"
    strftime_test.go:396: Format("%U", 1515283200) = "02", want "01"
    strftime_test.go:399: Format("%W", 1546300800) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546387200) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546473600) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546560000) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546646400) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546732800) = "01", want "00"
    strftime_test.go:399: Format("%W", 1546819200) = "02", want "01"
FAIL
exit status 1
FAIL    github.com/lestrrat-go/strftime 0.354s

You can validate my tests by running the following command, in macOS:

$ date -r 1546819200 +%W         
01

Or Linux:

$ date --date @1546819200 +%W         
01
codecov-commenter commented 1 year ago

Codecov Report

Merging #33 (4346282) into master (547681d) will increase coverage by 1.39%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
+ Coverage   79.92%   81.31%   +1.39%     
==========================================
  Files           7        7              
  Lines         274      273       -1     
==========================================
+ Hits          219      222       +3     
+ Misses         38       36       -2     
+ Partials       17       15       -2     
Impacted Files Coverage Δ
appenders.go 85.98% <100.00%> (+3.57%) :arrow_up:
lestrrat commented 1 year ago

welp. Thanks!