Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 4 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Tus_Date_Utils | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| date_utc | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| add_seconds | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Tus_Date Utils. |
| 4 | * |
| 5 | * @package VideoPressUploader |
| 6 | **/ |
| 7 | |
| 8 | namespace VideoPressUploader; |
| 9 | |
| 10 | // Avoid direct calls to this file. |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | die( 0 ); |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Class Tus_Date_Utils |
| 17 | */ |
| 18 | class Tus_Date_Utils { |
| 19 | /** |
| 20 | * Returns a UTC date. |
| 21 | * |
| 22 | * @param null|int|string $s Thing to turn to date utc. |
| 23 | * |
| 24 | * @return \DateTimeImmutable |
| 25 | * @throws \Exception If the thing provided does not make sense. |
| 26 | */ |
| 27 | public static function date_utc( $s = null ) { |
| 28 | return new \DateTimeImmutable( $s, new \DateTimeZone( 'UTC' ) ); |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Adds seconds to a date. |
| 33 | * |
| 34 | * @param \DateTimeImmutable $date The date. |
| 35 | * @param int $seconds The seconds. |
| 36 | * |
| 37 | * @return \DateTimeImmutable |
| 38 | * @throws \Exception If invalid interval. |
| 39 | */ |
| 40 | public static function add_seconds( \DateTimeImmutable $date, $seconds ) { |
| 41 | return $date->add( new \DateInterval( 'PT' . absint( $seconds ) . 'S' ) ); |
| 42 | } |
| 43 | } |