modifs.mineures sans commentaires
This commit is contained in:
parent
cf5ef38a0f
commit
7d332552ab
@ -91,7 +91,10 @@ class Delay {
|
||||
$from = MutableDateTime::with($from)->clone(true);
|
||||
if ($delay === "INF") {
|
||||
$dest = $from;
|
||||
$dest->add(new DateInterval("P9999Y"));
|
||||
# rajouter 1000 ans pour ne pas dépasser la capacité
|
||||
#XXX avant, c'était 9999 ans, mais getDest() provoque une exception parce
|
||||
# que DateTime ne sait pas traiter une valeur flottante
|
||||
$dest->add(new DateInterval("P1000Y"));
|
||||
$repr = "INF";
|
||||
} elseif (is_int($delay)) {
|
||||
[$dest, $repr] = self::compute_dest($delay, "s", null, $from);
|
||||
@ -119,10 +122,11 @@ class Delay {
|
||||
}
|
||||
|
||||
function __serialize(): array {
|
||||
return [$this->dest, $this->repr];
|
||||
return [$this->dest->clone(), $this->repr];
|
||||
}
|
||||
function __unserialize(array $data): void {
|
||||
[$this->dest, $this->repr] = $data;
|
||||
[$dest, $this->repr] = $data;
|
||||
$this->dest = $dest->clone(true);
|
||||
}
|
||||
|
||||
/** @var MutableDateTime */
|
||||
@ -132,20 +136,22 @@ class Delay {
|
||||
return $this->dest->clone();
|
||||
}
|
||||
|
||||
function addDuration($duration) {
|
||||
function addDuration($duration): self {
|
||||
if (is_numeric($duration) && $duration < 0) {
|
||||
$this->dest->sub(DateInterval::with(-$duration));
|
||||
} else {
|
||||
$this->dest->add(DateInterval::with($duration));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
function subDuration($duration) {
|
||||
function subDuration($duration): self {
|
||||
if (is_numeric($duration) && $duration < 0) {
|
||||
$this->dest->add(DateInterval::with(-$duration));
|
||||
} else {
|
||||
$this->dest->sub(DateInterval::with($duration));
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @var string */
|
||||
|
@ -1,10 +1,9 @@
|
||||
# nulib\php\time
|
||||
|
||||
* Date, DateTime sont immutables par défaut. par exemple, add() retourne un nouvel objet.
|
||||
ajouter une version des méthodes qui modifie les données en place en les
|
||||
préfixant de `_` e.g `_add()`
|
||||
|
||||
en terme d'implémentation, dériver \DateTime pour supporter les modification
|
||||
en place, bien que ce ne soit pas le fonctionnement par défaut
|
||||
* refaire l'implémentation pour les délais INF. c'est un cas particulier qui
|
||||
n'est jamais atteint. il faut donc implémenter un traitement spécifique dans
|
||||
chaque méthode (i.e `if ($repr === "INF") { doSomething() }`)
|
||||
* la destination est toujours 1000 ans dans le futur
|
||||
* la différence est toujours de 1000 ans
|
||||
|
||||
-*- coding: utf-8 mode: markdown -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8:noeol:binary
|
7
php/tbin/cachectl.php
Executable file
7
php/tbin/cachectl.php
Executable file
@ -0,0 +1,7 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
|
||||
use cli\CachectlApp;
|
||||
|
||||
CachectlApp::run();
|
@ -7,6 +7,15 @@ use nulib\cache\CacheFile;
|
||||
use nulib\ext\yaml;
|
||||
use nulib\os\sh;
|
||||
|
||||
function Txx(...$parts) {
|
||||
$line = [];
|
||||
foreach ($parts as $part) {
|
||||
if (is_scalar($part)) $line[] = strval($part);
|
||||
else $line[] = var_export($part, true);
|
||||
}
|
||||
echo implode("", $line)."\n";
|
||||
}
|
||||
|
||||
function show(string $prefix, CacheFile $cache, bool $dumpInfos=true): void {
|
||||
Txx("$prefix=", $cache->get());
|
||||
if ($dumpInfos) {
|
||||
|
@ -118,4 +118,12 @@ class DateTimeTest extends TestCase {
|
||||
self::assertFalse($b >= $b2);
|
||||
self::assertFalse($b >= $b3);
|
||||
}
|
||||
|
||||
function testSerialize() {
|
||||
$date = new DateTime();
|
||||
$serialized = serialize($date);
|
||||
echo "serialized: $serialized\n";
|
||||
$unserialized = unserialize($serialized);
|
||||
self::assertEquals($date, $unserialized);
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,12 @@ class DelayTest extends TestCase {
|
||||
sleep(5);
|
||||
self::assertTrue($delay->isElapsed());
|
||||
}
|
||||
|
||||
function testSerialize() {
|
||||
$delay = new Delay(5);
|
||||
$serialized = serialize($delay);
|
||||
echo "serialized: $serialized\n";
|
||||
$unserialized = unserialize($serialized);
|
||||
self::assertEquals($delay, $unserialized);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user