Skip to content

Commit d4227c2

Browse files
committed
Add locations() helper method
1 parent 32e45e9 commit d4227c2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<?php namespace de\thekid\dialog\import;
22

3+
use util\TimeZone;
4+
35
class Description {
46
public function __construct(
57
public private(set) array<string, mixed> $meta,
68
public private(set) string $content
79
) { }
10+
11+
public function locations(string|TimeZone $timezone): iterable {
12+
$tz= $timezone instanceof TimeZone ? $timezone->name() : $timezone;
13+
foreach (isset($this->meta['location']) ? [$this->meta['location']] : $this->meta['locations'] as $location) {
14+
$location['timezone']??= $tz;
15+
yield $location;
16+
}
17+
}
818
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,24 @@ public function parse_content() {
4646
public function resolve_timezone($tz, $resolved) {
4747
Assert::equals(
4848
['date' => new Date('2024-12-29 13:19:00', $resolved)],
49-
$this->parse("---\ndate: 2024-12-29 13:19:00 {$tz}\n---\nContent")->meta
49+
$this->parse("---\ndate: 2024-12-29 13:19:00 {$tz}\n---\n")->meta
50+
);
51+
}
52+
53+
#[Test, Values(['Europe/Berlin', 'Asia/Muscat', 'America/New_York'])]
54+
public function location_timezone($tz) {
55+
$locations= implode("\n", [
56+
' - {name: "Here"}',
57+
' - {name: "Oman", timezone: "Asia/Muscat"}',
58+
' - {name: "日本", timezone: "Asia/Tokyo"}',
59+
]);
60+
Assert::equals(
61+
[
62+
['name' => 'Here', 'timezone' => $tz],
63+
['name' => 'Oman', 'timezone' => 'Asia/Muscat'],
64+
['name' => '日本', 'timezone' => 'Asia/Tokyo'],
65+
],
66+
[...$this->parse("---\nlocations:\n{$locations}\n---\n")->locations($tz)]
5067
);
5168
}
5269
}

0 commit comments

Comments
 (0)