-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_calendar.php
More file actions
88 lines (77 loc) · 3.53 KB
/
Copy path06_calendar.php
File metadata and controls
88 lines (77 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Example: Using country calendars for business-day calculations.
* Run: php examples/06_calendar.php
*/
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use VeryCodeCom\Suus\Calendar\AustriaCalendar;
use VeryCodeCom\Suus\Calendar\CalendarFactory;
use VeryCodeCom\Suus\Calendar\CzechCalendar;
use VeryCodeCom\Suus\Calendar\GermanCalendar;
use VeryCodeCom\Suus\Calendar\HungarianCalendar;
use VeryCodeCom\Suus\Calendar\PolishCalendar;
use VeryCodeCom\Suus\Calendar\RomanianCalendar;
use VeryCodeCom\Suus\Calendar\SlovakCalendar;
use VeryCodeCom\Suus\Calendar\SlovenianCalendar;
use VeryCodeCom\Suus\Calendar\SwitzerlandCalendar;
$calendars = [
'PL' => new PolishCalendar(),
'DE' => new GermanCalendar(),
'AT' => new AustriaCalendar(),
'CH' => new SwitzerlandCalendar(),
'CZ' => new CzechCalendar(),
'SK' => new SlovakCalendar(),
'HU' => new HungarianCalendar(),
'RO' => new RomanianCalendar(),
'SI' => new SlovenianCalendar(),
];
// Check key dates across all calendars
$dates = [
'2025-04-18' => 'Good Friday (DE/CH/CZ/SK/SI holiday, not PL/AT/HU)',
'2025-04-21' => 'Easter Monday (holiday everywhere, Western)',
'2025-05-01' => 'Labour Day (holiday everywhere)',
'2025-05-03' => 'Polish Constitution Day (PL only, Sat in 2025)',
'2025-06-19' => 'Corpus Christi (PL/AT) / Ger. not federal',
'2025-08-01' => 'Swiss National Day (CH only)',
'2025-08-15' => 'Assumption (PL/AT/RO - but check RO uses Orthodox!)',
'2025-08-20' => 'Hungarian Foundation Day (HU only)',
'2025-10-03' => 'German Unity Day (DE only)',
'2025-10-23' => 'Hungarian Revolution Day (HU only)',
'2025-10-26' => 'Austrian National Day (AT only)',
'2025-10-31' => 'Reformation Day (SI only)',
'2025-12-01' => 'Romanian National Day (RO only)',
'2024-05-05' => 'Orthodox Easter Sunday 2024 (RO only, Western Easter = March 31)',
'2024-05-06' => 'Orthodox Easter Monday 2024 (RO only)',
];
echo str_pad('Date', 12) . str_pad('Description', 48) . implode(' ', array_keys($calendars)) . "\n";
echo str_repeat('-', 12 + 48 + count($calendars) * 4) . "\n";
foreach ($dates as $date => $label) {
$dt = new DateTimeImmutable($date);
echo str_pad($date, 12) . str_pad(substr($label, 0, 47), 48);
foreach ($calendars as $code => $cal) {
$business = $cal->isBusinessDay($dt) ? 'work' : 'off ';
echo ' ' . $business;
}
echo "\n";
}
// CalendarFactory auto-detection
echo "\n--- CalendarFactory auto-detection ---\n";
foreach (array_keys($calendars) as $cc) {
$cal = CalendarFactory::forCountry($cc);
echo " {$cc} → " . (new \ReflectionClass($cal))->getShortName() . "\n";
}
// addBusinessDays example with Romania (Orthodox Easter 2024)
echo "\n--- Romanian calendar: Orthodox Easter 2024 ---\n";
$ro = new RomanianCalendar();
echo "Orthodox Easter 2024: " . $ro->orthodoxEasterDate(2024)->format('Y-m-d') . "\n";
echo "Orthodox Easter 2025: " . $ro->orthodoxEasterDate(2025)->format('Y-m-d') . "\n";
echo "From 2024-04-30 + 2 RO business days = ";
echo $ro->addBusinessDays(new DateTimeImmutable('2024-04-30'), 2)->format('Y-m-d');
echo " (skips Orthodox Good Friday May 3 and Orthodox Easter May 5)\n";
// Override calendar in SuusClient
echo "\n--- Override calendar in SuusClient ---\n";
echo "// Use HungarianCalendar when sender is in Hungary:\n";
echo "// \$client = new SuusClient(\$config, calendar: new HungarianCalendar());\n";
echo "// Auto-detection (no override needed - client reads sender country code):\n";
echo "// \$client = new SuusClient(\$config);\n";