Is your feature request related to a problem? Please describe.
String date conversion fails a lot, and there are no error messages, just null outputs.
Describe the solution you'd like
I forked the code and found the issue in Convert-APIDateTime. I added handling for a 2nd string format in the function, as well as an else condition for unsupported strings (via RegEx matching).
Also, I added a method to the date object to ensure it retains its universal "Kind" time property. Otherwise it was being left ambiguous.
Also added tests for these changes, to the existing test file.
I was getting a massive amount of errors like this in my logs:
Exception calling "ParseExact" with "3" argument(s): "String was not recognized as a valid DateTime."
At C:\Program Files\WindowsPowerShell\Modules\Rubrik\6.0.1\Private\Convert-APIDateTime.ps1:45 char:13
+ [DateTime]::ParseExact($NewDateTimeString,'MM dd HH:mm:ss ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FormatException
I added better error handling so I could get a sample of the invalid string in the message.
Convert-APIDateTime : -07-16T10:02:33.896Z: Exception calling "ParseExact" with "3" argument(s):
"String was not recognized as a valid DateTime."
At C:\Program Files\WindowsPowerShell\Modules\Rubrik\6.0.1\Public\Get-RubrikEvent.ps1:231 char:25
+ expression = {Convert-APIDateTime -DateTimeString $_.time}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Convert-APIDateTime
This date string is not in the format of the one the function was expecting. This is a standard datetime format that Get-Date will recognize as UTC, but the first 4 chars were truncated by the function.
I added a conditional to support it, and errors for any future unsupported cases.
Is your feature request related to a problem? Please describe.
String date conversion fails a lot, and there are no error messages, just null outputs.
Describe the solution you'd like
I forked the code and found the issue in
Convert-APIDateTime
. I added handling for a 2nd string format in the function, as well as an else condition for unsupported strings (via RegEx matching).Also, I added a method to the date object to ensure it retains its universal "Kind" time property. Otherwise it was being left ambiguous.
Also added tests for these changes, to the existing test file.
Describe alternatives you've considered
I can PR this branch I made. here
Additional context
I was getting a massive amount of errors like this in my logs:
I added better error handling so I could get a sample of the invalid string in the message.
This date string is not in the format of the one the function was expecting. This is a standard datetime format that Get-Date will recognize as UTC, but the first 4 chars were truncated by the function.
I added a conditional to support it, and errors for any future unsupported cases.