mirror of
https://github.com/kevinpapst/kimai2.git
synced 2025-05-11 04:10:47 +00:00
new methods to create datetime
This commit is contained in:
parent
0349b5cb2d
commit
c93f7bda1c
1 changed files with 27 additions and 0 deletions
|
@ -69,6 +69,19 @@ final class DateTimeFactory
|
|||
return DateTime::createFromInterface($date);
|
||||
}
|
||||
|
||||
private function createDate(DateTimeInterface|string|null $date = null): \DateTimeImmutable
|
||||
{
|
||||
if ($date === null) {
|
||||
$date = 'now';
|
||||
}
|
||||
|
||||
if (\is_string($date)) {
|
||||
return $this->createDate($date);
|
||||
}
|
||||
|
||||
return \DateTimeImmutable::createFromInterface($date);
|
||||
}
|
||||
|
||||
public function getStartOfWeek(DateTimeInterface|string|null $date = null): DateTime
|
||||
{
|
||||
$date = $this->getDate($date);
|
||||
|
@ -139,6 +152,20 @@ final class DateTimeFactory
|
|||
return new \DateTimeImmutable($datetime, $this->getTimezone());
|
||||
}
|
||||
|
||||
public function createStartOfDay(DateTimeInterface|string|null $date = null): \DateTimeImmutable
|
||||
{
|
||||
$date = $this->createDate($date);
|
||||
|
||||
return $date->modify('00:00:00');
|
||||
}
|
||||
|
||||
public function createEndOfDay(DateTimeInterface|string|null $date = null): \DateTimeImmutable
|
||||
{
|
||||
$date = $this->createDate($date);
|
||||
|
||||
return $date->modify('23:59:59');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $format
|
||||
* @param null|string $datetime
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue