Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add time functions #1150

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
6 changes: 6 additions & 0 deletions builtin-functions/kphp-light/crypto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ function openssl_sign ($data ::: string, &$signature ::: string, $priv_key_id ::
/** @kphp-extern-func-info interruptible */
function openssl_verify ($data ::: string, $signature ::: string, $pub_key_id ::: string, $signature_alg ::: int = 1) ::: int;

/** @kphp-extern-func-info interruptible */
function openssl_random_pseudo_bytes ($length ::: int) ::: string | false;

/** @kphp-extern-func-info interruptible */
function openssl_x509_parse ($x509cert ::: string, $shortnames ::: bool = true) ::: mixed[] | false;

// ===== UNSUPPORTED =====

define('X509_PURPOSE_SSL_CLIENT' , 1);
Expand Down
10 changes: 2 additions & 8 deletions builtin-functions/kphp-light/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require_once __DIR__ . '/job-workers.txt';
require_once __DIR__ . '/rpc.txt';
require_once __DIR__ . '/string.txt';
require_once __DIR__ . '/kphp-toggles.txt';
require_once __DIR__ . '/kphp_internal.txt';
require_once __DIR__ . '/time.txt';

/** defined in runtime-core.h **/
function likely ($x ::: bool) ::: bool;
Expand Down Expand Up @@ -143,14 +145,6 @@ function json_encode ($v ::: mixed, $options ::: int = 0) ::: string | false;

function json_decode ($v ::: string, $assoc ::: bool = false) ::: mixed;

// === Crypto======================================================================================

/** @kphp-extern-func-info interruptible */
function openssl_random_pseudo_bytes ($length ::: int) ::: string | false;

/** @kphp-extern-func-info interruptible */
function openssl_x509_parse ($x509cert ::: string, $shortnames ::: bool = true) ::: mixed[] | false;

// === Misc =======================================================================================

/** @kphp-extern-func-info cpp_template_call */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php



function _exception_set_location($e, string $filename, int $line): ^1;
// ===== SUPPORTED =====

// microtime(false) specialization
/** @kphp-extern-func-info generate-stub */
function _microtime_string(): string;
// microtime(true) specialization
/** @kphp-extern-func-info generate-stub */
function _microtime_float(): float;

// hrtime(true) specialization
/** @kphp-extern-func-info generate-stub */
function _hrtime_int(): int;
// hrtime(false) specialization
/** @kphp-extern-func-info generate-stub */
function _hrtime_array(): int[];


// ===== UNSUPPORTED =====


function _exception_set_location($e, string $filename, int $line): ^1;

// `new $c(...)` => `_by_name_construct($c, ...)`
function _by_name_construct(string $class_name, ...$args) ::: instance<^1>;
// `$c::method()` => `_by_name_call_method($c, 'method')`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<?php

// ===== SUPPORTED =====

function mktime (int $hour, ?int $minute = null, ?int $second = null,
?int $month = null, ?int $day = null, ?int $year = null) ::: int;

function date ($format ::: string, $timestamp ::: ?int = null) ::: string;

function date_default_timezone_set ($s ::: string) ::: bool;

function gmdate ($format ::: string, $timestamp ::: ?int = null) ::: string;

function time() ::: int;

function microtime ($get_as_float ::: bool = false) ::: mixed;

function hrtime (bool $as_number = false): mixed; // int[]|int

// ===== UNSUPPORTED =====

/** @kphp-generate-stub-class */
class DateInterval {
/** @kphp-extern-func-info can_throw generate-stub */
Expand Down Expand Up @@ -144,32 +163,19 @@ define('DATE_RFC3339', "Y-m-d\TH:i:sP");
define('DATE_RSS', "D, d M Y H:i:s O");
define('DATE_W3C', "Y-m-d\TH:i:sP");

/** @kphp-extern-func-info generate-stub */
function date ($format ::: string, $timestamp ::: int = PHP_INT_MIN) ::: string;
/** @kphp-extern-func-info generate-stub */
function date_default_timezone_set ($s ::: string) ::: bool;
/** @kphp-extern-func-info generate-stub */
function date_default_timezone_get() ::: string;
/** @kphp-extern-func-info generate-stub */
function getdate ($timestamp ::: int = PHP_INT_MIN) ::: mixed[];
/** @kphp-extern-func-info generate-stub */
function gmdate ($format ::: string, $timestamp ::: int = PHP_INT_MIN) ::: string;
/** @kphp-extern-func-info generate-stub */
function gmmktime ($h ::: int = PHP_INT_MIN, $m ::: int = PHP_INT_MIN, $s ::: int = PHP_INT_MIN, $month ::: int = PHP_INT_MIN, $day ::: int = PHP_INT_MIN, $year ::: int = PHP_INT_MIN) ::: int;
/** @kphp-extern-func-info generate-stub */
function hrtime (bool $as_number = false): mixed; // int[]|int
/** @kphp-extern-func-info generate-stub */
function mktime ($h ::: int = PHP_INT_MIN, $m ::: int = PHP_INT_MIN, $s ::: int = PHP_INT_MIN, $month ::: int = PHP_INT_MIN, $day ::: int = PHP_INT_MIN, $year ::: int = PHP_INT_MIN) ::: int;

/** @kphp-extern-func-info generate-stub */
function localtime ($timestamp ::: int = PHP_INT_MIN, $is_associative ::: bool = false) ::: mixed[];
/** @kphp-extern-func-info generate-stub */
function microtime ($get_as_float ::: bool = false) ::: mixed;
/** @kphp-extern-func-info generate-stub */
function strftime ($format ::: string, $timestamp ::: int = PHP_INT_MIN) ::: string;
/** @kphp-extern-func-info generate-stub */
function strtotime ($time ::: string, $timestamp ::: int = PHP_INT_MIN) ::: int | false;
/** @kphp-extern-func-info generate-stub */
function time() ::: int;


/** @kphp-extern-func-info generate-stub */
Expand Down
2 changes: 0 additions & 2 deletions builtin-functions/kphp-light/unsupported-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ require_once __DIR__ . '/unsupported/file.txt';
require_once __DIR__ . '/unsupported/fork.txt';
require_once __DIR__ . '/unsupported/kml.txt';
require_once __DIR__ . '/unsupported/kphp-tracing.txt';
require_once __DIR__ . '/unsupported/kphp_internal.txt';
require_once __DIR__ . '/unsupported/math.txt';
require_once __DIR__ . '/unsupported/memcache.txt';
require_once __DIR__ . '/unsupported/misc.txt';
require_once __DIR__ . '/unsupported/regex.txt';
require_once __DIR__ . '/unsupported/serialize.txt';
require_once __DIR__ . '/unsupported/server.txt';
require_once __DIR__ . '/unsupported/spl.txt';
require_once __DIR__ . '/unsupported/time.txt';
require_once __DIR__ . '/unsupported/uberh3.txt';
require_once __DIR__ . '/unsupported/vkext.txt';
1 change: 1 addition & 0 deletions runtime-light/stdlib/stdlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ prepend(
rpc/rpc-tl-request.cpp
string/string-state.cpp
system/system-state.cpp
time/time-functions.cpp
file/file-stream-state.cpp)
Loading
Loading