I display a diffForHumans with one part
echo Carbon::create('1 hour 59 minutes ago')->diffForHumans(); // 1 hour ago
echo Carbon::create('1 day 23 hours ago')->diffForHumans(); // 1 day ago
echo Carbon::create('1 month 23 days ago')->diffForHumans(); // 1 month ago
echo Carbon::create('1 year 10 months ago')->diffForHumans(); // 1 year ago
For up to 25 months, I’d prefer to see months before it switches to year: e.g. to see 23 months instead of 1 year.
More generaly, I would like to keep the lower unit (like month) when the higher unit (like year) is 1 or 2.
I would also like the display to be as compact as possible.
How do I do that?
2
Answers
Test:
The test output is:
This is an update to skip weeks
Test output (same input data):