Skip to content

[LANG-1637] Fix 2 digit week year formatting#688

Merged
garydgregory merged 4 commits intoapache:masterfrom
ugonen:LANG-1637-fix-week-year-two-digits
Jan 6, 2021
Merged

[LANG-1637] Fix 2 digit week year formatting#688
garydgregory merged 4 commits intoapache:masterfrom
ugonen:LANG-1637-fix-week-year-two-digits

Conversation

@ugonen
Copy link
Contributor

@ugonen ugonen commented Dec 31, 2020

public void testWeekYear() {
final GregorianCalendar cal = new GregorianCalendar(2020, 12, 31, 0, 0, 0);
final DatePrinter printer4Digits = getInstance("YYYY");
final DatePrinter printer2Digits = getInstance("YY");
Copy link
Member

@garydgregory garydgregory Dec 31, 2020

Choose a reason for hiding this comment

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

Hi,
Thank you for your PR.
What about "YYY"?

Copy link
Member

Choose a reason for hiding this comment

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

Please add code in your new test for Y and YYY.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added, thanks

@ugonen
Copy link
Contributor Author

ugonen commented Jan 2, 2021

@garydgregory can you explain why you closed this PR ?
formatting date with year 31 Dec 2020 with pattern YY should result in '21' but instead you get 'ú1' (before the fix) which is clearly a bug

@garydgregory garydgregory reopened this Jan 2, 2021
@garydgregory
Copy link
Member

Reopening, I was going by the "invalid" comment.

@coveralls
Copy link

coveralls commented Jan 2, 2021

Coverage Status

Coverage decreased (-0.01%) to 95.001% when pulling b1ad8ae on ugonen:LANG-1637-fix-week-year-two-digits into f5c86f6 on apache:master.

@garydgregory
Copy link
Member

garydgregory commented Jan 2, 2021

@garydgregory
Copy link
Member

@michael-o The PR seems OK to me now. WDYT?

@ugonen ugonen requested a review from garydgregory January 2, 2021 16:16
@garydgregory garydgregory changed the title LANG-1637: fix 2 digit week year formatting [LANG-1637] Fix 2 digit week year formatting Jan 2, 2021
@michael-o
Copy link
Member

Will have a look.

@Override
public final void appendTo(final Appendable buffer, final int value) throws IOException {
appendDigits(buffer, value);
appendDigits(buffer, value % 100);
Copy link
Member

Choose a reason for hiding this comment

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

I am not convinced by this because it patches the wrong spot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the name TwoDigitYearField implies this class encapsulates formatting of year field to a 2 digit string. as such, it seems reasonable for it to have the logic to take any year integer and map it to a decade followed by a year digits.
you can also see that the other method in this class
void appendTo(Appendable buf, Calendar calendar) throws IOException
implementing the Rule interface, does the same

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Hi @michael-o
Earlier you said "I am not convinced by this because it patches the wrong spot." implying there was a "right" spot, but where would that be?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Well... which way is this one going to go? @ugonen Are you going to update your PR or @michael-o do you want to provide a different PR?

Copy link
Member

Choose a reason for hiding this comment

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

I think for the ease of use we have to use this one because my solution leaks abstraction. It makes too many assumptions about in the delegated NumberRule

@garydgregory garydgregory merged commit 63f644d into apache:master Jan 6, 2021
asfgit pushed a commit that referenced this pull request Jan 6, 2021
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.

4 participants