| @@ -1134,16 +1134,19 @@ | ||
| 1134 | 1134 | */ |
| 1135 | 1135 | public function getDuration(): array |
| 1136 | 1136 | { |
| 1137 | 1137 | $duration = ''; |
| 1138 | - if (!empty($this->duration_days)) { | |
| 1138 | + if ($this->isHoursBased()) { | |
| 1139 | + $duration = yatra_format_duration(0, null, $this->getDurationHours()); | |
| 1140 | + } elseif (!empty($this->duration_days)) { | |
| 1139 | 1141 | $duration = yatra_format_duration($this->duration_days, $this->duration_nights ?? null); |
| 1140 | 1142 | } |
| 1141 | - | |
| 1143 | + | |
| 1142 | 1144 | return [ |
| 1143 | 1145 | 'formatted' => $duration, |
| 1144 | 1146 | 'days' => $this->duration_days ?? 0, |
| 1145 | 1147 | 'nights' => $this->duration_nights ?? 0, |
| 1148 | + 'hours' => $this->getDurationHours(), | |
| 1146 | 1149 | 'has_duration' => !empty($duration) |
| 1147 | 1150 | ]; |
| 1148 | 1151 | } |
| 1149 | 1152 | |
| @@ -1560,8 +1563,30 @@ | ||
| 1560 | 1563 | */ |
| 1561 | 1564 | public function getDurationNights(): int |
| 1562 | 1565 | { |
| 1563 | 1566 | return $this->duration_nights ?? 0; |
| 1567 | + } | |
| 1568 | + | |
| 1569 | + /** | |
| 1570 | + * Duration in hours for hour-based (single-day) tours. 0 when the tour is | |
| 1571 | + * day-based (the default) — see {@see self::isHoursBased()}. | |
| 1572 | + */ | |
| 1573 | + public function getDurationHours(): int | |
| 1574 | + { | |
| 1575 | + return (int) ($this->duration_hours ?? 0); | |
| 1576 | + } | |
| 1577 | + | |
| 1578 | + /** | |
| 1579 | + * Whether this tour's duration is expressed in hours rather than days. | |
| 1580 | + * | |
| 1581 | + * True only when a positive `duration_hours` is set — so every existing | |
| 1582 | + * (day-based) trip returns false and keeps its current behaviour. Used by | |
| 1583 | + * the front-end duration display and the Google Calendar module to build a | |
| 1584 | + * same-day timed event instead of a multi-day span. | |
| 1585 | + */ | |
| 1586 | + public function isHoursBased(): bool | |
| 1587 | + { | |
| 1588 | + return $this->getDurationHours() > 0; | |
| 1564 | 1589 | } |
| 1565 | 1590 | |
| 1566 | 1591 | /** |
| 1567 | 1592 | * Raw difficulty classification ID on the trip row (not a human-readable label). |