Skip to content

Commit

Permalink
Improved humanDurationFromInterval()
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jun 6, 2018
1 parent 96c420d commit b0e6963
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Release Notes for Craft CMS 3.x

## Unreleased

### Changed
- Improved the output of `craft\helpers\DateTimeHelper::humanDurationFromInterval()`.

## 3.0.10.1 - 2018-06-06

### Fixed
Expand Down
13 changes: 12 additions & 1 deletion src/helpers/DateTimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,18 @@ public static function humanDurationFromInterval(DateInterval $dateInterval, boo
$timeComponents[] = $dateInterval->s == 1 ? Craft::t('app', '1 second') : Craft::t('app', '{num} seconds', ['num' => $dateInterval->s]);
}

return implode(', ', $timeComponents);
$last = array_pop($timeComponents);
if (!empty($timeComponents)) {
$string = implode(', ', $timeComponents);
if (count($timeComponents) > 1) {
$string .= ',';
}
$string .= ' '.Craft::t('app', 'and').' ';
} else {
$string = '';
}
$string .= $last;
return $string;
}

// Private Methods
Expand Down

0 comments on commit b0e6963

Please sign in to comment.