Skip to content

Conversation

@xtopaz
Copy link
Contributor

@xtopaz xtopaz commented Aug 25, 2022

This fixes a missing ToLocalTime conversion in the MockFileInfo.LastAccessTimeUtc setter, which leads to inconsistent results when dealing with DateTime values having DateTimeKind.Unspecified.

xtopaz added 2 commits August 25, 2022 16:31
This fixes an iconsistent DateTime conversion in the LastAccessTimeUtc
setter by adding explicit conversion to local time.

This fixes a conversion error that occurred when a value was passed with
DateTimeKind.Unspecified.
@xtopaz xtopaz changed the title Bugfix/set last write time with unspecified date time kind fix: set last write time with unspecified date time kind Aug 25, 2022
@xtopaz xtopaz changed the title fix: set last write time with unspecified date time kind fix: set last access time with unspecified date time kind Aug 27, 2022
Copy link
Contributor

@fgreinacher fgreinacher 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 your work @xtopaz!

I left two comments :)

{
var mockFileData = GetMockFileDataForWrite();
mockFileData.LastAccessTime = value;
mockFileData.LastAccessTime = value.ToLocalTime();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also do this for the other *TimeUtc properties?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@xtopaz xtopaz Sep 13, 2022

Choose a reason for hiding this comment

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

@fgreinacher Sorry for the late reply, just got back from vacation.

All other *TimeUtc properties already contain the ToLocalTime call. This way the behavior has been unified.

File.File.GetUtcDateTimeOffsetcannot be used because it is internal. However, this behaves analogously to the proposed implementation, since it takes Utc for DateTimeKind.Unspecified.

To be more precise, the preliminary conversion using ToLocalTime for values with DateTimeKind.Unspecified assumes UTC. The subsequent implicit conversion to DateTimeOffset then takes the time zone into account correctly. Thus the timestamps behave analogously to those in System.FileInfo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fgreinacher I've incorporated the recent changes from #875 and all test look fine.

@xtopaz
Copy link
Contributor Author

xtopaz commented Sep 16, 2022

Obsolete by #875.

@xtopaz xtopaz closed this Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants