Skip to content

fix: pad negative years to four digits in ISO 8601 output#12

Merged
brickfrog merged 4 commits into
masterfrom
master.task-fix-negative-year
Mar 28, 2026
Merged

fix: pad negative years to four digits in ISO 8601 output#12
brickfrog merged 4 commits into
masterfrom
master.task-fix-negative-year

Conversation

@brickfrog
Copy link
Copy Markdown
Owner

Summary

pad4 treated negative years as a single signed integer, so year -500 formatted as -500 instead of the ISO 8601-style -0500 (sign plus four-digit absolute value).

Changes

  • Add pad4_year(year) that prefixes - and applies pad4 to the absolute value when year < 0; otherwise delegates to pad4.
  • Use it in DateTime::format and Show for Date. Show for DateTime already uses format(), so it picks up the fix automatically.
  • Add blackbox tests for years -500 and -1 (format and Show).
  • Ignore .cursor/ so local editor metadata does not block PR tooling.

Closes #5.

Add pad4_year so the year field is sign plus four-digit absolute value
(e.g. -0500, -0001). Use it in DateTime::format and Show for Date.

Closes #5.

Made-with: Cursor
Copilot AI review requested due to automatic review settings March 28, 2026 15:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes ISO 8601-style formatting for negative years by ensuring the year field is zero-padded to four digits after applying the sign, and adds regression tests to cover BC/negative-year formatting.

Changes:

  • Introduce pad4_year(year) to format signed years as - + zero-padded absolute value.
  • Use pad4_year in DateTime::format and Show for Date.
  • Add blackbox tests for -500 and -1 for both format() and Show, and ignore .cursor/ in .gitignore.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/tempo.mbt Adds pad4_year and routes Date/DateTime formatting through it to correct negative-year padding.
src/tempo_test.mbt Adds regression tests asserting correct formatting/Show output for negative years.
.gitignore Ignores .cursor/ editor metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tempo.mbt
// Year field for ISO 8601 / RFC 3339: sign plus four-digit absolute value.

///|
fn pad4_year(year : Int) -> String {
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pad4_year negates year to compute the absolute value. If year can ever be the minimum representable Int, -year will overflow/wrap and produce an incorrect string (potentially with a doubled -). Consider using an overflow-safe absolute-value conversion (or explicitly rejecting/guarding that input range for Date::new).

Suggested change
fn pad4_year(year : Int) -> String {
fn pad4_year(year : Int) -> String {
if year == Int::MIN {
panic("pad4_year: year is Int::MIN, which is not supported");
}

Copilot uses AI. Check for mistakes.
Comment thread src/tempo.mbt Outdated
Comment on lines +348 to +356
// Year field for ISO 8601 / RFC 3339: sign plus four-digit absolute value.

///|
fn pad4_year(year : Int) -> String {
if year < 0 {
"-" + pad4(-year)
} else {
pad4(year)
}
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says “ISO 8601 / RFC 3339: sign plus four-digit absolute value”, but (1) RFC 3339 does not allow signed/expanded years, and (2) pad4 doesn’t enforce exactly 4 digits for years ≥ 10000. Please update the comment to reflect the actual behavior/spec you intend to support (e.g., ISO 8601 expanded year with at least 4 digits), or adjust the implementation to match the documented constraint.

Copilot uses AI. Check for mistakes.
@brickfrog
Copy link
Copy Markdown
Owner Author

Choir: comment-only review received — routed to master.task-fix-negative-year (leaf pane).

Reject Int::min_value in pad4_year with abort (negation overflow). Document
RFC 3339 vs ISO 8601 expanded-year behavior and pad4 rules for large years.
Import moonbitlang/core/int for @int.min_value.

Made-with: Cursor
@brickfrog
Copy link
Copy Markdown
Owner Author

Choir: fixes pushed by master.task-fix-negative-year — awaiting re-review (not merged yet).

@brickfrog brickfrog merged commit 3604e7f into master Mar 28, 2026
@brickfrog brickfrog deleted the master.task-fix-negative-year branch May 13, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: negative year formatting in pad4

2 participants