Skip to content

Commit 5995702

Browse files
committed
Simplify code to iterate locations
1 parent ea05931 commit 5995702

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/main/php/de/thekid/dialog/import/Description.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function __construct(
1010

1111
public function locations(string|TimeZone $timezone): iterable {
1212
$tz= $timezone instanceof TimeZone ? $timezone->name() : $timezone;
13-
foreach (isset($this->meta['location']) ? [$this->meta['location']] : $this->meta['locations'] as $location) {
13+
foreach ($this->meta['locations'] ?? [$this->meta['location']] as $location) {
1414
$location['timezone']??= $tz;
1515
yield $location;
1616
}

src/test/php/de/thekid/dialog/unittest/DescriptionsTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,24 @@ public function resolve_timezone($tz, $resolved) {
5050
);
5151
}
5252

53+
#[Test]
54+
public function passed_timezone_used() {
55+
$tz= 'Europe/Berlin';
56+
Assert::equals(
57+
[['name' => 'Berlin', 'timezone' => $tz]],
58+
[...$this->parse("---\nlocation:\n{name: \"Berlin\"}\n---\n")->locations($tz)]
59+
);
60+
}
61+
62+
#[Test]
63+
public function location_supplied_timezone_used() {
64+
$tz= 'Europe/Berlin';
65+
Assert::equals(
66+
[['name' => 'Oman', 'timezone' => 'Asia/Muscat']],
67+
[...$this->parse("---\nlocation:\n{name: \"Oman\", timezone: \"Asia/Muscat\"}\n---\n")->locations($tz)]
68+
);
69+
}
70+
5371
#[Test, Values(['Europe/Berlin', 'Asia/Muscat', 'America/New_York'])]
5472
public function location_timezone($tz) {
5573
$locations= implode("\n", [

0 commit comments

Comments
 (0)