Skip to content

Commit

Permalink
Merge pull request #380 from FewKinG/master
Browse files Browse the repository at this point in the history
Fix get_beginning_of_week
  • Loading branch information
rinatkhaziev authored Jun 14, 2018
2 parents aab8337 + 1c2d85a commit 31c2903
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1310,23 +1310,23 @@ function get_pagination_link( $direction = 'next', $filters = array(), $weeks_of

/**
* Given a day in string format, returns the day at the beginning of that week, which can be the given date.
* The end of the week is determined by the blog option, 'start_of_week'.
* The beginning of the week is determined by the blog option, 'start_of_week'.
*
* @see http://www.php.net/manual/en/datetime.formats.date.php for valid date formats
*
* @param string $date String representing a date
* @param string $format Date format in which the end of the week should be returned
* @param string $format Date format in which the beginning of the week should be returned
* @param int $week Number of weeks we're offsetting the range
* @return string $formatted_start_of_week End of the week
* @return string $formatted_start_of_week Beginning of the week
*/
function get_beginning_of_week( $date, $format = 'Y-m-d', $week = 1 ) {

$date = strtotime( $date );
$start_of_week = get_option( 'start_of_week' );
$day_of_week = date( 'w', $date );
$date += (( $start_of_week - $day_of_week - 7 ) % 7) * 60 * 60 * 24 * $week;
$additional = 3600 * 24 * 7 * ( $week - 1 );
$formatted_start_of_week = date( $format, $date + $additional );
$date += (( $start_of_week - $day_of_week - 7 ) % 7) * 60 * 60 * 24 ;
$date = strtotime ( '+' . ( $week - 1 ) . ' week', $date ) ;
$formatted_start_of_week = date( $format, $date );
return $formatted_start_of_week;

}
Expand All @@ -1348,8 +1348,8 @@ function get_ending_of_week( $date, $format = 'Y-m-d', $week = 1 ) {
$end_of_week = get_option( 'start_of_week' ) - 1;
$day_of_week = date( 'w', $date );
$date += (( $end_of_week - $day_of_week + 7 ) % 7) * 60 * 60 * 24;
$additional = 3600 * 24 * 7 * ( $week - 1 );
$formatted_end_of_week = date( $format, $date + $additional );
$date = strtotime ( '+' . ( $week - 1 ) . ' week', $date ) ;
$formatted_end_of_week = date( $format, $date );
return $formatted_end_of_week;

}
Expand Down

0 comments on commit 31c2903

Please sign in to comment.