xref: /PHP-8.0/ext/date/php_date.stub.php (revision c31f9f7e)
1<?php
2
3/** @generate-function-entries */
4
5function strtotime(string $datetime, ?int $baseTimestamp = null): int|false {}
6
7function date(string $format, ?int $timestamp = null): string {}
8
9function idate(string $format, ?int $timestamp = null): int|false {}
10
11function gmdate(string $format, ?int $timestamp = null): string {}
12
13function mktime(
14    int $hour, ?int $minute = null, ?int $second = null,
15    ?int $month = null, ?int $day = null, ?int $year = null): int|false {}
16
17function gmmktime(
18    int $hour, ?int $minute = null, ?int $second = null,
19    ?int $month = null, ?int $day = null, ?int $year = null): int|false {}
20
21function checkdate(int $month, int $day, int $year): bool {}
22
23function strftime(string $format, ?int $timestamp = null): string|false {}
24
25function gmstrftime(string $format, ?int $timestamp = null): string|false {}
26
27function time(): int {}
28
29function localtime(?int $timestamp = null, bool $associative = false): array {}
30
31function getdate(?int $timestamp = null): array {}
32
33function date_create(string $datetime = "now", ?DateTimeZone $timezone = null): DateTime|false {}
34
35function date_create_immutable(
36    string $datetime = "now", ?DateTimeZone $timezone = null): DateTimeImmutable|false {}
37
38function date_create_from_format(
39    string $format, string $datetime, ?DateTimeZone $timezone = null): DateTime|false {}
40
41function date_create_immutable_from_format(
42    string $format, string $datetime, ?DateTimeZone $timezone = null): DateTimeImmutable|false {}
43
44function date_parse(string $datetime): array {}
45
46function date_parse_from_format(string $format, string $datetime): array {}
47
48function date_get_last_errors(): array|false {}
49
50function date_format(DateTimeInterface $object, string $format): string {}
51
52function date_modify(DateTime $object, string $modifier): DateTime|false {}
53
54function date_add(DateTime $object, DateInterval $interval): DateTime {}
55
56function date_sub(DateTime $object, DateInterval $interval): DateTime {}
57
58function date_timezone_get(DateTimeInterface $object): DateTimeZone|false {}
59
60function date_timezone_set(DateTime $object, DateTimeZone $timezone): DateTime {}
61
62function date_offset_get(DateTimeInterface $object): int {}
63
64function date_diff(
65    DateTimeInterface $baseObject, DateTimeInterface $targetObject, bool $absolute = false): DateInterval {}
66
67function date_time_set(
68    DateTime $object, int $hour, int $minute, int $second = 0, int $microsecond = 0): DateTime {}
69
70function date_date_set(DateTime $object, int $year, int $month, int $day): DateTime {}
71
72function date_isodate_set(DateTime $object, int $year, int $week, int $dayOfWeek = 1): DateTime {}
73
74function date_timestamp_set(DateTime $object, int $timestamp): DateTime {}
75
76function date_timestamp_get(DateTimeInterface $object): int {}
77
78function timezone_open(string $timezone): DateTimeZone|false {}
79
80function timezone_name_get(DateTimeZone $object): string {}
81
82function timezone_name_from_abbr(string $abbr, int $utcOffset = -1, int $isDST = -1): string|false {}
83
84function timezone_offset_get(DateTimeZone $object, DateTimeInterface $datetime): int {}
85
86function timezone_transitions_get(
87    DateTimeZone $object, int $timestampBegin = PHP_INT_MIN, int $timestampEnd = PHP_INT_MAX): array|false {}
88
89function timezone_location_get(DateTimeZone $object): array|false {}
90
91function timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): array {}
92
93function timezone_abbreviations_list(): array {}
94
95function timezone_version_get(): string {}
96
97function date_interval_create_from_date_string(string $datetime): DateInterval|false {}
98
99function date_interval_format(DateInterval $object, string $format): string {}
100
101function date_default_timezone_set(string $timezoneId): bool {}
102
103function date_default_timezone_get(): string {}
104
105function date_sunrise(
106    int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING,
107    ?float $latitude = null, ?float $longitude = null, ?float $zenith = null,
108    ?float $utcOffset = null): string|int|float|false {}
109
110function date_sunset(
111    int $timestamp, int $returnFormat = SUNFUNCS_RET_STRING,
112    ?float $latitude = null, ?float $longitude = null, ?float $zenith = null,
113    ?float $utcOffset = null): string|int|float|false {}
114
115function date_sun_info(int $timestamp, float $latitude, float $longitude): array {}
116
117// NB: Adding return types to methods is a BC break!
118// For now only using @return annotations here.
119
120interface DateTimeInterface
121{
122    /** @return string */
123    public function format(string $format);
124
125    /** @return DateTimeZone|false */
126    public function getTimezone();
127
128    /** @return int */
129    public function getOffset();
130
131    /** @return int|false */
132    public function getTimestamp();
133
134    /** @return DateInterval|false */
135    public function diff(DateTimeInterface $targetObject, bool $absolute = false);
136
137    /** @return void */
138    public function __wakeup();
139}
140
141class DateTime implements DateTimeInterface
142{
143    public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null) {}
144
145    /** @return void */
146    public function __wakeup() {}
147
148    /** @return DateTime */
149    public static function __set_state(array $array) {}
150
151    /** @return DateTime */
152    public static function createFromImmutable(DateTimeImmutable $object) {}
153
154    public static function createFromInterface(DateTimeInterface $object): DateTime {}
155
156    /**
157     * @return DateTime|false
158     * @alias date_create_from_format
159     */
160    public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) {}
161
162    /**
163     * @return array|false
164     * @alias date_get_last_errors
165     */
166    public static function getLastErrors() {}
167
168    /**
169     * @return string
170     * @alias date_format
171     */
172    public function format(string $format) {}
173
174    /**
175     * @return DateTime|false
176     * @alias date_modify
177     */
178    public function modify(string $modifier) {}
179
180    /**
181     * @return DateTime
182     * @alias date_add
183     */
184    public function add(DateInterval $interval) {}
185
186    /**
187     * @return DateTime
188     * @alias date_sub
189     */
190    public function sub(DateInterval $interval) {}
191
192    /**
193     * @return DateTimeZone|false
194     * @alias date_timezone_get
195     */
196    public function getTimezone() {}
197
198    /**
199     * @return DateTime
200     * @alias date_timezone_set
201     */
202    public function setTimezone(DateTimeZone $timezone) {}
203
204    /**
205     * @return int
206     * @alias date_offset_get
207     */
208    public function getOffset() {}
209
210    /**
211     * @return DateTime
212     * @alias date_time_set
213     */
214    public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) {}
215
216    /**
217     * @return DateTime
218     * @alias date_date_set
219     */
220    public function setDate(int $year, int $month, int $day) {}
221
222    /**
223     * @return DateTime
224     * @alias date_isodate_set
225     */
226    public function setISODate(int $year, int $week, int $dayOfWeek = 1) {}
227
228    /**
229     * @return DateTime
230     * @alias date_timestamp_set
231     */
232    public function setTimestamp(int $timestamp) {}
233
234    /**
235     * @return int
236     * @alias date_timestamp_get
237     */
238    public function getTimestamp() {}
239
240    /**
241     * @return DateInterval
242     * @alias date_diff
243     */
244    public function diff(DateTimeInterface $targetObject, bool $absolute = false) {}
245}
246
247class DateTimeImmutable implements DateTimeInterface
248{
249    public function __construct(string $datetime = "now", ?DateTimeZone $timezone = null) {}
250
251    /** @return void */
252    public function __wakeup() {}
253
254    /** @return DateTimeImmutable */
255    public static function __set_state(array $array) {}
256
257    /**
258     * @return DateTimeImmutable|false
259     * @alias date_create_immutable_from_format
260     */
261    public static function createFromFormat(string $format, string $datetime, ?DateTimeZone $timezone = null) {}
262
263    /**
264     * @return array|false
265     * @alias date_get_last_errors
266     */
267    public static function getLastErrors() {}
268
269    /**
270     * @return string
271     * @alias date_format
272     */
273    public function format(string $format) {}
274
275    /**
276     * @return DateTimeZone|false
277     * @alias date_timezone_get
278     */
279    public function getTimezone() {}
280
281    /**
282     * @return int
283     * @alias date_offset_get
284     */
285    public function getOffset() {}
286
287    /**
288     * @return int
289     * @alias date_timestamp_get
290     */
291    public function getTimestamp() {}
292
293    /**
294     * @return DateInterval
295     * @alias date_diff
296     */
297    public function diff(DateTimeInterface $targetObject, bool $absolute = false) {}
298
299    /** @return DateTimeImmutable|false */
300    public function modify(string $modifier) {}
301
302    /** @return DateTimeImmutable */
303    public function add(DateInterval $interval) {}
304
305    /** @return DateTimeImmutable */
306    public function sub(DateInterval $interval) {}
307
308    /** @return DateTimeImmutable */
309    public function setTimezone(DateTimeZone $timezone) {}
310
311    /** @return DateTimeImmutable */
312    public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0) {}
313
314    /** @return DateTimeImmutable */
315    public function setDate(int $year, int $month, int $day) {}
316
317    /** @return DateTimeImmutable */
318    public function setISODate(int $year, int $week, int $dayOfWeek = 1) {}
319
320    /** @return DateTimeImmutable */
321    public function setTimestamp(int $timestamp) {}
322
323    /** @return DateTimeImmutable */
324    public static function createFromMutable(DateTime $object) {}
325
326    public static function createFromInterface(DateTimeInterface $object): DateTimeImmutable {}
327}
328
329class DateTimeZone
330{
331    public function __construct(string $timezone) {}
332
333    /**
334     * @return string
335     * @alias timezone_name_get
336     */
337    public function getName() {}
338
339    /**
340     * @return int
341     * @alias timezone_offset_get
342     */
343    public function getOffset(DateTimeInterface $datetime) {}
344
345    /**
346     * @return array|false
347     * @alias timezone_transitions_get
348     */
349    public function getTransitions(int $timestampBegin = PHP_INT_MIN, int $timestampEnd = PHP_INT_MAX) {}
350
351    /**
352     * @return array|false
353     * @alias timezone_location_get
354     */
355    public function getLocation() {}
356
357    /**
358     * @return array
359     * @alias timezone_abbreviations_list
360     */
361    public static function listAbbreviations() {}
362
363    /**
364     * @return array
365     * @alias timezone_identifiers_list
366     */
367    public static function listIdentifiers(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null) {}
368
369    /** @return void */
370    public function __wakeup() {}
371
372    /** @return DateTimeZone */
373    public static function __set_state(array $array) {}
374}
375
376class DateInterval
377{
378    public function __construct(string $duration) {}
379
380    /**
381     * @return DateInterval|false
382     * @alias date_interval_create_from_date_string
383     */
384    public static function createFromDateString(string $datetime) {}
385
386    /**
387     * @return string
388     * @alias date_interval_format
389     */
390    public function format(string $format) {}
391
392    /** @return void */
393    public function __wakeup() {}
394
395    /** @return DateInterval */
396    public static function __set_state(array $array) {}
397}
398
399class DatePeriod implements IteratorAggregate
400{
401    /**
402     * @param DateTimeInterface|string $start
403     * @param DateInterval|int $interval
404     * @param DateTimeInterface|int $end
405     * @param int $options
406     */
407    public function __construct($start, $interval = UNKNOWN, $end = UNKNOWN, $options = UNKNOWN) {}
408
409    /** @return DateTimeInterface */
410    public function getStartDate() {}
411
412    /** @return DateTimeInterface|null */
413    public function getEndDate() {}
414
415    /** @return DateInterval */
416    public function getDateInterval() {}
417
418    /** @return int|null */
419    public function getRecurrences() {}
420
421    /** @return void */
422    public function __wakeup() {}
423
424    /** @return DatePeriod */
425    public static function __set_state(array $array) {}
426
427    public function getIterator(): Iterator {}
428}
429