From da8870e85f59dc8e83d2c4f50432f688080cb1d1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 Mar 2018 14:17:36 +0100 Subject: [locationinfo] Add permissions --- .../locationinfo/inc/splittime.php.txt | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules-available/locationinfo/inc/splittime.php.txt (limited to 'modules-available/locationinfo/inc/splittime.php.txt') diff --git a/modules-available/locationinfo/inc/splittime.php.txt b/modules-available/locationinfo/inc/splittime.php.txt new file mode 100644 index 00000000..53510fee --- /dev/null +++ b/modules-available/locationinfo/inc/splittime.php.txt @@ -0,0 +1,80 @@ +(Unfinished) + + /* + error_log('Pre calendar: ' . print_r($calendar, true)); + $bad = array(); + for ($i = 0; $i < count($calendar); ++$i) { // Use for..count as we append while iterating + $entry =& $calendar[$i]; + // YYYY-MM-DDHH:MM:SS + $s = explode('T', $entry['start']); + $e = explode('T', $entry['end']); + if (count($s) !== 2 || count($e) !== 2) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + if ($e[0] === $s[0]) // Same day + continue; + $stime = explode(':', $s[1]); + $etime = explode(':', $e[1]); + if (count($stime) < 2 || count($etime) < 2) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + // Fix start + if ($stime[0] == 23 && $stime[1] >= 30) { + // clamp to next day + $day = strtotime($s[0] . ' 12:00 +1 day'); + if ($day === false || $day <= 0) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + $day = date('Y-m-d', $day); + $bad[] = $i; + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $day . 'T00:00:01', + 'end' => $entry['end'] + ); + continue; + } + + // Fix end + if ($etime[0] == 0 && $etime[1] <= 30) { + // clamp to next day + $day = strtotime($e[0] . ' 12:00 -1 day'); + if ($day === false || $day <= 0) { + error_log('Ignoring invalid calendar entry from backend ' . $this->serverId . ': ' . json_encode($entry)); + $bad[] = $i; + continue; + } + $day = date('Y-m-d', $day); + $bad[] = $i; + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $day . 'T23:59:59', + 'end' => $entry['end'] + ); + continue; + } + // Split + $nextday = strtotime($s[0] . ' 12:00 +1 day'); + $nextday = date('Y-m-d', $nextday); + $calendar[] = array( + 'title' => $entry['title'], + 'start' => $nextday . 'T00:00:01', + 'end' => $entry['end'] + ); + $entry['end'] = $s[0] . 'T23:59:59'; + } + unset($entry); + if (!empty($bad)) { + foreach ($bad as $i) { + unset($calendar[$i]); + } + $calendar = array_values($calendar); + } + */ + error_log('Post calendar: ' . print_r($calendar, true)); \ No newline at end of file -- cgit v1.2.3-55-g7522