mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add some time functions
This commit is contained in:
parent
a0a049fe91
commit
53730d16ef
@ -21,6 +21,7 @@ function ml_get_lisp(): array
|
|||||||
(new MadLisp\Lib\Compare())->register($env);
|
(new MadLisp\Lib\Compare())->register($env);
|
||||||
(new MadLisp\Lib\Math())->register($env);
|
(new MadLisp\Lib\Math())->register($env);
|
||||||
(new MadLisp\Lib\Strings())->register($env);
|
(new MadLisp\Lib\Strings())->register($env);
|
||||||
|
(new MadLisp\Lib\Time())->register($env);
|
||||||
(new MadLisp\Lib\Types())->register($env);
|
(new MadLisp\Lib\Types())->register($env);
|
||||||
|
|
||||||
return [$lisp, $env];
|
return [$lisp, $env];
|
||||||
|
30
src/Lib/Time.php
Normal file
30
src/Lib/Time.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
namespace MadLisp\Lib;
|
||||||
|
|
||||||
|
use MadLisp\CoreFunc;
|
||||||
|
use MadLisp\Env;
|
||||||
|
|
||||||
|
class Time implements ILib
|
||||||
|
{
|
||||||
|
public function register(Env $env): void
|
||||||
|
{
|
||||||
|
$env->set('time', new CoreFunc('time', 'Return the current time as unix timestamp.', 0, 0,
|
||||||
|
fn () => time()
|
||||||
|
));
|
||||||
|
|
||||||
|
$env->set('date', new CoreFunc('date', 'Format the time according to first argument.', 1, 2,
|
||||||
|
fn (string $format, ?int $time = null) => date($format, $time !== null ? $time : time())
|
||||||
|
));
|
||||||
|
|
||||||
|
$env->set('strtotime', new CoreFunc('strtotime', 'Parse datetime string into unix timestamp. Optional second argument can be used to give time for relative formats.', 1, 2,
|
||||||
|
fn (string $format, ?int $time = null) => strtotime($format, $time !== null ? $time : time())
|
||||||
|
));
|
||||||
|
|
||||||
|
$env->set('sleep', new CoreFunc('sleep', 'Sleep (wait) for the specified time in milliseconds.', 1, 1,
|
||||||
|
function (int $time) {
|
||||||
|
usleep($time * 1000);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user