Closed gahujipo closed 4 years ago
This variable is only used for manual testing and is designed so that you can pass a manual date into the script to simulate time-lapse. This variable is not used in the standard script run.
I confirm that. But the code before this fix didn't work on systems that have dots as a date separator. This leads to the fact that this lines
https://github.com/leeej84/PowerScale/blob/4259b937cc7a4ae76f5b6fce7fd026796482d030/Decision%20Making.ps1#L111-L115
fails because these rely on $inputDate
to be in the format dd/MM/yyyy HH:mm
This change in this PR makes sure that the date string written to $inputDate
is in the same format on every system and especially with slashes as date separator, as it is expected by the code mentioned above.
I understand what you've written but you've added get-date to a parameter.
There are two sections, one
if ($inputTime) { $inputDate = $([datetime]::ParseExact("$inputTime", "dd/MM/yyyy HH:mm", $null)).ToShortDateString()
$timesObj = [PSCustomObject]@{
startTime = [datetime]::ParseExact($("$($inputDate) $($businessStartTime)"), "dd/MM/yyyy HH:mm", $null)
endTime = [datetime]::ParseExact($("$($inputDate) $($businessCloseTime)"), "dd/MM/yyyy HH:mm", $null)
additionalScaleStartTime = [datetime]::ParseExact($("$($inputDate) $($additionalScaleStartTime)"), "dd/MM/yyyy HH:mm", $null)
additionalScaleEndTime = [datetime]::ParseExact($("$($inputDate) $($additionalScaleEndTime)"), "dd/MM/yyyy HH:mm", $null)
backupTime = [datetime]::ParseExact($("$($inputDate) $($dashboardBackupTime)"), "dd/MM/yyyy HH:mm", $null)
timeNow = $([datetime]::ParseExact("$inputTime", "dd/MM/yyyy HH:mm", $null))
}
} else { $timesObj = [PSCustomObject]@{ startTime = [datetime]::ParseExact($("$($dateNow) $($businessStartTime)"), "dd/MM/yy HH:mm", $null) endTime = [datetime]::ParseExact($("$($dateNow) $($businessCloseTime)"), "dd/MM/yy HH:mm", $null) additionalScaleStartTime = [datetime]::ParseExact($("$($dateNow) $($additionalScaleStartTime)"), "dd/MM/yy HH:mm", $null) additionalScaleEndTime = [datetime]::ParseExact($("$($dateNow) $($additionalScaleEndTime)"), "dd/MM/yy HH:mm", $null) backupTime = [datetime]::ParseExact($("$($dateNow) $($dashboardBackupTime)"), "dd/MM/yy HH:mm", $null) timeNow = $(Get-Date) } }
I understand but you have added get-date so I cannot merge your request.
$inputDate = get-date ([datetime]::ParseExact($inputTime, "dd/MM/yyyy HH:mm", $null)) -UFormat "%d/%m/%Y"
I'm happy with your UFormat piece but not the get-date before.
Why are you concerned about that? This code does not return a DateTime object if that is what you're worried about. You can see the datatype of String with:
$inputTime = "23/04/2020 22:00"
$a = get-date ([datetime]::ParseExact($inputTime, "dd/MM/yyyy HH:mm", $null)) -UFormat "%d/%m/%Y"
$a.GetType()
This Outputs
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Get-Date was added because -UFormat is a parameter of it.
I understand what you've done. Using Get-Date to pass the correct formatted date time and then output it in my format. No worries. Would you like a copy of the testing script to automate the runs, just send me a mail. I don't publish it as part of the code.
don't rely on the computers culture, but explicitly format the date to the later expected format. This is fixes the issue on a PC that uses dots as separator in date strings.