Skip to content
Closed
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 @@ -369,9 +369,7 @@ private string UFormatDateString(DateTime dateTime)
break;

case 'c':
sb.Append("{0:ddd} {0:MMM} ");
sb.Append(StringUtil.Format("{0,2} ", dateTime.Day));
sb.Append("{0:HH}:{0:mm}:{0:ss} {0:yyyy}");
sb.Append("{0:ddd} {0:MMM} {0:dd} {0:HH}:{0:mm}:{0:ss} {0:yyyy}");
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently, there are platform differences (not specific to the date utility implementation): on macOS 10.12.6 I get space-padded representation (e.g., <space>7), on Ubuntu 16.04 I get the 0-padded representation (e.g., 07).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On WSL I get space too. And it seems it can be culture-depended (see related Issue). I think we can not be full-compliant with Unix here. So we should follow "common" rule.

Copy link
Contributor

Choose a reason for hiding this comment

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

we should follow "common" rule.

I'm asking innocently: what do you mean by that?

I just checked the spec for the POSIX date utility, and the definition of %c is (a) definitely locale-(culture)-specific and (b) pretty open-ended:

%c
Locale's appropriate date and time representation.
...
The %x and %c conversion specifications, however, are intended for local representation; these may be based on a different, non-Gregorian calendar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I meant that "common" - used in most Unix clones.
Thank you for confirmation this is a locale-(culture)-specific. The problem may lie in the fact that we are forced to rely on CoreFX rather than Unix locales. I think that's a good compromise because our goal is to emulate Unix-like format. If we want more we should address this in CoreFX.

break;

case 'D':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" {
}

It "using -uformat 'aAbBcCdDehHIjmMpr' produces the correct output" {
Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should be "TueTuesdayJanJanuaryTue Jan 1 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM"
Get-date -Date 1/1/0030 -uformat %a%A%b%B%c%C%d%D%e%h%H%I%j%m%M%p%r | Should be "TueTuesdayJanJanuaryTue Jan 01 00:00:00 003000101/01/30 1Jan001210100AM12:00:00 AM"
}

It "using -uformat 'StTuUVwWxXyYZ' produces the correct output" {
Expand Down