Title: [type]$x and $x -as [type] aren't identical · Issue #16593 · PowerShell/PowerShell · GitHub
Open Graph Title: [type]$x and $x -as [type] aren't identical · Issue #16593 · PowerShell/PowerShell
X Title: [type]$x and $x -as [type] aren't identical · Issue #16593 · 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/16593
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[type]$x and $x -as [type] aren't identical","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\nThere are lots of different issues around date formats, and it's well understood that \r\n\r\n1. Some date format needs to be picked as the \"invariant\" one . Because much of IT is US-based, US format is used for this\r\n2. Local customs for how dates are written vary.\r\n3. As a result one needs to understand whether translation happens between text and date objects (and vice versa) is done using local or invariant format . \r\n\r\nSome oddness may be down to .NET but the following seem to be PowerShell quirks which make it harder to understand which way the translation occurs. To see this you need to ensure you're not on US format \r\n```\r\n> Get-Culture \r\n\r\nLCID Name DisplayName\r\n---- ---- -----------\r\n2057 en-GB English (United Kingdom)\r\n\r\n> [datetime]::now -as [String] \r\n10/12/2021 15:18:51\r\n\r\n> [string][datetime]::now \r\n12/10/2021 15:18:17\r\n```\r\n\r\n`-as type` converts using invariant. \r\n`[type]` converts as local. \r\n\r\nIt works the other way \r\n```\r\n> ([string][datetime]::now) -as [datetime]\r\n\r\n12 October 2021 15:21:14 \r\n\r\n>[datetime]([string][datetime]::now) \r\n10 December 2021 15:33:40\r\n\r\n> $x = [datetime]::now\r\n> \"It's \" + $x \r\nIt's 12/10/2021 15:36:50\r\n\r\n> \"It's \" + $x.ToString() \r\nIt's 10/12/2021 15:36:50\r\n```\r\n\r\nYes, I know that **there are loads of things depending on the current behaviour so making things consistent would be a massive breaking change**. But I'd love someone who knows to explain how we ended up in this mess.\r\n\n\n### Expected behavior\n\n```console\n$x -as [string] -eq [string]$x\r\ntrue\n```\n\n\n### Actual behavior\n\n```console\n$x -as [string] -eq [string]$x\r\n\r\nReturns false when $x is a date time object and the culture is not US.\n```\n\n\n### Error details\n\n_No response_\n\n### Environment data\n\n```powershell\nName Value\r\n---- -----\r\nPSVersion 7.2.0\r\nPSEdition Core\r\nGitCommitId 7.2.0\r\nOS Microsoft Windows 10.0.19042\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\r\nIt's the same on PowerShell 5.1\n```\n\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/jhoneill","@type":"Person","name":"jhoneill"},"datePublished":"2021-12-10T16:26:03Z","url":"https://github.com/PowerShell/PowerShell/issues/16593"}
| 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:37473108-ebbf-48ae-6204-0544f4b2959c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9144:2E24C3:2D080D4:3EEA83D:6AFD6880 |
| html-safe-nonce | 417f52be1f28cd872b6ae6e9fd7b3f1f778029bda59cd1b3586f6c45a967a5a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MTQ0OjJFMjRDMzoyRDA4MEQ0OjNFRUE4M0Q6NkFGRDY4ODAiLCJ2aXNpdG9yX2lkIjoiNjA2MzM2NDI1NTkzODA3ODg0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7b524a839eccea2c60c9367365311de1a9de43ef832a4bdec68ed678205ca8dd |
| hovercard-subject-tag | issue:1077019364 |
| 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/16593/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3981dab8eaa30a805a27af327bd850fbd3d4a426974d996951569e09dc5864cc/PowerShell/PowerShell/issues/16593 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3981dab8eaa30a805a27af327bd850fbd3d4a426974d996951569e09dc5864cc/PowerShell/PowerShell/issues/16593 |
| 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