Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2421,10 +2421,12 @@ private String adjustFieldTypes(PatternWithMatcher patternWithMatcher, DateTimeM
}
int adjFieldLen = reqFieldLen;
DateTimeMatcher matcherWithSkeleton = patternWithMatcher.matcherWithSkeleton;
if ( (type == HOUR && (options & MATCH_HOUR_FIELD_LENGTH)==0) ||
(type == MINUTE && (options & MATCH_MINUTE_FIELD_LENGTH)==0) ||
(type == SECOND && (options & MATCH_SECOND_FIELD_LENGTH)==0) ) {
adjFieldLen = fieldBuilder.length();
if (type == HOUR || type == MINUTE || type == SECOND) {
if ((type == HOUR && (options & MATCH_HOUR_FIELD_LENGTH)==0)
|| (type == MINUTE && (options & MATCH_MINUTE_FIELD_LENGTH)==0)
|| (type == SECOND && (options & MATCH_SECOND_FIELD_LENGTH)==0)) {
adjFieldLen = fieldBuilder.length();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the extra test getting you here? I'm not seeing how that changes the logic, but it must, since the unit-test results are different. What am I missing here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The else if had previously been reachable my hour/minute/second, and it was causing the field widths to revert to the pattern widths. With this change, the else if is no longer reachable on those fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, that's what I was missing. Thanks for the clarification.

} else if (matcherWithSkeleton != null && reqFieldChar != 'c' && reqFieldChar != 'e') {
// (we skip this section for 'c' and 'e' because unlike the other characters considered in this function,
// they have no minimum field length-- 'E' and 'EE' are equivalent to 'EEE', but 'e' and 'ee' are not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void TestC() {
{"zh-TW", "CCCCm", "BBBBhh:mm"},
{"zh-TW", "CCCCCm", "BBBBBh:mm"},
{"zh-TW", "CCCCCCm", "BBBBBhh:mm"},
{"de", "Cm", "HH:mm"},
{"de", "Cm", "H:mm"},
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice you're only changing the Java code. The C++ code already did this?

Copy link
Member Author

@sffc sffc Sep 11, 2025

Choose a reason for hiding this comment

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

I figured I would start in ICU4J and continue to ICU4C once I got alignment. (The PR is Draft and I am seeking feedback.)

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fine, but it means I shouldn't have approved the PR yet. I can't figure out how to take that back without just blocking the PR (which I've always thought was kind of rude), so I'll trust you. :-)

{"de", "CCm", "HH:mm"},
{"de", "CCCm", "HH:mm"},
{"de", "CCCCm", "HH:mm"},
Expand Down Expand Up @@ -1344,7 +1344,7 @@ public void TestOptions() {
new TestOptionsItem( "en", "Hmm", "HH:mm", DateTimePatternGenerator.MATCH_NO_OPTIONS ),
new TestOptionsItem( "en", "HHmm", "HH:mm", DateTimePatternGenerator.MATCH_NO_OPTIONS ),
new TestOptionsItem( "en", "hhmm", "h:mm\u202Fa", DateTimePatternGenerator.MATCH_NO_OPTIONS ),
new TestOptionsItem( "en", "Hmm", "HH:mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH ),
new TestOptionsItem( "en", "Hmm", "H:mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this match what the C++ code does? And is there already a test somewhere that shows we still get two digits without MATCH_HOUR_FIELD_LENGTH?

new TestOptionsItem( "en", "HHmm", "HH:mm", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH ),
new TestOptionsItem( "en", "hhmm", "hh:mm\u202Fa", DateTimePatternGenerator.MATCH_HOUR_FIELD_LENGTH ),
new TestOptionsItem( "da", "Hmm", "HH.mm", DateTimePatternGenerator.MATCH_NO_OPTIONS ),
Expand Down
Loading