Last active
December 17, 2018 21:04
-
-
Save dnavarrojr/a9384db4c211d044247ed3f2eb1f6a00 to your computer and use it in GitHub Desktop.
Recurring Weekly Array
This file contains 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 tscpl_recurring_weekly( $start_date, $dow, $count ) { | |
$days = array( | |
'sunday' => 0, | |
'monday' => 1, | |
'tuesday' => 2, | |
'wednesday' => 3, | |
'thursday' => 4, | |
'friday' => 5, | |
'saturday' => 6 | |
); | |
$start_date = date( 'Y-m-d', strtotime( $start_date ) ); | |
$start_dow = (int) date( 'w', strtotime( $start_date ) ); | |
if ( gettype( $dow ) == 'string' ) | |
$dow = $days[ strtolower( $dow ) ]; | |
// does our start date equal the DOW? | |
if ( $start_dow < $dow ) { | |
$start_date = date( 'Y-m-d', strtotime( $start_date . ' +' . ($dow - $start_dow) . ' days' ) ); | |
} elseif ( $start_dow > $dow ) { | |
$start_date = date( 'Y-m-d', strtotime( $start_date . ' +' . (7 - ( $start_dow - $dow ) ) . ' days' ) ); | |
} | |
$i = 0; | |
$dates = array(); | |
while ( $i < $count ) { | |
$dates[] = date( 'Y-m-d', strtotime( $start_date . ' +' . $i . ' weeks' ) ); | |
$i++; | |
} | |
return $dates; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment