Closed sba923 closed 3 years ago
Is this behaviour new in the latest preview or has it always been this way?
I would say it's new in preview 3. Too bad, I've just upgraded my last system, so I don't have any preview 2 system anymore.
We'll need to confirm if there was a change at some point or if this is the original behaviour.
Also, can you confirm if this is affected at all by using the -UseCulture
parameter explicitly?
We use Datetime.ToLongTimeString()
method for output in the case.
Also you could look (Get-Culture).DateTimeFormat
.
In 7.0.1:
> $PSVersionTable.PSVersion.ToString(); (Get-Culture).DateTimeFormat
7.0.1
AMDesignator : AM
Calendar : System.Globalization.GregorianCalendar
DateSeparator : -
FirstDayOfWeek : Monday
CalendarWeekRule : FirstDay
FullDateTimePattern : dddd, MMMM d, yyyy HH:mm:ss
LongDatePattern : dddd, MMMM d, yyyy
LongTimePattern : HH:mm:ss
MonthDayPattern : MMMM d
PMDesignator : PM
RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern : yyyy-MM-dd
ShortTimePattern : HH:mm
SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator : :
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern : MMMM yyyy
AbbreviatedDayNames : {Sun, Mon, Tue, Wed…}
ShortestDayNames : {Su, Mo, Tu, We…}
DayNames : {Sunday, Monday, Tuesday, Wednesday…}
AbbreviatedMonthNames : {Jan, Feb, Mar, Apr…}
MonthNames : {January, February, March, April…}
IsReadOnly : True
NativeCalendarName : Gregorian Calendar
AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr…}
MonthGenitiveNames : {January, February, March, April…}
In 7.1 preview 3:
> $PSVersionTable.PSVersion.ToString(); (Get-Culture).DateTimeFormat
7.1.0-preview.3
AMDesignator : AM
Calendar : System.Globalization.GregorianCalendar
DateSeparator : /
FirstDayOfWeek : Sunday
CalendarWeekRule : FirstDay
FullDateTimePattern : dddd, MMMM d, yyyy h:mm:ss tt
LongDatePattern : dddd, MMMM d, yyyy
LongTimePattern : h:mm:ss tt
MonthDayPattern : MMMM d
PMDesignator : PM
RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern : M/d/yyyy
ShortTimePattern : h:mm tt
SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator : :
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern : MMMM yyyy
AbbreviatedDayNames : {Sun, Mon, Tue, Wed…}
ShortestDayNames : {S, M, T, W…}
DayNames : {Sunday, Monday, Tuesday, Wednesday…}
AbbreviatedMonthNames : {Jan, Feb, Mar, Apr…}
MonthNames : {January, February, March, April…}
IsReadOnly : True
NativeCalendarName : Gregorian Calendar
AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr…}
MonthGenitiveNames : {January, February, March, April…}
We'll need to confirm if there was a change at some point or if this is the original behaviour.
Also, can you confirm if this is affected at all by using the
-UseCulture
parameter explicitly?
> $PSVersionTable.PSVersion.ToString(); Get-Date | ConvertTo-Csv -UseCulture
7.0.1
"DisplayHint","DateTime","Date","Day","DayOfWeek","DayOfYear","Hour","Kind","Millisecond","Minute","Month","Second","Ticks","TimeOfDay","Year"
"DateTime","Friday, May 22, 2020 19:33:59","2020-05-22 00:00:00","22","Friday","143","19","Local","174","33","5","59","637257728391742480","19:33:59.1742480","2020"
> $PSVersionTable.PSVersion.ToString(); Get-Date | ConvertTo-Csv -UseCulture
7.1.0-preview.3
"DisplayHint","DateTime","Date","Day","DayOfWeek","DayOfYear","Hour","Kind","Millisecond","Minute","Month","Second","Ticks","TimeOfDay","Year"
"DateTime","Friday, May 22, 2020 7:34:45 PM","5/22/2020 12:00:00 AM","22","Friday","143","19","Local","63","34","5","45","637257728850632108","19:34:45.0632108","2020"
Looks like a regression indeed. @iSazonov do you know if there were any changes merged to this area of code since 7.1-p2? I can't recall any at the moment.
Perhaps it's a regression or change in .NET Core?
Here's what I get with preview 2 on the same system:
> $PSVersionTable.PSVersion.ToString(); (Get-ItemProperty 'HKCU:\Control Panel\International' -name sTimeFormat).sTimeFormat; (Get-ItemProperty 'HKCU:\Control Panel\International' -name sShortDate).sShortDate; Get-Date -DisplayHint Time; Get-Date | ConvertTo-Csv
7.1.0-preview.2
HH:mm:ss
yyyy-MM-dd
19:42:05
"DisplayHint","DateTime","Date","Day","DayOfWeek","DayOfYear","Hour","Kind","Millisecond","Minute","Month","Second","Ticks","TimeOfDay","Year"
"DateTime","Friday, May 22, 2020 19:42:05","2020-05-22 00:00:00","22","Friday","143","19","Local","14","42","5","5","637257733250149958","19:42:05.0149958","2020"
> $PSVersionTable.PSVersion.ToString(); Get-Date | ConvertTo-Csv -UseCulture
7.1.0-preview.2
"DisplayHint","DateTime","Date","Day","DayOfWeek","DayOfYear","Hour","Kind","Millisecond","Minute","Month","Second","Ticks","TimeOfDay","Year"
"DateTime","Friday, May 22, 2020 19:42:40","2020-05-22 00:00:00","22","Friday","143","19","Local","847","42","5","40","637257733608470239","19:42:40.8470239","2020"
I can not confirm. After I changed these format strings in registry and restarted PowerShell I get right outputs.
What? Where was changing the format strings in the registry mentioned here? 😕
To get things right I uninstalled preview 3 and installed preview 2
😜
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
I don't understand: there is an issue in preview 3, it has to be fixed!
I can repo. We need reliable repo steps. You could download zip packages, install PowerShell side-by-side, run both version and check result (better on clean system).
You mean you can't repro?
I don't have a clean system to test on (could set up a test VM, but would take a significant amount of time).
I'll test with XCOPY-deployed SxS installations of preview 2 and preview 3.
Here's the outcome, using these launch scripts:
REM runpwsh.bat
cls
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
.\pwsh -noprofile -file .\runtest.ps1
# runtest.ps1
$PSVersionTable.PSVersion.ToString()
(Get-ItemProperty 'HKCU:\Control Panel\International' -name sTimeFormat).sTimeFormat
(Get-ItemProperty 'HKCU:\Control Panel\International' -name sShortDate).sShortDate
Get-Date -DisplayHint Time
Get-Date | ConvertTo-Csv
Repro'ed on two different systems.
What is output:
$Host
(Get-Culture).DateTimeFormat
On preview 2:
C:\tmp\PowerShell-7.1.0-preview.2-win-x64>PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
C:\tmp\PowerShell-7.1.0-preview.2-win-x64>.\pwsh -noprofile -file .\runtest.ps1
7.1.0-preview.2
Name : ConsoleHost
Version : 7.1.0-preview.2
InstanceId : 91f11a8e-5486-4058-b1e8-9bb93bb9adc9
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
AMDesignator : AM
Calendar : System.Globalization.GregorianCalendar
DateSeparator : -
FirstDayOfWeek : Monday
CalendarWeekRule : FirstDay
FullDateTimePattern : dddd, MMMM d, yyyy HH:mm:ss
LongDatePattern : dddd, MMMM d, yyyy
LongTimePattern : HH:mm:ss
MonthDayPattern : MMMM d
PMDesignator : PM
RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern : yyyy-MM-dd
ShortTimePattern : HH:mm
SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator : :
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern : MMMM yyyy
AbbreviatedDayNames : {Sun, Mon, Tue, Wed…}
ShortestDayNames : {Su, Mo, Tu, We…}
DayNames : {Sunday, Monday, Tuesday, Wednesday…}
AbbreviatedMonthNames : {Jan, Feb, Mar, Apr…}
MonthNames : {January, February, March, April…}
IsReadOnly : True
NativeCalendarName : Gregorian Calendar
AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr…}
MonthGenitiveNames : {January, February, March, April…}
On preview 3:
C:\tmp\PowerShell-7.1.0-preview.3-win-x64>PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
C:\tmp\PowerShell-7.1.0-preview.3-win-x64>.\pwsh -noprofile -file .\runtest.ps1
7.1.0-preview.3
Name : ConsoleHost
Version : 7.1.0-preview.3
InstanceId : 9244eab6-c591-4b06-9148-719bc5cba22d
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-US
CurrentUICulture : en-US
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
AMDesignator : AM
Calendar : System.Globalization.GregorianCalendar
DateSeparator : /
FirstDayOfWeek : Sunday
CalendarWeekRule : FirstDay
FullDateTimePattern : dddd, MMMM d, yyyy h:mm:ss tt
LongDatePattern : dddd, MMMM d, yyyy
LongTimePattern : h:mm:ss tt
MonthDayPattern : MMMM d
PMDesignator : PM
RFC1123Pattern : ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern : M/d/yyyy
ShortTimePattern : h:mm tt
SortableDateTimePattern : yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator : :
UniversalSortableDateTimePattern : yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern : MMMM yyyy
AbbreviatedDayNames : {Sun, Mon, Tue, Wed…}
ShortestDayNames : {S, M, T, W…}
DayNames : {Sunday, Monday, Tuesday, Wednesday…}
AbbreviatedMonthNames : {Jan, Feb, Mar, Apr…}
MonthNames : {January, February, March, April…}
IsReadOnly : True
NativeCalendarName : Gregorian Calendar
AbbreviatedMonthGenitiveNames : {Jan, Feb, Mar, Apr…}
MonthGenitiveNames : {January, February, March, April…}
What is time you change the datetime format?
The PowerShell versions use different .Net 5 Preview - 3 and 4. You could download nightly build (it is on .Net 5.0 Preview5) and check again. If you will see the issue you could discuss this in .Net Runtime repo.
I'm not sure I understand your question. When did I change the datetime format? That must've been when I installed the systems in the first place, 'cos as a software engineer I prefer 1) the English UI, so I changed the display language to English (my computers came with French Windows) 2) the ISO8601 YYYY-MM-DD date format. So I've probably never run any version of PowerShell with the default en-US date/time formats.
Where can I get the nightly builds from?
What is the .NET Core API that's used by PowerShell Core to convert a date/time to string? I need this information if I want to open an issue on .NET 5.0.
You can download night build from main page of the repository.
PowerShell uses Datetime.ToLongTimeString() method. All formats you get above with (Get-Culture).DateTimeFormat.
On that main page, I can see the status of the nightly builds in CI, but no download links. Am I missing something?
I'll try creating a C# test program and run it with various previous versions of .NET 5.
Press on the status icon and look artifacts under "Build for Windows".
Same repro:
The code that handles this is here:
With this code in mind, can you check what you get back for (Get-Date).ToString()
and (Get-Date).PSObject.ToString()
?
I'm reopening this as it doesn't look like we've gotten to the bottom of it yet. 🙂
What's the easy way to create a C# program that invokes that .ToString()
method and run it under various previews of .NET 5?
🤔 OK, that definitely looks like a regression in .NET 5 then, nice find.
Dunno if there's an easy way, but you can specify which preview to run against with usually a global.json
in the project folder; you can see an example in the global.json
in this repo. 🙂
If you can figure out which preview broke the ToString() behaviour, definitely worth opening up an issue on the dotnet/runtime repository so we can get that fixed.
You will save time if you discuss with .Net Runtime experts.
That's what I want to do next... once I have found how to deploy the last 3 previews of .NET 5 side-by-side to run the C# test program against. I presume there are XCOPY-deployable zipfiles of those previews somewhere...
Can someone help me find those .NET bits (at least the versions used by PS7.1 preview 2 and preview 3)?
Maybe I'll just wait until preview 4, based on .NET 5 Preview 5, comes out, and test again there...
You can download nightly build - it is on .Net 5 Preview 5 already.
Good news!
But... when I reach https://powershell.visualstudio.com/PowerShell/_build/results?buildId=55455&view=artifacts&type=publishedArtifacts I get:
and clicking artifacts
doesn't do anything. What am I doing wrong?
Sorry for sounding dumb, I'm definitely a GH CI rookie...
You can load nightly build from main page https://github.com/PowerShell/PowerShell#build-status-of-nightly-builds
GitHubPowerShell for every system! Contribute to PowerShell/PowerShell development by creating an account on GitHub.
That's exactly what I've been trying to do, see Can't download PS nightly build.zip
Try "Artifacts" - button on the right.
What "Artifacts" button on the right? Please refer to my PSR slideshow, or make a screenshot on your own.
I presume you wanted a ProcMon log of me reproducing the problem? Here it is, with preview 3.
@sba923 I still suggest to open new issue in .Net Runtime.
That's what I've been aiming at for some time now, but I can't unless I can post a repro. For this, I need to know how to get a side-by-side deployment of different previews of .NET 5, and then write a C# program I would run against each of those .NET previews. I haven't been able to find out how to download and deploy those previews. Yet...
Download link https://dotnet.microsoft.com/download/dotnet/5.0?utm_source=dotnet-website&utm_medium=banner&utm_campaign=preview5-banner You can use install scripts from the link.
Thanks for the hint.
But before I do this I'd like to test with a .NET 5 Preview 5-based build of PowerShell... ;-)
I think this is it ;-)
using System;
namespace DateTimeToString
{
class Program
{
static void Main(string[] args)
{
string dotnetversion = System.Environment.Version.ToString();
Console.WriteLine("dotnet version: {0}", dotnetversion);
var now = System.DateTime.Now;
string str = now.ToString();
Console.WriteLine("DateTime.Now.ToString(): {0}", str);
}
}
}
gci -dir 'dotnet5p*' | % {
$dotnetdir = $_.FullName
"Testing in: " + $dotnetdir
& ($dotnetdir + '\dotnet') --info | sls -raw 'Version:.*preview'
& ($dotnetdir + '\dotnet') ($dotnetdir + '\DateTimeToString.dll')
}
In procmon log I see an access to ICU - I guess the issue could be related to the fact.
It seems .Net has an option to opt out ICU. You could try and see a result.
Here's what I get with "System.Globalization.Invariant": true
if this is what you were referring to:
Formatting is incorrect whatever the .NET 5 preview version.
No, there is an option to switch back from ICU to Windows traditional API.
See https://docs.microsoft.com/en-us/dotnet/core/run-time-config/globalization#nls
Learn about run-time settings that configure globalization aspects of a .NET Core app, for example, how it parses Japanese dates.
Will test... The change to use ICU was introduced in .NET 5 preview 4...
This should speak for itself:
Steps to reproduce
en-US
cultureHH:mm:ss
and date format toyyyy-MM-dd
via SettingsGet-Date | ConvertTo-Csv
Expected behavior
Time is formatted using 24-hr format, date using specified
yyyy-MM-dd
format.Actual behavior
Time is formatted in 12-hr am/pm format, date using
M/dd/yyyy
formatEnvironment data