-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
With reference to #4264 first reported by @chuanjiao10 - on further examination there are a number of UFormats outputs which diverge from the output under Linux. Because the UFormat parameter is supposed to be UNIX format, the output should match that of the date command (i.e. strftime) on Linux.
It's clear that some of the divergences are simple format issues, for instance leading zeros. Others are down to following the ISO 8601 week date specification (https://en.wikipedia.org/wiki/ISO_week_date). And others appear to be differences between locale data on Linux and .Net. In these latter cases it looks like the C locale is followed, which may actually be the best that can be done given the lack of Linux locale data.
%c
- (PR Correct %c, %l, %k, %s, %j format in Get-Date -UFormat #4805) The preferred date and time representation for the current locale.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %c Sat Jan 1 01:00:00 2005
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%cSat 01 Jan 2005 01:00:00 AM GMT
C
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %c Sat Jan 1 01:00:00 2005
Linux
LC_TIME="C.UTF-8" date -d 2005-01-01T01:00:00 +%cSat Jan 1 01:00:00 2005
%g
- (PR #4750 Fix Get-Date -UFormat %G and %g behavior #14555) Like %G, but without century, that is, with a 2-digit year (00-99).
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %g 05
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%g04
%G
- (PR #4750 Fix Get-Date -UFormat %G and %g behavior #14555) The ISO 8601 week-based year ... with century as a decimal number.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %g 2005
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%G2004
%j
- (PR Correct %c, %l, %k, %s, %j format in Get-Date -UFormat #4805) The day of the year as a decimal number (range 001 to 366).
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %j 1
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%j001
%k
- (PR Correct %c, %l, %k, %s, %j format in Get-Date -UFormat #4805) The hour (24-hour clock) as a decimal number (range 0 to 23); single digits are preceded by a blank.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %k 01
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%k 1
%l
- (PR Correct %c, %l, %k, %s, %j format in Get-Date -UFormat #4805) The hour (12-hour clock) as a decimal number (range 1 to 12); single digits are preceded by a blank.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %l 01
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%l 1
%s
- (PR Correct %c, %l, %k, %s, %j format in Get-Date -UFormat #4805) The number of seconds since the Epoch, 1970-01-01 00:00:00+0000 (UTC).
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -Millisecond 0 -UFormat %s 1104541200
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%s1104541200
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -Millisecond 1 -UFormat %s 1104541200.001
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00.001 +%s 1104541200
%u
- (PR #4750 Fix Get-Date -UFormat %u behavior #14549) The ISO 8601 day of the week 1-7 (M-Su).
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 2 -Hour 1 -Minute 0 -Second 0 -UFormat %u0
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-02T01:00:00 +%u7
%U
- The week number of the current year as a decimal number, range 00 to 53, starting with the first Sunday as the first day of week 01.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %U 0
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%U00
%V
- The ISO 8601 week number ... of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the new year.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %V 1
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%V53
%W
- The week number of the current year as a decimal number, range 00 to 53, starting with the first Monday as the first day of week 01.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %W 0
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%W00
%x
- The preferred date representation for the current locale without the time.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %x 01/01/05
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%x01/01/2005
C
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %x 01/01/05
Linux
LC_TIME="C.UTF-8" date -d 2005-01-01T01:00:00 +%x01/01/05
%X
- The preferred date representation for the current locale without the time.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %X 01:00:00
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%X01:00:00 AM
C
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %X 01:00:00
Linux
LC_TIME="C.UTF-8" date -d 2005-01-01T01:00:00 +%X01:00:00
%Z
- The timezone name or abbreviation.
en-US
PowerShell
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::GetCultureInfo('en-US')
get-date -Year 2005 -Month 1 -Day 1 -Hour 1 -Minute 0 -Second 0 -UFormat %Z +00
Linux
LC_TIME="en_US.UTF-8" date -d 2005-01-01T01:00:00 +%ZGMT
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.0-beta
PSEdition Core
GitCommitId v6.0.0-beta.5
OS Linux 4.10.0-32-generic #36~16.04.1-Ubuntu SM...
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0 I initially, naively, made PR #4508 for #4264 which simply used the GetWeekOfYear method from the Gregorian Calendar. Unfortunately that is too simplistic, and the formula needs to be followed to determine the correct week number. I suggest that PR be closed and new PRs to be created against this tracking issue. My suggestion is that the Pester tests be broken out into a test per UFormat to make this easier (with the failing tests commented until they can be addressed).