Skip to content

Commit daf319a

Browse files
jmdoddgeorgestephanis
authored andcommitted
iCalendar Reader: Resolve inconsistent use of unixtime and $current
Adds the filter `ical_get_current_time` to the initial call to `time()` to allow unit tests to run from a set unixtime. Updates `date()` and `time()` functions running with the default timestamp `time()` to include this value as the second parameter, ensuring that the entirety of `filter_past_and_recurring_events()` runs from the same value for `$current`. Merges r112068-wpcom.
1 parent 6bfeb4c commit daf319a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

_inc/lib/icalendar-reader.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function get_events( $url = '', $count = 5 ) {
8787
protected function filter_past_and_recurring_events( $events ) {
8888
$upcoming = array();
8989
$set_recurring_events = array();
90-
$current = time();
90+
$current = apply_filters( 'ical_get_current_time', time() );
9191

9292
foreach ( $events as $event ) {
9393

@@ -140,7 +140,7 @@ protected function filter_past_and_recurring_events( $events ) {
140140
}
141141
} else {
142142
$echo_limit = 10;
143-
$current_date = date( 'Ymd' );
143+
$current_date = date( 'Ymd', $current );
144144
if ( 8 == strlen( $event['DTSTART'] ) ) {
145145
$recurring_event_date_start = $current_date;
146146
$recurring_event_date_end = $current_date;
@@ -164,7 +164,7 @@ protected function filter_past_and_recurring_events( $events ) {
164164
}
165165
} else {
166166
$echo_limit = 3;
167-
$current_date = date( 'Ym' );
167+
$current_date = date( 'Ym', $current );
168168
if ( 8 == strlen( $event['DTSTART'] ) ) {
169169
$recurring_event_date_start = date( "d", strtotime( $event['DTSTART'] ) );
170170
$recurring_event_date_end = date( "d", strtotime( $event['DTEND'] ) );
@@ -192,7 +192,7 @@ protected function filter_past_and_recurring_events( $events ) {
192192
}
193193
} else {
194194
$echo_limit = 2;
195-
$current_date = date( 'Ym' );
195+
$current_date = date( 'Ym', $current );
196196
if ( 8 == strlen( $event['DTSTART'] ) ) {
197197
$recurring_event_date_start = date( "d", strtotime( $event['DTSTART'] ) );
198198
$recurring_event_date_end = date( "d", strtotime( $event['DTEND'] ) );
@@ -216,7 +216,7 @@ protected function filter_past_and_recurring_events( $events ) {
216216
}
217217
} else {
218218
$echo_limit = 1;
219-
$current_date = date( 'Y' );
219+
$current_date = date( 'Y', $current );
220220
if ( 8 == strlen( $event['DTSTART'] ) ) {
221221
$recurring_event_date_start = date( "md", strtotime( $event['DTSTART'] ) );
222222
$recurring_event_date_end = date( "md", strtotime( $event['DTEND'] ) );
@@ -254,7 +254,7 @@ protected function filter_past_and_recurring_events( $events ) {
254254
}
255255
$event_start = strtotime( $recurring_event_date_start );
256256
$event_end = strtotime( $recurring_event_date_end );
257-
$until = ( isset( $rrule_array['UNTIL'] ) ) ? strtotime( $rrule_array['UNTIL'] ) : strtotime( '+1 year' );
257+
$until = ( isset( $rrule_array['UNTIL'] ) ) ? strtotime( $rrule_array['UNTIL'] ) : strtotime( '+1 year', $current );
258258
$exdate = ( isset( $event['EXDATE;VALUE=DATE'] ) ) ? $event['EXDATE;VALUE=DATE'] : null;
259259

260260
if ( isset( $rrule_array['BYDAY'] ) && $frequency === 'week' ) {

0 commit comments

Comments
 (0)