Failed Conditions
Push — master ( e341c2...878df1 )
by Bas
12:12
created

HasDateFunctions::dateMillisecond()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace LaravelFreelancerNL\FluentAQL\AQL;
4
5
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;
6
7
/**
8
 * Trait hasNumericFunctions.
9
 *
10
 * Date AQL functions.
11
 *
12
 * @see https://www.arangodb.com/docs/stable/aql/functions-date.html
13
 */
14
trait HasDateFunctions
15
{
16
    /**
17
     * Get the current unix time as numeric timestamp.
18
     *
19
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_now
20
     *
21
     * @return FunctionExpression
22
     */
23 1
    public function dateNow()
24
    {
25 1
        return new FunctionExpression('DATE_NOW', []);
26
    }
27
28
    /**
29
     * Return an ISO 8601 date time string from date
30
     * You may enter a unix timestamp or a datestring: year, month, day, hour, minute, second, millisecond
31
     * Instead of year you can also enter a unix timestamp in which case month and day may be null.
32
     * https://www.arangodb.com/docs/stable/aql/functions-date.html#date_iso8601.
33
     *
34
     * @return FunctionExpression
35
     */
36 3
    public function dateIso8601()
37
    {
38 3
        $arguments = func_get_args();
39 3
        if (empty($arguments)) {
40 1
            $arguments[] = time();
41
        }
42
43 3
        return new FunctionExpression('DATE_ISO8601', $arguments);
44
    }
45
46
    /**
47
     * Return an Unix timestamp from a date value
48
     * You may enter a or a dateString: year, month, day, hour, minute, second, millisecond
49
     * Instead of year you can also enter a unix timestamp in which case month and day may be null.
50
     * https://www.arangodb.com/docs/stable/aql/functions-date.html#date_iso8601.
51
     *
52
     * @return FunctionExpression
53
     */
54 3
    public function dateTimestamp()
55
    {
56 3
        $arguments = func_get_args();
57 3
        if (empty($arguments)) {
58 1
            $arguments[] = time();
59
        }
60
61 3
        return new FunctionExpression('DATE_TIMESTAMP', $arguments);
62
    }
63
64
    /**
65
     * Get the year value of a date.
66
     *
67
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_year
68
     *
69
     * @param  $date
70
     *
71
     * @return FunctionExpression
72
     */
73 1
    public function dateYear($date)
74
    {
75 1
        return new FunctionExpression('DATE_YEAR', $date);
76
    }
77
78
    /**
79
     * Get the month value of a date.
80
     *
81
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_month
82
     *
83
     * @param  $date
84
     *
85
     * @return FunctionExpression
86
     */
87 1
    public function dateMonth($date)
88
    {
89 1
        return new FunctionExpression('DATE_MONTH', $date);
90
    }
91
92
    /**
93
     * Get the day value of a date.
94
     *
95
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_day
96
     *
97
     * @param  $date
98
     *
99
     * @return FunctionExpression
100
     */
101 1
    public function dateDay($date)
102
    {
103 1
        return new FunctionExpression('DATE_DAY', $date);
104
    }
105
106
    /**
107
     * Get the day value of a date.
108
     *
109
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_hour
110
     *
111
     * @param  $date
112
     *
113
     * @return FunctionExpression
114
     */
115 1
    public function dateHour($date)
116
    {
117 1
        return new FunctionExpression('DATE_HOUR', $date);
118
    }
119
120
    /**
121
     * Get the minute value of a date.
122
     *
123
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_minute
124
     *
125
     * @param  $date
126
     *
127
     * @return FunctionExpression
128
     */
129 1
    public function dateMinute($date)
130
    {
131 1
        return new FunctionExpression('DATE_MINUTE', $date);
132
    }
133
134
    /**
135
     * Get the second of the date.
136
     *
137
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_second
138
     *
139
     * @param  $date
140
     *
141
     * @return FunctionExpression
142
     */
143 1
    public function dateSecond($date)
144
    {
145 1
        return new FunctionExpression('DATE_SECOND', $date);
146
    }
147
148
    /**
149
     * Get the millisecond of the date.
150
     *
151
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_millisecond
152
     *
153
     * @param  $date
154
     *
155
     * @return FunctionExpression
156
     */
157 1
    public function dateMillisecond($date)
158
    {
159 1
        return new FunctionExpression('DATE_MILLISECOND', $date);
160
    }
161
162
    /**
163
     * Get the custom formatted representation of the date.
164
     *
165
     * @Link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_format
166
     *
167
     * @param  $date
168
     * @param  $format
169
     * @return FunctionExpression
170
     */
171 1
    public function dateFormat($date, $format): FunctionExpression
172
    {
173 1
        return new FunctionExpression('DATE_FORMAT', [$date, $format]);
174
    }
175
}
176