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

DateOnly from DateTime.MinValue returns "2 months ago" #1189

Closed
21r8390 opened this issue Mar 23, 2022 · 3 comments · Fixed by #1228
Closed

DateOnly from DateTime.MinValue returns "2 months ago" #1189

21r8390 opened this issue Mar 23, 2022 · 3 comments · Fixed by #1228

Comments

@21r8390
Copy link

21r8390 commented Mar 23, 2022

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"
@21r8390
Copy link
Author

21r8390 commented Mar 23, 2022

The workaround for this is to add:

.ToDateTime(TimeOnly.MinValue).Humanize()

@hangy
Copy link
Contributor

hangy commented Mar 23, 2022

var diffDays = Math.Abs(comparisonBase.DayOfYear - input.DayOfYear);
var ts = new TimeSpan(diffDays, 0, 0, 0);
var sameMonth = comparisonBase.AddMonths(tense == Tense.Future ? 1 : -1) == input;
var days = Math.Abs(input.DayOfYear - comparisonBase.DayOfYear);

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

hangy commented Mar 23, 2022

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

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 a pull request may close this issue.

2 participants