Corriger l'URL du calendrier et le parsing des dates

- Passe à l'URL Nextcloud directe (le proxy alpinux.org retourne vide)
- Corrige le parsing DTSTART avec TZID (Europe/Paris) et UTC (suffixe Z)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Cédrix 2026-05-05 23:47:16 +02:00
parent 4f6094c6c6
commit aa2c188c78

View file

@ -1,7 +1,7 @@
<?php
function calendar_next_events(int $n = 5): array {
$url = 'https://alpinux.org/public-calendars/n5BWPYsxw7FCYozM?p=webcal';
$url = 'https://alpinux.yourownnet.fr/remote.php/dav/public-calendars/n5BWPYsxw7FCYozM?export';
$cache = sys_get_temp_dir() . '/alpinux_calendar.ics';
$ttl = 3600;
@ -30,11 +30,16 @@ function _ical_upcoming(string $ical, int $n): array {
if (preg_match('/^LOCATION[^:]*:(.+)$/m', $b, $m))
$e['location'] = trim($m[1]);
if (preg_match('/^DTSTART[^:]*:(\d+)/m', $b, $m)) {
$r = $m[1];
$e['start'] = strlen($r) === 8
? mktime(0, 0, 0, substr($r, 4, 2), substr($r, 6, 2), substr($r, 0, 4))
: strtotime($r);
// Handles: DTSTART:YYYYMMDD, DTSTART:YYYYMMDDTHHmmss[Z], DTSTART;TZID=...:YYYYMMDDTHHmmss
if (preg_match('/^DTSTART(?:;[^:]+)?:([\dTZ]+)/m', $b, $m)) {
$raw = $m[1];
if (strlen($raw) === 8) {
$e['start'] = mktime(0, 0, 0, (int)substr($raw, 4, 2), (int)substr($raw, 6, 2), (int)substr($raw, 0, 4));
} else {
$dt = DateTime::createFromFormat('Ymd\THis\Z', $raw, new DateTimeZone('UTC'))
?: DateTime::createFromFormat('Ymd\THis', $raw, new DateTimeZone('Europe/Paris'));
if ($dt) $e['start'] = $dt->getTimestamp();
}
}
if (isset($e['start'], $e['title']) && $e['start'] >= $now)