Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
DateTime | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
parseStr | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
parseInt | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2023 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen; |
10 | |
11 | use Selen\DateTime\Record; |
12 | |
13 | /** |
14 | * 日付に関する処理を提供するクラス |
15 | */ |
16 | class DateTime |
17 | { |
18 | public Record $record; |
19 | public function __construct(Record $dateTimeRecord) |
20 | { |
21 | $this->record = $dateTimeRecord; |
22 | } |
23 | |
24 | /** |
25 | * 日付文字列からインスタンスを生成します |
26 | * |
27 | * @param string $parseFormat パース文字列 |
28 | * @param string $dateTime 日付文字列 |
29 | * |
30 | * @return DateTime 成功した場合はインスタンスを返します |
31 | */ |
32 | public static function parseStr(string $parseFormat, string $dateTime): DateTime |
33 | { |
34 | return new DateTime(Record::parseStr($parseFormat, $dateTime)); |
35 | } |
36 | |
37 | /** |
38 | * タイムスタンプからインスタンスを生成します |
39 | * |
40 | * @param int $timestamp タイムスタンプ |
41 | * |
42 | * @return DateTime 成功した場合はインスタンスを返します |
43 | */ |
44 | public static function parseInt(int $timestamp): DateTime |
45 | { |
46 | $format = 'Y-m-d H:i:s'; |
47 | $dateTime = \date($format, $timestamp); |
48 | return new DateTime(Record::parseStr($format, $dateTime)); |
49 | } |
50 | } |