fix(Foundation): %c format specifier emits centiseconds (#3949)#5350
Merged
Conversation
Documentation describes %c as "centisecond" but the implementation was emitting a single-digit decisecond (millisecond / 100). Bring the code in line with the documentation: %c now formats and parses a zero-padded two-digit centisecond value (00 .. 99), i.e. millisecond / 10. Affects DateTimeFormatter (DateTime and Timespan overloads), DateTimeParser, and PatternFormatter. The format/parse pair stays consistent so round-tripping a value via "%H:%M:%S.%c" preserves the centisecond resolution. Updated docs in DateTimeFormatter.h and PatternFormatter.h to read "centisecond (00 .. 99)". Adjusted the existing testCustom assertion that hard-coded the old single-digit output, and added focused testFractionalSpecifiers tests in both DateTimeFormatterTest and DateTimeParserTest covering the boundary values and a format/parse round trip. Note: this is a behavioural change for callers that relied on %c producing a single digit. PatternFormatter timestamps that include %c (e.g. the format used by the Logger and FastLogger samples, "%H:%M:%S.%c") will now contain one extra character.
264999c to
719aac5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
%cspecifier was documented as "centisecond" but emitted a single-digit decisecond (millisecond / 100). Bring the implementation in line with the documentation:%cnow formats and parses a zero-padded two-digit centisecond value (00 .. 99), i.e.millisecond / 10.Affects
DateTimeFormatter(DateTime and Timespan overloads),DateTimeParser, andPatternFormatter. The format/parse pair stays consistent so round-tripping a value via"%H:%M:%S.%c"preserves centisecond resolution.Updated docs in
DateTimeFormatter.handPatternFormatter.hto read "centisecond (00 .. 99)". Added focusedtestFractionalSpecifiersto bothDateTimeFormatterTestandDateTimeParserTestcovering boundary values and a format/parse round trip. Adjusted the existingtestCustomassertion that hard-coded the old single-digit output.Behavioural change: callers that relied on
%cproducing a single digit will now see one extra character. PatternFormatter timestamps using%c(e.g. the Logger and FastLogger samples'"%H:%M:%S.%c") gain one character. Worth a CHANGELOG note.Closes #3949.
Test plan