Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
6 / 6 |
DateFormatter | |
100.00% |
1 / 1 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
6 / 6 |
toUTCDatetime | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
toArray | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
toJson | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
carbonDate | |
100.00% |
1 / 1 |
2 | |
100.00% |
3 / 3 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\MongoJsExecutor\Helpers; |
4 | |
5 | use Carbon\Carbon; |
6 | |
7 | abstract class DateFormatter |
8 | { |
9 | |
10 | /** |
11 | * |
12 | */ |
13 | const DATE_PLACEHOLDER = '@DATE'; |
14 | /** |
15 | * Undocumented function |
16 | * |
17 | * @param string $method |
18 | * @return \MongoDB\BSON\UTCDateTime |
19 | */ |
20 | public static function toUTCDatetime(Carbon $carbon = null) |
21 | { |
22 | return new \MongoDB\BSON\UTCDateTime($carbon ?? self::carbonDate()); |
23 | } |
24 | /** |
25 | * Return UTCDatetime to Array |
26 | * |
27 | * @return array |
28 | */ |
29 | public static function toArray(Carbon $carbon = null) |
30 | { |
31 | return self::toUTCDatetime($carbon)->jsonSerialize(); |
32 | } |
33 | |
34 | /** |
35 | * Return UTCDatetime to json |
36 | * |
37 | * @return string |
38 | */ |
39 | public static function toJson(Carbon $carbon = null) |
40 | { |
41 | return json_encode(self::toArray($carbon)); |
42 | } |
43 | |
44 | /** |
45 | * Undocumented function |
46 | * |
47 | * @param [type] $type |
48 | * @return Carbon |
49 | */ |
50 | public static function carbonDate($type = null) |
51 | { |
52 | if(in_array($type, ['now', 'yesterday', 'tomorrow'])) { |
53 | return Carbon::$type(); |
54 | } |
55 | return Carbon::now(); |
56 | } |
57 | } |