From 0edb438872796902d3e4d3c2eea791f6af1956aa Mon Sep 17 00:00:00 2001
From: horus
Date: Thu, 20 Feb 2020 15:35:53 +0100
Subject: Supports iCal-Feed and styled website with bootstrap.css.
---
app/Libraries/Zeitumstellung.php | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
(limited to 'app/Libraries/Zeitumstellung.php')
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 1 Stunde weniger schlafen.';
+ $this->descriptionHTML = 'Die Uhr wird von 2 Uhr auf 3 Uhr vorgestellt, sodass wir 1 Stunde weniger 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 1 Stunde länger schlafen.';
+ $this->descriptionHTML = 'Die Uhr wird von 3 Uhr auf 2 Uhr zurückgestellt, sodass wir 1 Stunde länger 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();
--
cgit v1.2.3