Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion calendar-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down
2 changes: 1 addition & 1 deletion includes/class-calendar-plus-dates-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


Expand Down
52 changes: 50 additions & 2 deletions includes/ical/class-calendar-plus-ical-parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 ) {
Expand All @@ -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;
Expand Down Expand Up @@ -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' );
}
}