Last active
December 11, 2015 18:19
-
-
Save brianfeister/4640642 to your computer and use it in GitHub Desktop.
Function for custom display of Timely All-in-One-Calendar long date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ======================================================================================== | |
* | |
* function for custom date range display of Timely ai1ec events | |
* | |
* @param $event - you must pass Timely's $event object to this function | |
* @param $date_format - pass a PHP valid date format for Month & Day (not year!) | |
* @param $time_format - pass a PHP valid time format, pass FALSE to omit time from output | |
* @param $echo - defaults to true, in order to return pass FALSE for $echo parameter | |
* ======================================================================================== */ | |
if ( in_array( 'all-in-one-event-calendar/all-in-one-event-calendar.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
function timely_event_long_date( | |
$event = '', | |
$date_format = 'M d', | |
$time_format = 'g:i a', | |
$echo = true | |
){ | |
global $post, | |
$ai1ec_calendar_helper, | |
$ai1ec_events_helper; | |
if ( empty($event) ) : | |
if($echo): echo 'Date parameter is undefined.'; else: return 'Date parameter is undefined.'; endif; | |
exit; | |
endif; | |
$start = date( $ai1ec_events_helper->gmt_to_local( $event->start ) ); | |
$start_month = date( 'm', $start ); | |
$start_day = date( 'd', $start ); | |
$start_year = date( 'Y', $start ); | |
$start_hour = date( 'G', $start ); | |
$start_min = date( 'i', $start ); | |
$end = date( $ai1ec_events_helper->gmt_to_local( $event->end ) ); | |
$end_month = date( 'm', $end ); | |
$end_day = date( 'd', $end ); | |
$end_year = date( 'Y', $end ); | |
$end_hour = date( 'G', $end ); | |
$end_min = date( 'i', $end); | |
// error_log(print_r($event,true)); | |
if ( $time_format != false ): | |
if( $start_hour == $end_hour && $start_min == $end_min ): | |
$time = ' | ' . date( $time_format, $start ); | |
else: | |
$time = ' | ' . date( $time_format, $start ) . ' - ' . date( $time_format, $end ); | |
endif; | |
endif; | |
if($start <= $end): | |
if($start == $end): | |
//Month Day, Year | |
$date = date( $date_format . ', Y ', $start) . $time; | |
else: | |
if($start_year == $end_year): | |
if($start_month == $end_month): | |
if($start_day == $end_day): | |
//Month Day - Day, Year | |
$date = date( $date_format . ', Y', $start ) . $time; | |
else: | |
//Month Day - Day, Year | |
$date = date( $date_format, $start ). ' - ' . date( 'j, Y', $end ) . $time; | |
endif; | |
else: | |
//Month Day - Month Day, Year | |
$date = date( $date_format, $start ) . ' - ' . date( $date_format ,$end ) . ', ' . date( 'Y', $end ) . $time; | |
endif; | |
else: | |
//Month Day, Year - Month Day, Year | |
$date = date( $date_format . ', Y', $start ) . ' - ' . date( $date_format . ', Y', $end ) . $time; | |
endif; | |
endif; | |
endif; | |
// Add all-day label. | |
if ( $event->allday ) { | |
$date .= | |
' <span class="ai1ec-allday-badge">' . | |
__( 'all-day', AI1EC_PLUGIN_NAME ) . | |
'</span>'; | |
} | |
if($echo): echo $date; else: return $date; endif; | |
} | |
} // end wrapper to check if all-in-one-event-calendar is active | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment