diff --git a/hwe/func.php b/hwe/func.php index e7ea5903..0284e298 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -923,6 +923,13 @@ function banner() function addTurn($date, int $turnterm, int $turn = 1, bool $withFraction = true) { + if($turnterm < 0){ + if($turnterm == -60){ + return VarTurn60::fromDatetime(new \DateTimeImmutable(($date)))->addTurn($turn )->toDateStr($withFraction); + } + throw new \Exception("InvalidTurnTerm".$turnterm); + } + $date = new \DateTime($date); $target = $turnterm * $turn; $date->add(new \DateInterval("PT{$target}M")); @@ -934,6 +941,13 @@ function addTurn($date, int $turnterm, int $turn = 1, bool $withFraction = true) function subTurn($date, int $turnterm, int $turn = 1, bool $withFraction = true) { + if($turnterm < 0){ + if($turnterm == -60){ + return VarTurn60::fromDatetime(new \DateTimeImmutable(($date)))->addTurn($turn * -1)->toDateStr($withFraction); + } + throw new \Exception("InvalidTurnTerm".$turnterm); + } + $date = new \DateTime($date); $target = $turnterm * $turn; $date->sub(new \DateInterval("PT{$target}M")); @@ -945,6 +959,14 @@ function subTurn($date, int $turnterm, int $turn = 1, bool $withFraction = true) function cutTurn($date, int $turnterm, bool $withFraction = true) { + if($turnterm < 0){ + if($turnterm == -60){ + [$baseDate, ] = VarTurn60::fromDatetime(new \DateTimeImmutable(($date)))->cutTurn($withFraction); + return $baseDate; + } + throw new \Exception("InvalidTurnTerm".$turnterm); + } + $date = new \DateTime($date); $baseDate = new \DateTime($date->format('Y-m-d')); @@ -963,6 +985,8 @@ function cutTurn($date, int $turnterm, bool $withFraction = true) function cutDay($date, int $turnterm, bool $withFraction = true) { + assert($turnterm > 0); + $date = new \DateTime($date); $baseDate = new \DateTime($date->format('Y-m-d'));