Skip to content

Commit

Permalink
fix: Rolling with our own date methods, since the built in didn't do …
Browse files Browse the repository at this point in the history
…what I expected
  • Loading branch information
itssimple committed Jul 15, 2020
1 parent 7d2c6b3 commit e57e2dc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion PLUGIN-CHECKSUM
Original file line number Diff line number Diff line change
@@ -1 +1 @@
56042f67280b837a420c8738b02de8dd
98ec109486d56a32a65d336104134223
8 changes: 6 additions & 2 deletions content/template/detailTemplate/blocks/event-item.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
<div data-groupid="eduev<?php echo( $group_by_city ? '-' . esc_attr( $ev['City'] ) : '' ); ?>" class="eventItem<?php echo( $show_more > 0 && $i >= $show_more ? ' showMoreHidden' : '' ); ?>">
<div class="eventDate<?php echo esc_attr( $group_by_city_class ); ?>">
<?php
echo isset( $event_dates[ $ev['EventId'] ] ) ? get_logical_date_groups( $event_dates[ $ev['EventId'] ] ) : wp_kses_post( get_old_start_end_display_date( $ev['StartDate'], $ev['EndDate'] ) );
echo ! isset( $event_dates[ $ev['EventId'] ] ) || 1 === count( $event_dates[ $ev['EventId'] ] ) ? '<span class="eventTime">, ' . esc_html( edu_get_timezoned_date( 'H:i', $ev['StartDate'] ) ) . ' - ' . esc_html( edu_get_timezoned_date( 'H:i', $ev['EndDate'] ) ) . '</span>' : '';
echo isset( $event_dates[ $ev['EventId'] ] ) ?
get_logical_date_groups( $event_dates[ $ev['EventId'] ] ) :
wp_kses_post( get_old_start_end_display_date( $ev['StartDate'], $ev['EndDate'] ) );
echo ! isset( $event_dates[ $ev['EventId'] ] ) || 1 === count( $event_dates[ $ev['EventId'] ] ) ?
'<span class="eventTime">, ' . esc_html( edu_get_timezoned_date( 'H:i', $ev['StartDate'] ) ) . ' - ' . esc_html( edu_get_timezoned_date( 'H:i', $ev['EndDate'] ) ) . '</span>' :
'';
?>
</div>
<?php if ( ! $group_by_city ) { ?>
Expand Down
50 changes: 48 additions & 2 deletions includes/edu-text-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,53 @@ function convert_to_money( $value, $currency = 'SEK', $decimal = ',', $thousand
return $d;
}

function edu_get_timezoned_date( $dateformat, $input_date ) {
function edu_timezone_shim() {
$offset = (float) get_option( 'gmt_offset' );
$hours = (int) $offset;
$minutes = ( $offset - $hours );

$sign = ( $offset < 0 ) ? '-' : '+';
$abs_hour = abs( $hours );
$abs_mins = abs( $minutes * 60 );

return sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
}

function edu_now_date() {
$timezone_string = get_option( 'timezone_string' );
if ( $timezone_string ) {
date_default_timezone_set( $timezone_string );
}
$offset = (float) get_option( 'gmt_offset' );
$timestamp = time() + $offset;

return date( "Y-m-d\TH:i:s", $timestamp ) . edu_timezone_shim();
}

function edu_get_timezoned_date( $dateformat, $input_date = null ) {
$orig_input = $input_date;
if ( $input_date == null || $input_date == "" ) {
$input_date = edu_now_date();
}

if ( stripos( $input_date, "now" ) !== false ) {
if ( $input_date === "now" ) {
$offset = (float) get_option( 'gmt_offset' );
$input_date = "now " . date( "H:i:s", strtotime( "now" ) + $offset );
}
$input_date = date( "c", strtotime( substr( edu_now_date(), 0, 10 ) . " " . substr( $input_date, 4 ) ) );
}

/*echo "<!-- " . print_r( [
$dateformat,
$orig_input,
$input_date,
get_date_from_gmt( $input_date, $dateformat ),
edu_timezone_shim(),
date( "Z" ),
debug_backtrace()[1]['function'],
], true ) . "-->\n";*/

return get_date_from_gmt( $input_date, $dateformat );
}

Expand Down Expand Up @@ -580,7 +626,7 @@ function get_start_end_display_date( $start_date, $end_date, $short = false, $ev
$end_month = edu_get_timezoned_date( 'n', $end_date['EndDate'] );
$now_year = edu_get_timezoned_date( 'Y' );

$str = '<span class="eduadmin-dateText" data-startdate="' . esc_attr( $start_date ) . '" data-enddate="' . esc_attr( $end_date ) . '">';
$str = '<span class="eduadmin-dateText" data-startdate="' . esc_attr( $start_date['StartDate'] ) . '" data-enddate="' . esc_attr( $end_date['EndDate'] ) . '">';

if ( $show_days ) {
$str .= $week_days[ edu_get_timezoned_date( 'N', $start_date['StartDate'] ) ] . ' ';
Expand Down

0 comments on commit e57e2dc

Please sign in to comment.