Use RFC3339 strings to represent start and end times for shifts json start/stop, fixed ical timezone output

This commit is contained in:
Igor Scheller 2021-12-09 13:00:47 +01:00 committed by msquare
parent 39f83ef082
commit 38dda01330
3 changed files with 16 additions and 4 deletions

View File

@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use Engelsystem\Http\Exceptions\HttpForbidden;
use Engelsystem\Models\Room;
use Engelsystem\Models\Shifts\ScheduleShift;
@ -381,6 +382,10 @@ function shifts_json_export_controller()
}
$shifts = load_ical_shifts();
foreach ($shifts as $row => $shift) {
$shifts[$row]['start_date'] = Carbon::createFromTimestamp($shift['start'])->toRfc3339String();
$shifts[$row]['end_date'] = Carbon::createFromTimestamp($shift['end'])->toRfc3339String();
}
header('Content-Type: application/json; charset=utf-8');
raw_output(json_encode($shifts));

View File

@ -619,7 +619,8 @@ function Shifts_by_user($userId, $include_freeload_comments = false)
`ShiftEntry`.`Comment`,
' . ($include_freeload_comments ? '`ShiftEntry`.`freeload_comment`, ' : '') . '
`Shifts`.*,
@@session.time_zone AS timezone
@@session.time_zone AS timezone,
? AS event_timezone
FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
@ -628,7 +629,8 @@ function Shifts_by_user($userId, $include_freeload_comments = false)
ORDER BY `start`
',
[
$userId
config('timezone'),
$userId,
]
);
}

View File

@ -1,5 +1,6 @@
<?php
use Carbon\Carbon;
use Engelsystem\Http\Exceptions\HttpForbidden;
/**
@ -54,6 +55,9 @@ function send_ical_from_shifts($shifts)
*/
function make_ical_entry_from_shift($shift)
{
$start = Carbon::createFromTimestamp($shift['start']);
$end = Carbon::createFromTimestamp($shift['end']);
$output = "BEGIN:VEVENT\r\n";
$output .= 'UID:' . md5($shift['start'] . $shift['end'] . $shift['name']) . "\r\n";
$output .= 'SUMMARY:' . str_replace("\n", "\\n", $shift['name'])
@ -61,8 +65,9 @@ function make_ical_entry_from_shift($shift)
if (isset($shift['Comment'])) {
$output .= 'DESCRIPTION:' . str_replace("\n", "\\n", $shift['Comment']) . "\r\n";
}
$output .= 'DTSTART;TZID=Europe/Berlin:' . date("Ymd\THis", $shift['start']) . "\r\n";
$output .= 'DTEND;TZID=Europe/Berlin:' . date("Ymd\THis", $shift['end']) . "\r\n";
$output .= 'DTSTAMP:' . $start->utc()->format('Ymd\THis\Z') . "\r\n";
$output .= 'DTSTART:' . $start->utc()->format('Ymd\THis\Z') . "\r\n";
$output .= 'DTEND:' . $end->utc()->format('Ymd\THis\Z') . "\r\n";
$output .= 'LOCATION:' . $shift['Name'] . "\r\n";
$output .= "END:VEVENT\r\n";
return $output;