1 | <?php |
||
2 | |||
3 | namespace Helix\DB\Fluent; |
||
4 | |||
5 | use Helix\DB; |
||
6 | use Helix\DB\Fluent\DateTime\DateTimeTrait; |
||
7 | use Helix\DB\Fluent\Str\StrCastTrait; |
||
8 | |||
9 | /** |
||
10 | * A date-time expression. |
||
11 | */ |
||
12 | class DateTime extends Expression implements ValueInterface |
||
13 | { |
||
14 | |||
15 | use DateTimeTrait; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
16 | use FactoryFormatTrait; |
||
17 | use StrCastTrait; |
||
18 | |||
19 | /** |
||
20 | * An expression for the current date and time. |
||
21 | * |
||
22 | * @param DB $db |
||
23 | * @return static |
||
24 | */ |
||
25 | public static function now(DB $db) |
||
26 | { |
||
27 | return static::fromFormat($db, [ |
||
28 | 'mysql' => "NOW()", |
||
29 | 'sqlite' => "DATETIME()" |
||
30 | ]); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * An expression for the current date. |
||
35 | * |
||
36 | * @param DB $db |
||
37 | * @return static |
||
38 | */ |
||
39 | public static function today(DB $db) |
||
40 | { |
||
41 | return static::fromFormat($db, [ |
||
42 | 'mysql' => "CURDATE()", |
||
43 | 'sqlite' => "DATE()" |
||
44 | ]); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * An expression for tomorrow's date. |
||
49 | * |
||
50 | * @param DB $db |
||
51 | * @return static |
||
52 | */ |
||
53 | public static function tomorrow(DB $db) |
||
54 | { |
||
55 | return static::today($db)->addDay(); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * An expression for yesterday's date. |
||
60 | * |
||
61 | * @param DB $db |
||
62 | * @return static |
||
63 | */ |
||
64 | public static function yesterday(DB $db) |
||
65 | { |
||
66 | return static::today($db)->subDay(); |
||
67 | } |
||
68 | } |
||
69 |