dragan Posted April 21, 2019 Share Posted April 21, 2019 I tried out the new $datetime->elapsedTimeStr() method, and found something strange... // https://processwire.com/blog/posts/pw-3.0.130/#new-datetime-gt-elapsedtimestr-method // https://processwire.com/api/ref/wire-date-time/elapsed-time-str/ $p = $pages->get(11297); $p->of(false); $start = $p->proj_timespan_from; $end = $p->proj_timespan_to; //echo "$start / $end <br>"; // unixtime $duration = $datetime->elapsedTimeStr($start, $end, true, $options = array("exclude" => ['seconds', 'minutes', 'hours', 'days'])); echo $duration; // shows: 161 weeks. Months and years are not shown :-( $duration shows: 161 weeks. Months and years are not shown / calculated. Is that by design? I would expect that if the $duration is over a year, it would show x years, y months, z weeks, with my excluded options... 1 Link to comment Share on other sites More sharing options...
isellsoap Posted June 18, 2020 Share Posted June 18, 2020 I created a feature request for this: https://github.com/processwire/processwire-requests/issues/367 Link to comment Share on other sites More sharing options...
Robin S Posted June 18, 2020 Share Posted June 18, 2020 On 4/22/2019 at 12:03 AM, dragan said: Is that by design? I think the reason might be that a week, day, hour and minute is a fixed number of seconds whereas a month or a year is a variable number of seconds. So from a given number of seconds you can't accurate calculate if a month or year has passed without knowing which month (e.g. February or March) in which year (leap year or common year). Having said that, the elapsedTimeStr() method does get supplied all the information it would need to accurately calculate elapsed months and years, it just doesn't currently take account of the actual calendar dates and simply uses the difference in seconds. For now you could use Carbon to get an accurate relative time string including months and years. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now