-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from lukeyouell/develop
Develop
- Loading branch information
Showing
5 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
/** | ||
* Read Time plugin for Craft CMS 3.x | ||
* | ||
* Calculate the estimated read time for content. | ||
* | ||
* @link https://github.com/lukeyouell | ||
* @copyright Copyright (c) 2018 Luke Youell | ||
*/ | ||
|
||
namespace lukeyouell\readtime\models; | ||
|
||
use lukeyouell\readtime\ReadTime; | ||
|
||
use Craft; | ||
use craft\base\Model; | ||
use craft\helpers\DateTimeHelper; | ||
|
||
class TimeModel extends Model | ||
{ | ||
// Public Properties | ||
// ========================================================================= | ||
|
||
public $seconds = 0; | ||
|
||
public $showSeconds = true; | ||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function __toString() | ||
{ | ||
return (string) $this->human(); | ||
} | ||
|
||
public function human() | ||
{ | ||
return DateTimeHelper::secondsToHumanTimeDuration($this->seconds, $this->showSeconds); | ||
} | ||
|
||
public function interval($format = '%h hours, %i minutes, %s seconds') | ||
{ | ||
$currentTimeStamp = DateTimeHelper::currentTimeStamp(); | ||
$datetimeStart = DateTimeHelper::toDateTime($currentTimeStamp); | ||
$datetimeEnd = DateTimeHelper::toDateTime(DateTimeHelper::currentTimeStamp() + $this->seconds); | ||
|
||
$interval = $datetimeStart->diff($datetimeEnd); | ||
|
||
return $interval->format($format); | ||
} | ||
|
||
public function seconds() | ||
{ | ||
return $this->seconds; | ||
} | ||
|
||
public function minutes() | ||
{ | ||
return floor($this->seconds / 60); | ||
} | ||
|
||
public function hours() | ||
{ | ||
return floor(($this->seconds / 60) / 60); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters