Created
June 22, 2013 10:48
-
-
Save cristianciofu/5840415 to your computer and use it in GitHub Desktop.
Change php's DateTime behavior to use Monday as first day of the week
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
<?php | |
// found it here : | |
// http://stackoverflow.com/questions/13128854/php-datetime-class-change-first-day-of-the-week-to-monday | |
class EuroDateTime extends DateTime { | |
// Override "modify()" | |
public function modify($string) { | |
// Change the modifier string if needed | |
if ( $this->format('N') == 7 ) { // It's Sunday and we're calculating a day using relative weeks | |
$matches = array(); | |
$pattern = '/this week|next week|previous week|last week/i'; | |
if ( preg_match( $pattern, $string, $matches )) { | |
$string = str_replace($matches[0], '-7 days '.$matches[0], $string); | |
} | |
} | |
return parent::modify($string); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I make another day of the week (eg Wednesday) the first day?