Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_beginning_of_week #380

Merged
merged 2 commits into from
Jun 14, 2018
Merged
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
16 changes: 8 additions & 8 deletions modules/calendar/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1276,23 +1276,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 @@ -1314,8 +1314,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