HasDateFunctions::dateMonth()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
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 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\AQL;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
8
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;
9
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
10
11
/**
12
 * Trait hasNumericFunctions.
13
 *
14
 * Date AQL functions.
15
 *
16
 * @see https://www.arangodb.com/docs/stable/aql/functions-date.html
17
 */
18
trait HasDateFunctions
19
{
20
    /**
21
     * Check if two partial dates match.
22
     *
23
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_compare
24
     */
25 1
    public function dateCompare(
26
        string|int|object $date1,
27
        string|int|object $date2,
28
        string|object $unitRangeStart,
29
        null|string|object $unitRangeEnd
30
    ): FunctionExpression {
31 1
        $arguments = [
32
            "date1" => $date1,
33
            "date2" => $date2,
34
            "unitRangeStart" => $unitRangeStart,
35
        ];
36 1
        if (isset($unitRangeEnd)) {
37 1
            $arguments['unitRangeEnd'] = $unitRangeEnd;
38
        }
39
40 1
        return new FunctionExpression('DATE_COMPARE', $arguments);
41
    }
42
43
    /**
44
     * Get the day value of a date.
45
     *
46
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_day
47
     */
48 1
    public function dateDay(
49
        string|int|object $date
50
    ): FunctionExpression {
51 1
        return new FunctionExpression('DATE_DAY', $date);
52
    }
53
54
    /**
55
     * Get the custom formatted representation of the date.
56
     *
57
     * @Link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_format
58
     */
59 1
    public function dateFormat(
60
        string|int|object $date,
61
        string|object $format
62
    ): FunctionExpression {
63 1
        return new FunctionExpression('DATE_FORMAT', [$date, $format]);
64
    }
65
66
    /**
67
     * Get the day value of a date.
68
     *
69
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_hour
70
     */
71 1
    public function dateHour(
72
        string|int|object $date
73
    ): FunctionExpression {
74 1
        return new FunctionExpression('DATE_HOUR', $date);
75
    }
76
77
    /**
78
     * Return an ISO 8601 date time string from date
79
     */
80 3
    public function dateIso8601(): FunctionExpression
81
    {
82
        /** @var array<int|string> $arguments */
83 3
        $arguments = func_get_args();
84 3
        if (empty($arguments)) {
85 1
            $arguments[] = time();
86
        }
87
88 3
        return new FunctionExpression('DATE_ISO8601', $arguments);
89
    }
90
91
    /**
92
     * Get the millisecond of the date.
93
     *
94
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_millisecond
95
     */
96 1
    public function dateMillisecond(
97
        string|int|object $date
98
    ): FunctionExpression {
99 1
        return new FunctionExpression('DATE_MILLISECOND', $date);
100
    }
101
102
    /**
103
     * Get the minute value of a date.
104
     *
105
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_minute
106
     */
107 1
    public function dateMinute(
108
        string|int|object $date
109
    ): FunctionExpression {
110 1
        return new FunctionExpression('DATE_MINUTE', $date);
111
    }
112
113
    /**
114
     * Get the month value of a date.
115
     *
116
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_month
117
     */
118 1
    public function dateMonth(
119
        string|int|object $date
120
    ): FunctionExpression {
121 1
        return new FunctionExpression('DATE_MONTH', $date);
122
    }
123
124
    /**
125
     * Get the current unix time as numeric timestamp.
126
     *
127
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_now
128
     */
129 2
    public function dateNow(): FunctionExpression
130
    {
131 2
        return new FunctionExpression('DATE_NOW', []);
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 1
    public function dateSecond(
140
        string|int|object $date
141
    ): FunctionExpression {
142 1
        return new FunctionExpression('DATE_SECOND', $date);
143
    }
144
145
    /**
146
     * Return an Unix timestamp from a date value
147
     *
148
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_iso8601.
149
     */
150 3
    public function dateTimestamp(): FunctionExpression
151
    {
152
        /** @var array<int|string> $arguments */
153 3
        $arguments = func_get_args();
154 3
        if (empty($arguments)) {
155 1
            $arguments[] = time();
156
        }
157
158 3
        return new FunctionExpression('DATE_TIMESTAMP', $arguments);
159
    }
160
161
    /**
162
     * Truncates the given date after unit and returns the modified date.
163
     *
164
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_trunc
165
     */
166 1
    public function dateTrunc(
167
        int|string|object $date,
168
        string|object $unit
169
    ): FunctionExpression {
170 1
        $arguments = [
171
            "date" => $date,
172
            "unit" => $unit
173
        ];
174
175 1
        return new FunctionExpression('DATE_TRUNC', $arguments);
176
    }
177
178
    /**
179
     * Bin a date/time into a set of equal-distance buckets, to be used for grouping.
180
     *
181
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_round
182
     */
183 2
    public function dateRound(
184
        int|string|object $date,
185
        int|object $amount,
186
        string|object $unit
187
    ): FunctionExpression {
188 2
        $arguments = [
189
            "date" => $date,
190
            "amount" => $amount,
191
            "unit" => $unit
192
        ];
193
194 2
        return new FunctionExpression('DATE_ROUND', $arguments);
195
    }
196
197
    /**
198
     * Converts date assumed in Zulu time (UTC) to the given timezone.
199
     *
200
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_utctolocal
201
     *
202
     * @param array<mixed>|object|null $zoneInfo
203
     */
204 2
    public function dateUtcToLocal(
205
        int|string|object $date,
206
        string|object $timezone,
207
        null|array|object $zoneInfo = null
208
    ): FunctionExpression {
209 2
        $arguments = [
210
            "date" => $date,
211
            "timezone" => $timezone
212
        ];
213 2
        if (isset($zoneInfo)) {
214 1
            $arguments['zoneInfo'] = $zoneInfo;
215
        }
216
217 2
        return new FunctionExpression('DATE_UTCTOLOCAL', $arguments);
218
    }
219
220
    /**
221
     * Converts date assumed in the given timezone to Zulu time (UTC).
222
     *
223
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_localtoutc
224
     *
225
     * @param array<mixed>|object|null $zoneInfo
226
     */
227 2
    public function dateLocalToUtc(
228
        int|string|object $date,
229
        string|object $timezone,
230
        null|array|object $zoneInfo = null
231
    ): FunctionExpression {
232 2
        $arguments = [
233
            "date" => $date,
234
            "timezone" => $timezone
235
        ];
236 2
        if (isset($zoneInfo)) {
237 1
            $arguments['zoneInfo'] = $zoneInfo;
238
        }
239
240 2
        return new FunctionExpression('DATE_LOCALTOUTC', $arguments);
241
    }
242
243
244
    /**
245
     * Get the year value of a date.
246
     *
247
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_year
248
     */
249 1
    public function dateYear(
250
        string|int|object $date
251
    ): FunctionExpression {
252 1
        return new FunctionExpression('DATE_YEAR', $date);
253
    }
254
}
255