Skip to content

fix: report non-zero megabyte size for xkcd-kb unit in non-leap years - #740

Merged
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/w3-scc-xkcd
Aug 10, 2026
Merged

fix: report non-zero megabyte size for xkcd-kb unit in non-leap years#740
boyter merged 1 commit into
boyter:masterfrom
YuriNachos:YuriNachos/w3-scc-xkcd

Conversation

@YuriNachos

Copy link
Copy Markdown
Contributor

The xkcd-kb size case assigned size only inside the leap-year branch with no else, so in a non-leap year size stayed 0.0 and scc printed 0.000 megabytes (XKCD-KB) for every file — in 3 of every 4 years. This contradicts the unit's own help text "1000 bytes during leap years, 1024 otherwise" (which says non-leap must be 1024-based = 1,048,576). Reproduced on master: 3,000,001-byte file, year 2026 → "0.000 megabytes". Every other --size-unit emits a real figure.

Fix

Divide by a new pure helper xkcdKbDivisor(year) returning 1_000_000 (1000-based) in a leap year and 1_048_576 (1024-based) otherwise — mirroring the existing pure isLeapYear(year). No languages.json change, so no go generate drift.

Test plan

go test -race ./processor/... — green, including a new TestCalculateSizeXkcdKb that asserts the output is non-zero in a non-leap year and matches 10_000_000/(1024*1024) = 9.537 megabytes, plus year-independent assertions xkcdKbDivisor(2026) == 1_048_576 and xkcdKbDivisor(2024) == 1_000_000.

I licence this contribution under the MIT licence.

The xkcd-kb size case assigned `size` only inside the leap-year branch with no
else, so in a non-leap year `size` stayed 0.0 and the output read
"0.000 megabytes" for any byte count, contradicting the unit's help text
"1000 bytes during leap years, 1024 otherwise".

Divide by a new pure helper xkcdKbDivisor(year) returning 1_000_000 (1000-based)
in leap years and 1_048_576 (1024-based) otherwise, mirroring the existing pure
isLeapYear(year). Adds TestCalculateSizeXkcdKb covering both year classes.

I licence this contribution under the MIT licence.
@pr-insights pr-insights Bot added L/complexity Low complexity M/size Normal or medium sized change labels Aug 8, 2026
@boyter
boyter merged commit 4c75f88 into boyter:master Aug 10, 2026
3 checks passed
@boyter

boyter commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Cheers. Should make it to the next release which should be soon.

@YuriNachos
YuriNachos deleted the YuriNachos/w3-scc-xkcd branch August 10, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L/complexity Low complexity M/size Normal or medium sized change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants