-6

When parsing a string of the format HH:MM:SS where HH is greater than 24, this seems to parse the time span incorrectly:

[MultiTenant\Exchange\] PS C:\Users\vijara> [System.TimeSpan]::Parse("24:00:00")


Days              : 24
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 20736000000000
TotalDays         : 24
TotalHours        : 576
TotalMinutes      : 34560
TotalSeconds      : 2073600
TotalMilliseconds : 2073600000

This is the case for any value of HH above 23.

[MultiTenant\Exchange\] PS C:\Users\vijara> [System.TimeSpan]::Parse("45:00:00")


Days              : 45
Hours             : 0
Minutes           : 0
Seconds           : 0
Milliseconds      : 0
Ticks             : 38880000000000
TotalDays         : 45
TotalHours        : 1080
TotalMinutes      : 64800
TotalSeconds      : 3888000
TotalMilliseconds : 3888000000
  • Explanation is right in the documentation: https://learn.microsoft.com/en-us/dotnet/api/system.timespan.parse?view=netframework-4.8 – Chris White Apr 29 '19 at 21:43
  • What's your question? It's doing what it was specified to do. – Jeff Apr 29 '19 at 21:44
  • Consider using `ParseExact` and specifying the format string. – Ben Voigt Apr 29 '19 at 21:46
  • I believe you would want `[System.TimeSpan]::Parse("1.0:00:00")` to get a 24-hour timespan, and `[System.TimeSpan]::Parse("1.21:00:00")` for 45 hours, in the powershell format. – Jonathon Chase Apr 29 '19 at 21:47
  • Thanks, I was wondering why this doesn't result in an overflow. But I guess it's dropping the second and parsing the first literal as days when it's greater than the number of hours in a day – Vijay Kumar Apr 30 '19 at 06:24

1 Answers1

0

Because a day cannot have more than 24 hours. Once the parsing method see the number larger than 24, it assumes you want days.

Same with different values for demo purpose

Black Frog
  • 11,595
  • 1
  • 35
  • 66