Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Force short date pattern to use yyyy on Linux #18316

Merged
merged 2 commits into from
Jun 7, 2018

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Jun 5, 2018

The default pattern we get is using yy which causes the years to be displayed as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digit year in the optional list

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list
@tarekgh tarekgh self-assigned this Jun 5, 2018
@tarekgh
Copy link
Member Author

tarekgh commented Jun 5, 2018

@tarekgh
Copy link
Member Author

tarekgh commented Jun 5, 2018

@krwq @AlexGhiondea could you please help to review this one? Thanks.

@tarekgh tarekgh requested a review from krwq June 5, 2018 23:36
int index = 0;

while (index < s.Length)
{
Copy link
Member

Choose a reason for hiding this comment

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

Why are ticks getting special treatment? A comment with some example inputs and outputs might help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure what you mean by ticks here. I thought the comment before the method should be clear. I'll try to clarify it. basically, if try to format any date with the short pattern on Linux the year will be displayed as 2 digits. "6/5/18" this formatting has nothing to do with the date ticks. the fix is to display the year as 4 digits


string s = shortDatePatterns[0];

if (s.Length > 100)

Choose a reason for hiding this comment

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

A comment about why 100 is special would help.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had to pick some number to ensure we'll not cause a stack overflow. 100 is more than enough for the date pattern but I'll add a comment

index++;
}

if (index >= s.Length - 1 || s[index + 1] != 'y')
Copy link
Member

@krwq krwq Jun 6, 2018

Choose a reason for hiding this comment

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

index + 1 >= s.Length would make it easier to see there is no edge case here, if you increment index before it might also simplify the rest a little bit

Copy link
Member Author

Choose a reason for hiding this comment

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

I think for code readability, what I have is better is you read it we are checking where the index now and if we crossed the boundaries. I prefer to keep the way I wrote but let me know if you still feel strongly about it.

Copy link
Member

Choose a reason for hiding this comment

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

for this one not strongly

return;
}

if (index <= s.Length - 3 && s[index + 2] == 'y')
Copy link
Member

@krwq krwq Jun 6, 2018

Choose a reason for hiding this comment

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

index + 2 < s.Length? Also consider incrementing before

Copy link
Member Author

Choose a reason for hiding this comment

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

ditto as last comment

Copy link
Member

Choose a reason for hiding this comment

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

for this one it would be easier to read if you use 2

}

return result;
}

// FixDefaultShortDatePattern will convert the default short date pattern from using 'yy' to using 'yyyy'
// And will ensure the original pattern still exist in the list
private static void FixDefaultShortDatePattern(List<string> shortDatePatterns)
Copy link
Member

Choose a reason for hiding this comment

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

I might be missing context but are we assuming there will be only one 'yy'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. if we have more than one yy that will be ok because we'll convert at least one of them which will show the 4 digit year


shortDatePatterns[0] = modifiedPattern.ToString();

for (int i=1; i < shortDatePatterns.Count; i++)
Copy link
Member

Choose a reason for hiding this comment

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

nit: spaces around =

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll fix that

Copy link
Member

@krwq krwq left a comment

Choose a reason for hiding this comment

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

added couple of comments

@tarekgh
Copy link
Member Author

tarekgh commented Jun 6, 2018

@dotnet-bot test Ubuntu x64 Checked corefx_baseline

@tarekgh
Copy link
Member Author

tarekgh commented Jun 6, 2018

@dotnet/dnceng could you help to find out what is the problem with Ubuntu x64 Checked Build and Test (Jit - CoreFx)? The console log doesn't seem to be much useful

@markwilkie
Copy link
Member

Investigating as part of https://github.com/dotnet/core-eng/issues/3639

@tarekgh tarekgh merged commit a513283 into dotnet:master Jun 7, 2018
dotnet-bot pushed a commit to dotnet/corert that referenced this pull request Jun 7, 2018
* Force short date pattern to use yyyy on Linux

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list

* Address the review feedback

Signed-off-by: dotnet-bot <[email protected]>
jkotas pushed a commit to dotnet/corert that referenced this pull request Jun 7, 2018
* Force short date pattern to use yyyy on Linux

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list

* Address the review feedback

Signed-off-by: dotnet-bot <[email protected]>
dotnet-bot pushed a commit to dotnet/corefx that referenced this pull request Jun 7, 2018
* Force short date pattern to use yyyy on Linux

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list

* Address the review feedback

Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>
tarekgh added a commit to dotnet/corefx that referenced this pull request Jun 7, 2018
* Force short date pattern to use yyyy on Linux

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list

* Address the review feedback

Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>
@alam-manjur
Copy link

alam-manjur commented Jul 9, 2018

@tarekgh - I tried to use dotnet core build pack 2.1.3, it did not resolve my issue (still getting 7/6/18) for format d, could you please help me to resolve for the same. Thanks in advance

@tarekgh
Copy link
Member Author

tarekgh commented Jul 9, 2018

I tried to use dotnet core build pack 2.1.3, it did not resolve my issue (still getting 7/6/18) for format d, could you please help me to resolve for the same. Thanks in advance

This is fixed in 3.0. we didn't change 2.1 behavior for app compatibility reason.

@tarekgh tarekgh deleted the UpdateTheDefaultShortDatePattern branch March 25, 2019 15:29
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Force short date pattern to use yyyy on Linux

The default pattern we get is using yy which causes the years  to be displayed  as 2 digits. This is not acceptable for many users. The fix here is to force 4-digit year as a default and still keep the original pattern which has 2-digits year in the optional list

* Address the review feedback


Commit migrated from dotnet/coreclr@a513283
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants