| Conditions | 7 |
| Paths | 64 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function generate(Link $link): string |
||
| 16 | { |
||
| 17 | $url = 'https://outlook.live.com/owa/?path=/calendar/action/compose&rru=addevent'; |
||
| 18 | |||
| 19 | $dateTimeFormat = $link->allDay ? 'Ymd' : "Ymd\THis"; |
||
| 20 | $utcStartDateTime = (clone $link->from)->setTimezone(new DateTimeZone('UTC')); |
||
| 21 | $utcEndDateTime = (clone $link->to)->setTimezone(new DateTimeZone('UTC')); |
||
| 22 | $url .= '&startdt='.$utcStartDateTime->format($dateTimeFormat); |
||
| 23 | |||
| 24 | $isSingleDayEvent = $link->to->diff($link->from)->d < 2; |
||
| 25 | $canOmitEndDateTime = $link->allDay && $isSingleDayEvent; |
||
| 26 | if (! $canOmitEndDateTime) { |
||
| 27 | $url .= '&enddt='.$utcEndDateTime->format($dateTimeFormat); |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($link->allDay) { |
||
| 31 | $url .= '&allday=true'; |
||
| 32 | } |
||
| 33 | |||
| 34 | $url .= '&subject='.urlencode($link->title); |
||
| 35 | |||
| 36 | if ($link->description) { |
||
| 37 | $url .= '&body='.urlencode($link->description); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($link->address) { |
||
| 41 | $url .= '&location='.urlencode($link->address); |
||
| 42 | } |
||
| 43 | |||
| 44 | return $url; |
||
| 45 | } |
||
| 46 | } |
||
| 47 |