diff options
Diffstat (limited to 'app/Libraries')
| -rw-r--r-- | app/Libraries/.Zeitumstellung.php.swp | bin | 12288 -> 0 bytes | |||
| -rw-r--r-- | app/Libraries/Zeitumstellung.php | 26 |
2 files changed, 19 insertions, 7 deletions
diff --git a/app/Libraries/.Zeitumstellung.php.swp b/app/Libraries/.Zeitumstellung.php.swp Binary files differdeleted file mode 100644 index 5eacf1c..0000000 --- a/app/Libraries/.Zeitumstellung.php.swp +++ /dev/null diff --git a/app/Libraries/Zeitumstellung.php b/app/Libraries/Zeitumstellung.php index 17daa08..42b8415 100644 --- a/app/Libraries/Zeitumstellung.php +++ b/app/Libraries/Zeitumstellung.php @@ -27,12 +27,16 @@ class Zeitumstellung { private $tc_march; private $tc_oct; - function __construct() { + function __construct($setNow = null) { # debug #Carbon::setTestNow( Carbon::create(2018, 10, 28, 2) ); #Carbon::setTestNow( Carbon::create(2020, 03, 30, 5) ); - $this->now = Carbon::now()->startOfDay(); + if ( is_null($setNow) ) { + $this->now = Carbon::now()->startOfDay(); + } else { + $this->now = $setNow; + } $this->year = $this->now->year; @@ -45,16 +49,17 @@ class Zeitumstellung { $this->tc_oct = Carbon::parse('last sunday of october ' . $this->year)->startOfDay(); if ( $this->now->lte($this->tc_march) ){ - # next time change is in march this year, (last sunday in october) + # next time change is in march this year, (last sunday in march) $this->date = $this->tc_march; $this->description = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir 1 Stunde weniger schlafen.'; - $this->descriptionHTML = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir <b>1 Stunde weniger</b> schlafen.'; + $this->descriptionHTML = 'Die Uhr wird von <b>2 Uhr auf 3 Uhr vorgestellt</b>, sodass wir <b>1 Stunde weniger</b> schlafen.'; # detect if last time change was last year if ( $this->now->lt( Carbon::parse('last sunday of march ') ) ) { - $this->year = $this->now->year - 1; - $this->daysago = Carbon::parse('last sunday of october' . $this->year)->diffInDays( $this->now ); + #$this->year = $this->now->year - 1; + $year = $this->now->year - 1; + $this->daysago = Carbon::parse('last sunday of october' . $year)->diffInDays( $this->now ); } else { $this->daysago = $this->tc_oct->diffInDays( $this->now ); } @@ -64,7 +69,7 @@ class Zeitumstellung { $this->date = $this->tc_oct; $this->description = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir 1 Stunde länger schlafen.'; - $this->descriptionHTML = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir <b>1 Stunde länger</b> schlafen.'; + $this->descriptionHTML = 'Die Uhr wird von <b>3 Uhr auf 2 Uhr zurückgestellt</b>, sodass wir <b>1 Stunde länger</b> schlafen.'; $this->daysago = $this->tc_march->diffInDays( $this->now ); } @@ -84,6 +89,13 @@ class Zeitumstellung { } } + /** + * Returns an instance of the object with the next time change after the current one. + */ + function next(){ + return new Zeitumstellung( $this->date->add(1, 'day') ); + } + public function getData(){ $result = array(); |
