Test: fix ZIP entry LastWriteTime tests to support running locally (when system clock is not UTC) #5949
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#11312
Description
This change fixes some tests that only pass when the system clock is UTC (like on a CI build machine).
The way the
DateTimeOffset ZipArchiveEntry.LastWriteTime
property works is for anyDateTimeOffset
value you set it to,ZipArchiveEntry
will use only theDateTime
property of thatDateTimeOffset
.DateTimeOffset.DateTime
effectively returns theDateTime
component of aDateTimeOffset
, after first discarding its time zone information. To illustrate, theDateTime
property of these differentDateTimeOffset
values all return the sameDateTime
value of8/3/2024 11:50:51 AM
with an "unspecified" time zone.That means any test that checks that NuGet sets a file's
LastWriteTime
value correctly must useDateTimeOffset.DateTime
to check the file's last write time in UTC, orDateTimeOffset.DateTime.ToLocalTime()
to check the file's last write time in local.As part of this change, I changed the
entryModifiedTime
type fromDateTime
toDateTimeOffset
to match theZipArchiveEntry.LastWriteTime
data type.I also opportunistically fixed some code style issues in the area.
PR Checklist
Added testsN/ALink to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.N/ACC @aortiz-msft