Skip to content

Commit 51e484b

Browse files
committed
Time\Duration
1 parent 07696ea commit 51e484b

19 files changed

Lines changed: 1122 additions & 2 deletions

ext/date/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// vim:ft=javascript
22

3-
EXTENSION("date", "php_date.c", false, "/Iext/date/lib /DHAVE_TIMELIB_CONFIG_H=1");
3+
EXTENSION("date", "php_date.c php_date_time.c php_date_time_duration.c", false, "/Iext/date/lib /DHAVE_TIMELIB_CONFIG_H=1");
44
PHP_DATE = "yes";
55
ADD_SOURCES("ext/date/lib", "astro.c timelib.c dow.c duration.c parse_date.c parse_posix.c parse_tz.c tm2unixtime.c unixtime2tm.c parse_iso_intervals.c interval.c", "date");
66

ext/date/config0.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ timelib_sources="lib/astro.c lib/dow.c lib/duration.c lib/parse_date.c lib/parse
1818
lib/timelib.c lib/tm2unixtime.c lib/unixtime2tm.c lib/parse_iso_intervals.c lib/interval.c"
1919

2020
PHP_NEW_EXTENSION([date],
21-
[php_date.c],
21+
[php_date.c php_date_time.c php_date_time_duration.c],
2222
[no],,
2323
[$PHP_DATE_CFLAGS])
2424

ext/date/php_date.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ PHP_MINIT_FUNCTION(date)
447447
REGISTER_INI_ENTRIES();
448448
date_register_classes();
449449
register_php_date_symbols(module_number);
450+
PHP_MINIT(date_time)(INIT_FUNC_ARGS_PASSTHRU);
450451

451452
php_date_global_timezone_db = NULL;
452453
php_date_global_timezone_db_enabled = 0;

ext/date/php_date.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,6 @@ PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, siz
153153
PHPAPI void php_date_initialize_from_ts_long(php_date_obj *dateobj, zend_long sec, int usec);
154154
PHPAPI bool php_date_initialize_from_ts_double(php_date_obj *dateobj, double ts);
155155

156+
#include "php_date_time.h"
157+
156158
#endif /* PHP_DATE_H */

ext/date/php_date_time.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright © The PHP Group and Contributors. |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to the Modified BSD License that is |
6+
| bundled with this package in the file LICENSE, and is available |
7+
| through the World Wide Web at <https://www.php.net/license/>. |
8+
| |
9+
| SPDX-License-Identifier: BSD-3-Clause |
10+
+----------------------------------------------------------------------+
11+
| Authors: Derick Rethans <derick@derickrethans.nl> |
12+
| Tim Düsterhus <timwolla@php.net> |
13+
+----------------------------------------------------------------------+
14+
*/
15+
16+
#include "php.h"
17+
#include "Zend/zend_exceptions.h"
18+
19+
#include "php_date_time.h"
20+
#include "php_date_time_arginfo.h"
21+
22+
zend_class_entry *php_date_ce_time_duration;
23+
zend_class_entry *php_date_ce_time_timeexception;
24+
25+
static zend_object_handlers php_date_time_duration_object_handlers;
26+
27+
static zend_object *php_date_time_duration_object_create(zend_class_entry *ce)
28+
{
29+
php_date_time_duration *obj = zend_object_alloc(sizeof(*obj), ce);
30+
31+
zend_object_std_init(&obj->std, ce);
32+
object_properties_init(&obj->std, ce);
33+
34+
timelib_duration_ctor_static(&obj->duration, 0,0, false);
35+
36+
return &obj->std;
37+
}
38+
39+
PHP_MINIT_FUNCTION(date_time)
40+
{
41+
php_date_ce_time_timeexception = register_class_Time_TimeException(zend_ce_exception);
42+
43+
memcpy(&php_date_time_duration_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
44+
php_date_time_duration_object_handlers.offset = offsetof(php_date_time_duration, std);
45+
php_date_ce_time_duration = register_class_Time_Duration();
46+
php_date_ce_time_duration->create_object = php_date_time_duration_object_create;
47+
php_date_ce_time_duration->default_object_handlers = &php_date_time_duration_object_handlers;
48+
49+
return SUCCESS;
50+
}

ext/date/php_date_time.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright © The PHP Group and Contributors. |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to the Modified BSD License that is |
6+
| bundled with this package in the file LICENSE, and is available |
7+
| through the World Wide Web at <https://www.php.net/license/>. |
8+
| |
9+
| SPDX-License-Identifier: BSD-3-Clause |
10+
+----------------------------------------------------------------------+
11+
| Authors: Derick Rethans <derick@derickrethans.nl> |
12+
| Tim Düsterhus <timwolla@php.net> |
13+
+----------------------------------------------------------------------+
14+
*/
15+
16+
#ifndef PHP_DATE_TIME_H
17+
#define PHP_DATE_TIME_H
18+
19+
# include "php.h"
20+
# include "lib/timelib.h"
21+
22+
typedef struct php_date_time_duration {
23+
timelib_duration duration;
24+
zend_object std;
25+
} php_date_time_duration;
26+
27+
#define php_date_time_duration_from_obj(obj) ZEND_CONTAINER_OF(obj, php_date_time_duration, std)
28+
29+
#define Z_DATE_TIME_DURATION_P(zv) php_date_time_duration_from_obj(Z_OBJ_P((zv)))
30+
31+
PHPAPI extern zend_class_entry *php_date_ce_time_duration;
32+
PHPAPI extern zend_class_entry *php_date_ce_time_timeexception;
33+
34+
PHP_MINIT_FUNCTION(date_time);
35+
36+
#endif /* PHP_DATE_TIME_H */

ext/date/php_date_time.stub.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/** @generate-class-entries */
4+
5+
namespace Time {
6+
/** @strict-properties */
7+
class TimeException extends \Exception { }
8+
9+
/**
10+
* @strict-properties
11+
*/
12+
final readonly class Duration
13+
{
14+
public readonly int $seconds;
15+
16+
public readonly int $nanoseconds;
17+
18+
public readonly bool $negative;
19+
20+
public static function fromSeconds(int $seconds, int $nanoseconds = 0): Duration
21+
{
22+
}
23+
24+
public static function fromNanoseconds(int $nanoseconds): Duration
25+
{
26+
}
27+
28+
public static function fromMicroseconds(int $microseconds): Duration
29+
{
30+
}
31+
32+
public static function fromMilliseconds(int $milliseconds): Duration
33+
{
34+
}
35+
36+
public static function fromMinutes(int $minutes): Duration
37+
{
38+
}
39+
40+
public static function fromHours(int $hours): Duration
41+
{
42+
}
43+
44+
public static function fromIso8601DurationString(string $specification): Duration
45+
{
46+
}
47+
48+
public function negate(): Duration
49+
{
50+
}
51+
52+
public function absolute(): Duration
53+
{
54+
}
55+
56+
public function add(Duration $duration): Duration
57+
{
58+
}
59+
60+
public function sub(Duration $duration): Duration
61+
{
62+
}
63+
64+
public function multiplyBy(int $factor): Duration
65+
{
66+
}
67+
68+
public function divideBy(int $divisor): Duration
69+
{
70+
}
71+
72+
public static function compare(Duration $a, Duration $b): int
73+
{
74+
}
75+
}
76+
}

ext/date/php_date_time_arginfo.h

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)