Skip to content

Invalid DateTime values due to daylight savings time #129

@vavranic

Description

@vavranic

Issue:

ObjectFiller occasionally creates a DateTime value that fails the System.TimeZoneInfo.IsInvalidTime test, https://docs.microsoft.com/en-us/dotnet/api/system.timezoneinfo.isinvalidtime?view=net-5.0. For example, it has randomly created values 4/2/1989 2:29:23 AM and 4/5/1970 2:57:46 AM in my local time zone Central Time (US & Canada). Those times are invalid due to daylight savings time, where the clock jumps forward from 2AM to 3AM on those specific days. This at least occurs in ObjectFiller version 1.5.0.

Please consider changing it to always pick a valid time. Perhaps it just needs to create random DateTime values in a loop until IsInvalidTime returns false.

Background:

I use your handy ObjectFiller for unit testing serialization of many classes. We use ObjectFiller to generically fill a new object, serialize the object, deserialize to create a new object, and then use the Kellerman Compare-NET-Objects package to generically compare the two objects. This works great and saves me from writing a lot of unit testing code. However, my tests randomly fail once or twice a month due to these bad DateTime values. The test reports that the DateTime values differ for the two objects, such as 4/2/1989 2:29:23 AM versus 4/2/1989 3:29:23 AM. We use DateTime.ToBinary and DateTime.FromBinary to serialize and deserialize DateTime objects. Per the Local Time Adjustment section of the DateTime.ToBinary documentation, https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tobinary?view=net-5.0, this can happen if the original DateTime value is invalid due to daylight savings time adjustments.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions