Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: fix ZIP entry LastWriteTime tests to support running locally (when system clock is not UTC) #5949

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

dtivel
Copy link
Contributor

@dtivel dtivel commented Aug 3, 2024

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 any DateTimeOffset value you set it to, ZipArchiveEntry will use only the DateTime property of that DateTimeOffset. DateTimeOffset.DateTime effectively returns the DateTime component of a DateTimeOffset, after first discarding its time zone information. To illustrate, the DateTime property of these different DateTimeOffset values all return the same DateTime value of 8/3/2024 11:50:51 AM with an "unspecified" time zone.

8/3/2024 11:50:51 AM -07:00
8/3/2024 11:50:51 AM +00:00
8/3/2024 11:50:51 AM +05:30

That means any test that checks that NuGet sets a file's LastWriteTime value correctly must use DateTimeOffset.DateTime to check the file's last write time in UTC, or DateTimeOffset.DateTime.ToLocalTime() to check the file's last write time in local.

As part of this change, I changed the entryModifiedTime type from DateTime to DateTimeOffset to match the ZipArchiveEntry.LastWriteTime data type.

I also opportunistically fixed some code style issues in the area.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests N/A
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc. N/A

CC @aortiz-msft

@dtivel dtivel requested a review from a team as a code owner August 3, 2024 19:02
Copy link
Contributor

@jeffkl jeffkl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this, I saw fail a few months ago and never got around to doing it.

@dtivel dtivel merged commit a06319d into dev Aug 6, 2024
30 checks passed
@dtivel dtivel deleted the dev-dtivel-fix-tests branch August 6, 2024 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants