Skip to content

fix: set last access time with unspecified date time kind - #879

Closed
xtopaz wants to merge 5 commits into
TestableIO:mainfrom
xtopaz:bugfix/setLastWriteTimeWithUnspecifiedDateTimeKind
Closed

fix: set last access time with unspecified date time kind#879
xtopaz wants to merge 5 commits into
TestableIO:mainfrom
xtopaz:bugfix/setLastWriteTimeWithUnspecifiedDateTimeKind

Conversation

@xtopaz

Copy link
Copy Markdown
Contributor

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

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.
@xtopazxtopaz changed the title Bugfix/set last write time with unspecified date time kindfix: set last write time with unspecified date time kindAug 25, 2022
@xtopazxtopaz changed the title fix: set last write time with unspecified date time kindfix: set last access time with unspecified date time kindAug 27, 2022

@fgreinacherfgreinacher left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@xtopazxtopazSep 13, 2022

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

Obsolete by #875.

@xtopazxtopaz closed this Sep 16, 2022
Sign up for freeto 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

@xtopaz@fgreinacher@vbtig