diff --git a/calendar-plus.php b/calendar-plus.php index bb9a9ab..0af6925 100755 --- a/calendar-plus.php +++ b/calendar-plus.php @@ -6,7 +6,7 @@ * Plugin Name: Calendar+ (An Accessible Events Calendar) * Plugin URI: https://campuspress.com/accessible-wordpress-calendar-plugin/ * Description: Accessibility-ready complete calendar and events plugin. Import from Google Calendar, subscribe to events, and more. - * Version: 2.2.13 + * Version: 2.2.14.beta1 * Author: CampusPress * Author URI: https://campuspress.com * License: GPL-2.0+ diff --git a/includes/class-calendar-plus-dates-generator.php b/includes/class-calendar-plus-dates-generator.php index 4b81db3..5674e11 100644 --- a/includes/class-calendar-plus-dates-generator.php +++ b/includes/class-calendar-plus-dates-generator.php @@ -281,7 +281,7 @@ public static function delete_old_dates( $delete_from = false ) { // Lets use this opportunity to store the last known total dates $total_old_dates = (int) $wpdb->get_var( "SELECT COUNT(ID) FROM $table" ); - update_option( 'calendarp_last_known_total_dates', $delete_from ); + update_option( 'calendarp_last_known_total_dates', $total_old_dates ); } diff --git a/includes/ical/class-calendar-plus-ical-parser.php b/includes/ical/class-calendar-plus-ical-parser.php index 9fef147..f711da6 100644 --- a/includes/ical/class-calendar-plus-ical-parser.php +++ b/includes/ical/class-calendar-plus-ical-parser.php @@ -145,6 +145,8 @@ public function parse_events() { $content = html_entity_decode( $content ); + $cast_timezone = true; + //dtstart has to be set but, dtend not always. $start_date_tz = $calendar_tz; if ( $_event->dtstart_array ) { @@ -159,10 +161,15 @@ public function parse_events() { // Set start time to begining $_event->dtstart .= 'T'; $_event->all_day = true; + $cast_timezone = false; } } - $from = self::cast_date_timezones( $_event->dtstart, $start_date_tz, $local_tz ); + if ( $_event->all_day && ! $cast_timezone ) { + $from = self::cast_date_without_timezones( $_event->dtstart ); + } else { + $from = self::cast_date_timezones( $_event->dtstart, $start_date_tz, $local_tz ); + } $end_date_tz = $calendar_tz; if( isset( $_event->dtend ) && $_event->dtend ) { @@ -180,7 +187,12 @@ public function parse_events() { } } $end_date_tz = $end_date_tz ?: $calendar_tz; - $to = self::cast_date_timezones( $_event->dtend, $end_date_tz, $local_tz ); + + if ( $_event->all_day && ! $cast_timezone ) { + $to = self::cast_previous_date_without_timezones( $_event->dtend ); + } else { + $to = self::cast_date_timezones( $_event->dtend, $end_date_tz, $local_tz ); + } } else { $to = $from; @@ -533,4 +545,40 @@ private static function cast_date_timezones( $date, $from_tz, $to_tz ) { //Its not easy to get time zone based timestamp. Hack was needed. return strtotime( $date->format( 'Y-m-d H:i:s' ) ); } + + /** + * Transform a date to given format without changing timezones. + * + * @param string $date + * + * @return int New timestamp + */ + private static function cast_date_without_timezones( $date ) { + $date = date_create( $date ); + + if ( ! $date ) { + return ''; + } + + //Its not easy to get time zone based timestamp. Hack was needed. + return strtotime( $date->format( 'Y-m-d H:i:s' ) ); + } + + /** + * Casts a date to previous day without changing timezones. + * + * @param string $date + * + * @return int New timestamp + */ + private static function cast_previous_date_without_timezones( $date ) { + $date = date_create( $date ); + + if ( ! $date ) { + return ''; + } + + //Its not easy to get time zone based timestamp. Hack was needed. + return strtotime( $date->format( 'Y-m-d H:i:s' ) . ' -1 day' ); + } } \ No newline at end of file