Skip to content

Instantly share code, notes, and snippets.

@addisonhall
Created November 2, 2015 14:05
Show Gist options
  • Save addisonhall/03741532be500b891fc6 to your computer and use it in GitHub Desktop.
Save addisonhall/03741532be500b891fc6 to your computer and use it in GitHub Desktop.
Added PHP function to deal with DST discrepancy when importing from Google Calendar
{layout="site/.layout_default" body_class="events"}
{preload_replace:pre_channel_name="events"}
{preload_replace:pre_section_title="Events"}
{layout:set name="section_title" value="{pre_section_title}"}
<?php
function adjust_dst($this_date, $this_hour) {
$check_dst = new DateTime($this_date . ' America/Chicago');
$is_dst = $check_dst->format('I');
if ($is_dst == 1) {
if ($this_hour == 12) {
return '1';
} else {
return $this_hour + 1;
}
} else {
return $this_hour;
}
}
?>
<section class="container-fluid">
<header class="row">
<div class="col-md-12 section-hdr {pre_channel_name}-hdr">
<h1>{pre_section_title}</h1>
</div>
</header>
<div class="row">
<!-- TODO: Need for sub-menu? -->
<article class="col-sm-12 page-content">
<header class="hidden">
<h1>
Calendar of Events
</h1>
</header>
<div class="text-center append-btm">
<ul class="list-inline">
<li>Download:</li>
{exp:low_variables:pair var="lv_calendar_downloads"}
<li><a href="{url}">{title}</a></li>
{/exp:low_variables:pair}
</ul>
</div>
<div id="fc_calendar" class="calendar calendar-full hidden-xs">
{exp:calendar:cal
{if segment_3 == ''}
date_range_start="year-month-01"
date_range_end="year-month-last"
{/if}
{if segment_3 != ""}
date_range_start="{segment_3}-{segment_4}-01"
date_range_end="{segment_3}-{segment_4}-last"
{/if}
}
{display_each_month}
<table id="fc_outer" class="calendar-outer">
<thead class="calendar-month">
<tr id="month_year">
<th colspan="2">&laquo;
<a href="{path='events/month'}/{prev_month format='%Y/%m'}/">
{prev_month format="%F"}
</a>
</th>
<th colspan="3" class="text-center">{date format="%F %Y"}</th>
<th colspan="2" class="text-right">
<a href="{path='events/month'}/{next_month format='%Y/%m'}/">
{next_month format="%F"}
</a>
&raquo;
</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="7">
<div class="wrap">
<table id="fc_inner" class="calendar-inner">
<thead class="calendar-week-days">
<tr id="days_of_week">
{display_each_day_of_week}
<th class="day_of_week {day_of_week}">
{day_of_week}
</th>
{/display_each_day_of_week}
</tr>
</thead>
<tbody>
{display_each_week}
<tr>
{display_each_day}
{if day_in_current_month}
<td class="day_cell">
<div class="date">
<span class="num">
{date format="%j"}
</span>
</div>
{if:else}
<td class="day_cell out_of_range">
<div class="date">
<span class="num">
{date format="%j"}
</span>
</div>
{/if}
{display_each_hour}
{events}
<div
class="
event {if event_all_day}all_day{/if}
{if event_multi_day}multi_day{/if}
{if event_first_day}first_day{/if}
{if event_last_day}last_day{/if}
{if all_day_event_index_difference > 0}
index_difference_{all_day_event_index_difference}
{/if}
">
{if event_multi_day}
{if event_all_day == FALSE}
{if event_first_day}
{event_start_time}
{/if}
{if event_last_day}
{event_end_time}
{/if}
{/if}
<a href="#" data-toggle="modal" data-target="#event-{event_id}">{event_title}</a>
{if:else}
{if event_all_day == ''}
{!--{event_start_date format="%g"}--}
<?php echo adjust_dst({event_start_date}, {event_start_date format="%g"}); ?>
{if event_start_minute > 0}
:{event_start_minute}
{/if}
{if event_end_time != event_start_time && event_end_time != '00:00'}
&ndash;
{!--{event_end_date format="%g"}--}
<?php echo adjust_dst({event_end_date}, {event_end_date format="%g"}); ?>
{if event_end_minute > 0}
:{event_end_minute}
{/if}
{event_end_date format="%a"}
{if:else}
{event_start_date format="%a"}
{/if}
{/if}
<a href="#" data-toggle="modal" data-target="#event-{event_id}">{event_title}</a>
{/if}
<div id="event-{event_id}" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="event-title-{event_id}" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="event">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="event-title-{event_id}">{event_title}</h4>
</div>
<div class="modal-body">
<ul class="list-unstyled">
{if event_summary}
<li><strong>Details:</strong> {event_summary}</li>
{if:else}
<li>
<strong>When:</strong>
{if event_all_day}
All day
{if:else}
<?php echo adjust_dst({event_start_date}, {event_start_date format="%g"}); ?>{event_start_date format=":%i%a"}
{/if}
</li>
{/if}
{if event_location}<li><strong>Where:</strong> {event_location}</li>{/if}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
{/events}
{/display_each_hour}
</td>
{/display_each_day}
</tr>
{/display_each_week}
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
{/display_each_month}
{/exp:calendar:cal}
</div>
<div class="calendar calendar-list visible-xs">
<ul class="list-unstyled">
{exp:calendar:events orderby="title" orderby="event_start_date" sort="asc" date_range_start="today" event_limit="100" show_months="3" dynamic="no"}
{if calendar_no_results}
<li>No Results</li>
{/if}
<li data-tz-offset="{event_calendar_tz_offset}">
<a href="#" data-toggle="modal" data-target="#event-list-{event_id}">
<h3 class="title normal-case"><span class="event-date-lead">{event_start_date format="%F %j, %Y"}:</span> {event_title}</h3>
<!--<p>{event_start_date format="%F %j, %Y"}</p>-->
</a>
<div id="event-list-{event_id}" class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="event-list-title-{event_id}" aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="event">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="event-list-title-{event_id}">{event_title}</h4>
</div>
<div class="modal-body">
<ul class="list-unstyled">
{if event_summary}
<li><strong>Details:</strong> {event_summary}</li>
{if:else}
<li>
<strong>When:</strong>
{if event_all_day}
All day
{if:else}
<?php echo adjust_dst({event_start_date}, {event_start_date format="%g"}); ?>{event_start_date format=":%i%a"}
{/if}
</li>
{/if}
{if event_location}<li><strong>Where:</strong> {event_location}</li>{/if}
</ul>
</div>
</div>
</div>
</div>
</div>
</li>
{/exp:calendar:events}
</ul>
</div>
</article>
</div>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment