fix: allow booking the free part of a partly booked day
This commit is contained in:
1 parent
a88ff7ff24
commit
78839838f0
15 files changed
+541
-60
No files matched your search
+20
-10
@@ -37,20 +37,30 @@ final class BookingRequest
|
||||
{
|
||||
$this->date = $date;
|
||||
|
||||
if (null !== $time && !$time->isAllDay()) {
|
||||
$this->allDay = false;
|
||||
$this->startTime = self::timeOf($time->startMinute);
|
||||
$this->endTime = self::timeOf($time->endMinute);
|
||||
if (null === $time || $time->isAllDay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->allDay = false;
|
||||
// An edge that is open to the edge of the day is left blank rather than filled in:
|
||||
// 24:00 has no representation in <input type="time"> at all, and a blank already means
|
||||
// "to the end of the day" here, exactly as it does on the board's span picker.
|
||||
$this->startTime = TimeRange::DAY_START === $time->startMinute ? null : self::timeOf($time->startMinute);
|
||||
$this->endTime = TimeRange::DAY_END === $time->endMinute ? null : self::timeOf($time->endMinute);
|
||||
}
|
||||
|
||||
public function timeRange(): TimeRange
|
||||
{
|
||||
if ($this->allDay || null === $this->startTime || null === $this->endTime) {
|
||||
if ($this->allDay || (null === $this->startTime && null === $this->endTime)) {
|
||||
return TimeRange::wholeDay();
|
||||
}
|
||||
|
||||
return TimeRange::fromTimes($this->startTime, $this->endTime);
|
||||
// One-sided input is open to that edge of the day -- the same rule TimeRange::parse()
|
||||
// applies to the board's ?from=&to= pair, so the two never disagree.
|
||||
return TimeRange::fromMinutes(
|
||||
null === $this->startTime ? TimeRange::DAY_START : self::minutesOf($this->startTime),
|
||||
null === $this->endTime ? TimeRange::DAY_END : self::minutesOf($this->endTime),
|
||||
);
|
||||
}
|
||||
|
||||
public function repeats(): bool
|
||||
@@ -66,10 +76,10 @@ final class BookingRequest
|
||||
public function validate(ExecutionContextInterface $context): void
|
||||
{
|
||||
if (!$this->allDay) {
|
||||
foreach (['startTime' => $this->startTime, 'endTime' => $this->endTime] as $field => $value) {
|
||||
if (null === $value) {
|
||||
$context->buildViolation('Bitte eine Uhrzeit angeben.')->atPath($field)->addViolation();
|
||||
}
|
||||
if (null === $this->startTime && null === $this->endTime) {
|
||||
$context->buildViolation('Bitte eine Uhrzeit angeben oder „Ganzer Tag" wählen.')
|
||||
->atPath('startTime')
|
||||
->addViolation();
|
||||
}
|
||||
|
||||
if (null !== $this->startTime && null !== $this->endTime
|
||||
|
||||
Reference in new issue
Block a user