Passed
Branch next (ee2197)
by Bas
02:37
created

HasDateFunctions::dateRound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 12
ccs 6
cts 6
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
0 ignored issues
show
Bug introduced by
The type LaravelFreelancerNL\FluentAQL\AQL\null was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
    ): FunctionExpression {
31 1
        $arguments = [
32 1
            "date1" => $date1,
33 1
            "date2" => $date2,
34 1
            "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 3
        $arguments = func_get_args();
83 3
        if (empty($arguments)) {
84 1
            $arguments[] = time();
85
        }
86
87 3
        return new FunctionExpression('DATE_ISO8601', $arguments);
88
    }
89
90
    /**
91
     * Get the millisecond of the date.
92
     *
93
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_millisecond
94
     */
95 1
    public function dateMillisecond(
96
        string|int|object $date
97
    ): FunctionExpression {
98 1
        return new FunctionExpression('DATE_MILLISECOND', $date);
99
    }
100
101
    /**
102
     * Get the minute value of a date.
103
     *
104
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_minute
105
     */
106 1
    public function dateMinute(
107
        string|int|object $date
108
    ): FunctionExpression {
109 1
        return new FunctionExpression('DATE_MINUTE', $date);
110
    }
111
112
    /**
113
     * Get the month value of a date.
114
     *
115
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_month
116
     */
117 1
    public function dateMonth(
118
        string|int|object $date
119
    ): FunctionExpression {
120 1
        return new FunctionExpression('DATE_MONTH', $date);
121
    }
122
123
    /**
124
     * Get the current unix time as numeric timestamp.
125
     *
126
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_now
127
     */
128 2
    public function dateNow(): FunctionExpression
129
    {
130 2
        return new FunctionExpression('DATE_NOW', []);
131
    }
132
133
    /**
134
     * Get the second of the date.
135
     *
136
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_second
137
     */
138 1
    public function dateSecond(
139
        string|int|object $date
140
    ): FunctionExpression {
141 1
        return new FunctionExpression('DATE_SECOND', $date);
142
    }
143
144
    /**
145
     * Return an Unix timestamp from a date value
146
     *
147
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_iso8601.
148
     */
149 3
    public function dateTimestamp(): FunctionExpression
150
    {
151 3
        $arguments = func_get_args();
152 3
        if (empty($arguments)) {
153 1
            $arguments[] = time();
154
        }
155
156 3
        return new FunctionExpression('DATE_TIMESTAMP', $arguments);
157
    }
158
159
    /**
160
     * Truncates the given date after unit and returns the modified date.
161
     *
162
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_trunc
163
     */
164 1
    public function dateTrunc(
165
        int|string|object $date,
166
        string|object $unit
167
    ): FunctionExpression {
168 1
        $arguments = [
169 1
            "date" => $date,
170 1
            "unit" => $unit
171
        ];
172
173 1
        return new FunctionExpression('DATE_TRUNC', $arguments);
174
    }
175
176
    /**
177
     * Bin a date/time into a set of equal-distance buckets, to be used for grouping.
178
     *
179
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_round
180
     */
181 2
    public function dateRound(
182
        int|string|object $date,
183
        int|object $amount,
184
        string|object $unit
185
    ): FunctionExpression {
186 2
        $arguments = [
187 2
            "date" => $date,
188 2
            "amount" => $amount,
189 2
            "unit" => $unit
190
        ];
191
192 2
        return new FunctionExpression('DATE_ROUND', $arguments);
193
    }
194
195
    /**
196
     * Converts date assumed in Zulu time (UTC) to the given timezone.
197
     *
198
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_utctolocal
199
     *
200
     * @param array<mixed>|object|null $zoneInfo
201
     */
202 2
    public function dateUtcToLocal(
203
        int|string|object $date,
204
        string|object $timezone,
205
        null|array|object $zoneInfo = null
206
    ): FunctionExpression {
207 2
        $arguments = [
208 2
            "date" => $date,
209 2
            "timezone" => $timezone
210
        ];
211 2
        if (isset($zoneInfo)) {
212 1
            $arguments['zoneInfo'] = $zoneInfo;
213
        }
214
215 2
        return new FunctionExpression('DATE_UTCTOLOCAL', $arguments);
216
    }
217
218
    /**
219
     * Converts date assumed in the given timezone to Zulu time (UTC).
220
     *
221
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_localtoutc
222
     *
223
     * @param array<mixed>|object|null $zoneInfo
224
     */
225 2
    public function dateLocalToUtc(
226
        int|string|object $date,
227
        string|object $timezone,
228
        null|array|object $zoneInfo = null
229
    ): FunctionExpression {
230 2
        $arguments = [
231 2
            "date" => $date,
232 2
            "timezone" => $timezone
233
        ];
234 2
        if (isset($zoneInfo)) {
235 1
            $arguments['zoneInfo'] = $zoneInfo;
236
        }
237
238 2
        return new FunctionExpression('DATE_LOCALTOUTC', $arguments);
239
    }
240
241
242
    /**
243
     * Get the year value of a date.
244
     *
245
     * @link https://www.arangodb.com/docs/stable/aql/functions-date.html#date_year
246
     */
247 1
    public function dateYear(
248
        string|int|object $date
249
    ): FunctionExpression {
250 1
        return new FunctionExpression('DATE_YEAR', $date);
251
    }
252
}
253