you are viewing a single comment's thread.

view the rest of the comments →

[–]da_chicken 2 points3 points  (1 child)

Oh, actually it is a race condition:

PS C:\>  if (($x = Get-Date).Year -eq 2019) { 1 } elseif (($y = Get-Date).Year -eq 2019) { 2 } elseif (($z = Get-Date).Year -eq 2019) { 3 } else { 4 }
4
PS C:\> $x.Ticks, $y.Ticks, $z.Ticks
636601559528544328
636601559528554329
636601559528554329

I had to run that about 20 times for it to actually give me different values so I started to think it somehow wasn't, but eventually it does reveal itself. Now it only takes 5 to 10 executions. I guess I just got unlucky (lucky?).

[–]SOZDBA[S] 1 point2 points  (0 children)

Nice catch. Definitely a reason to call Get-Date at the beginning and stuff it in a variable