Title: Date parameters handled differently for compiled c# cmdlets and functions. · Issue #16767 · PowerShell/PowerShell · GitHub
Open Graph Title: Date parameters handled differently for compiled c# cmdlets and functions. · Issue #16767 · PowerShell/PowerShell
X Title: Date parameters handled differently for compiled c# cmdlets and functions. · Issue #16767 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/16767
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Date parameters handled differently for compiled c# cmdlets and functions. ","articleBody":"### Prerequisites\n\n- [X] Write a descriptive title.\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [X] Search the existing issues.\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nIf a cmdlet takes a parameter of type `System.DateTime` a parameter passed to it is parsed using the **local** date format. \r\nIf a function takes a parameter of type `System.DateTime` a parameter passed to it is parsed using the **Invariant** time format. \r\n\r\nNote this will not be visible if the culture is US. \r\nFor example \r\n```\r\nps > set-culture fr-Fr\r\nps > pwsh -nologo\r\nps > get-date\r\nmardi 18 janvier 2022 17:57:15\r\n\r\nps > New-TimeSpan -Start \"18 janvier 2022\" -end \"19 janvier 2022\" | % days # French months recognized\r\n1\r\nps > function test {[cmdletbinding()] param ([system.datetime]$start, [system.datetime]$End) $end.Subtract($start)}\r\nps > test -Start \"18 janvier 2022\" -end \"19 janvier 2022\"\r\ntest: Cannot process argument transformation on parameter 'start'. Cannot convert value \"18 janvier 2022\" to type \"System.DateTime\". Error: \"The string '18 janvier 2022' was not recognized as a valid DateTime. There is an unknown word starting at index '3'.\"\r\n\r\nps > New-TimeSpan -Start 3/1/2022 -end 1/3/2022 | % days # parsed as d/m/y \r\n57\r\n> test -Start 3/1/2022 -end 1/3/2022 | % days # parsed as m/d/y\r\n-57\r\n```\r\nI compiled the cmdlet below and it behaved as the built in cmdlet did. \r\n\r\n```c#\r\nusing System;\r\nusing System.Management.Automation;\r\n\r\nnamespace psmodule {\r\n [Cmdlet(VerbsDiagnostic.Test,\"SampleCmdlet\")]\r\n public class TestSampleCmdletCommand : PSCmdlet {\r\n [Parameter(Position = 0)]\r\n public DateTime Before { get; set; }\r\n [Parameter(Position = 1)]\r\n public DateTime After { get; set; }\r\n protected override void BeginProcessing() {}\r\n protected override void ProcessRecord() { WriteObject(After.Subtract(Before) ); }\r\n protected override void EndProcessing() {}\r\n }\r\n}\r\n```\r\n\r\n**fixing this would be a breaking change** I would like to understand if there is a reason for it. \r\n\n\n### Expected behavior\n\n```console\nConsistent. See actual behavior\n```\n\n\n### Actual behavior\n\n```console\nps > New-TimeSpan -Start 3/1/2022 -end 1/3/2022 | % days # parsed as d/m/y \r\n57\r\n> test -Start 3/1/2022 -end 1/3/2022 | % days # parsed as m/d/y\r\n-57\r\nps > Test-SampleCmdlet -Before \"18 janvier 2022\" -after \"19 janvier 2022\" | % days # parsed in French \r\n1\r\nps > test -Start \"18 janvier 2022\" -end \"19 janvier 2022\" # Can only parse English \r\n\u003c\u003cerror janvier isn't recognized>>\n```\n\n\n### Error details\n\n_No response_\n\n### Environment data\n\n```powershell\nName Value\u001b[0m\r\n---- -----\u001b[0m\r\nPSVersion 7.2.1\r\nPSEdition Core\r\nGitCommitId 7.2.1\r\nOS Microsoft Windows 10.0.19043\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n\r\n(same on 5.1.19041.1320)\n```\n\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/jhoneill","@type":"Person","name":"jhoneill"},"datePublished":"2022-01-18T18:12:24Z","url":"https://github.com/PowerShell/PowerShell/issues/16767"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:70d1dc18-602e-80cb-7254-5392ddc13b01 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEE2:33AF49:1785D1:20BF42:6AFD6E78 |
| html-safe-nonce | e170bb497b9615fa340b84a80e2d602dd6f86e238ccafb08e5be44c7d6d717db |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRUUyOjMzQUY0OToxNzg1RDE6MjBCRjQyOjZBRkQ2RTc4IiwidmlzaXRvcl9pZCI6IjQ2NzA5NzEyNTc2OTUzMzQwMDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7bbe2dd50668e3e0f13807ad7662351e55240de4a5dbdc5d0a448820eed6efe3 |
| hovercard-subject-tag | issue:1107216066 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/16767/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25cc9960b2aaf00ba6f84c8dcd328698a3e502f0e30af909d2563c08a4caedd2/PowerShell/PowerShell/issues/16767 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25cc9960b2aaf00ba6f84c8dcd328698a3e502f0e30af909d2563c08a4caedd2/PowerShell/PowerShell/issues/16767 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jhoneill |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9985ca2e21b59673104d4d830d4afeb946c67f248f273ab2e824c31c8db46e4a |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0db9e8d463c3f4540570e6ad3c501a06db9dc02a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width