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:
parent
4f6094c6c6
commit
aa2c188c78
1 changed files with 11 additions and 6 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
function calendar_next_events(int $n = 5): array {
|
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';
|
$cache = sys_get_temp_dir() . '/alpinux_calendar.ics';
|
||||||
$ttl = 3600;
|
$ttl = 3600;
|
||||||
|
|
||||||
|
|
@ -30,11 +30,16 @@ function _ical_upcoming(string $ical, int $n): array {
|
||||||
if (preg_match('/^LOCATION[^:]*:(.+)$/m', $b, $m))
|
if (preg_match('/^LOCATION[^:]*:(.+)$/m', $b, $m))
|
||||||
$e['location'] = trim($m[1]);
|
$e['location'] = trim($m[1]);
|
||||||
|
|
||||||
if (preg_match('/^DTSTART[^:]*:(\d+)/m', $b, $m)) {
|
// Handles: DTSTART:YYYYMMDD, DTSTART:YYYYMMDDTHHmmss[Z], DTSTART;TZID=...:YYYYMMDDTHHmmss
|
||||||
$r = $m[1];
|
if (preg_match('/^DTSTART(?:;[^:]+)?:([\dTZ]+)/m', $b, $m)) {
|
||||||
$e['start'] = strlen($r) === 8
|
$raw = $m[1];
|
||||||
? mktime(0, 0, 0, substr($r, 4, 2), substr($r, 6, 2), substr($r, 0, 4))
|
if (strlen($raw) === 8) {
|
||||||
: strtotime($r);
|
$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)
|
if (isset($e['start'], $e['title']) && $e['start'] >= $now)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue