PowerShell icon indicating copy to clipboard operation
PowerShell copied to clipboard

CreationTime date: Linux

Open 237dmitry opened this issue 3 years ago • 5 comments
trafficstars

Prerequisites

Steps to reproduce

What date is wrong?

 PS > & {
 >> $format = 'yyyy-MM-dd HH:mm:ss'
 >> (Get-Date (stat -c %w /root) -f $format) + " # $(which stat) 'birth time'"
 >> (Get-Item /root).CreationTime.ToString($format) + " # CreationTime"
 >> (Get-Date (stat -c %y /root) -f $format) + " # $(which stat) 'last modified time'"
 >> (Get-Item /root).LastAccessTime.ToString($format) + " # LastAccessTime"
 >> (Get-Item /root).LastWriteTime.ToString($format) + " # LastWriteTime"  
 >> }
2021-03-10 22:31:43 # /usr/bin/stat 'birth time'
2022-06-04 23:48:49 # CreationTime
2022-06-04 23:48:49 # /usr/bin/stat 'last modified time'
2021-03-10 22:35:51 # LastAccessTime
2022-06-04 23:48:49 # LastWriteTime

Expected behavior

CreationTime must be equivalent to the native `stat` birth of file

Actual behavior

Creation time equivalent `stat` last modified time

Error details

No errors

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.7
PSEdition                      Core
GitCommitId                    7.2.7
OS                             Linux 6.0.5-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 26 Oct 2022 15:25:45 +0000
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

237dmitry avatar Oct 28 '22 17:10 237dmitry

PS. UnixStat also does not return proper datetime of file creation.

237dmitry avatar Oct 28 '22 17:10 237dmitry

CreationTime comes from the .NET FileInfo type. If that value is incorrect, you'll need to open an issue here: https://github.com/dotnet/runtime

GitHub
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps. - GitHub - dotnet/runtime: .NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.

SteveL-MSFT avatar Oct 28 '22 19:10 SteveL-MSFT

Yes, System.IO.DirectoryInfo and FileInfo give wrong information.

237dmitry avatar Oct 28 '22 20:10 237dmitry

Can you check on latest pwsh build?

iSazonov avatar Oct 29 '22 06:10 iSazonov

The same result, 7.3.0-rc.1

PS. But there is also good news, [console]::ReadKey() has learned to correctly recognize arrow keys ))

237dmitry avatar Oct 29 '22 07:10 237dmitry

Can you check on latest pwsh build?

Problem still exists in PowerShell 7.4.0-preview.4. But as @SteveL-MSFT indicated, this is a .NET problem. See dotnet/runtime#42372.

sdwheeler avatar Aug 21 '23 18:08 sdwheeler

The WG discussed this and agree this is a .NET issue.

sdwheeler avatar Aug 23 '23 20:08 sdwheeler

This issue has been marked as external and has not had any activity for 1 day. It has been be closed for housekeeping purposes.