Humanizer icon indicating copy to clipboard operation
Humanizer copied to clipboard

`DateOnly` from DateTime.MinValue returns "2 months ago"

Open flimtix opened this issue 2 years ago • 3 comments

When I use DateOnly and want to put this into a readable form with Humanizer, I get the error that "2 months ago" comes out for DateTime.MinValue. If I use DateTime, then I get the expected result of "2022 years ago".

Examples:

DateOnly.FromDateTime(DateTime.MinValue).Humanize(); // returns "2 months ago"
DateTime.MinValue.Humanize(); // returns "2022 years ago"

flimtix avatar Mar 23 '22 12:03 flimtix

The workaround for this is to add:

.ToDateTime(TimeOnly.MinValue).Humanize()

flimtix avatar Mar 23 '22 14:03 flimtix

https://github.com/Humanizr/Humanizer/blob/937e827b8d664ce800b31160e51e8b2eca95fadc/src/Humanizer/DateTimeHumanizeStrategy/DateTimeHumanizeAlgorithms.cs#L158-L163

Does this need to use DayNumber instead of DayOfYear? I have a feeling that the current code doesn't work well with >1 year differences.

hangy avatar Mar 23 '22 17:03 hangy

Probably related to #1186 or solved by it, if it gets a new implementation.

hangy avatar Mar 23 '22 18:03 hangy