From 9ea335ab9c8f9e17e8ce8b6a7e76962bec7ed418 Mon Sep 17 00:00:00 2001
From: horus
Date: Mon, 17 Feb 2020 13:17:18 +0100
Subject: Initial commit.
---
app/Libraries/Zeitumstellung.php | 104 +++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 app/Libraries/Zeitumstellung.php
(limited to 'app/Libraries/Zeitumstellung.php')
diff --git a/app/Libraries/Zeitumstellung.php b/app/Libraries/Zeitumstellung.php
new file mode 100644
index 0000000..17daa08
--- /dev/null
+++ b/app/Libraries/Zeitumstellung.php
@@ -0,0 +1,104 @@
+now = Carbon::now()->startOfDay();
+
+ $this->year = $this->now->year;
+
+ # detect if next time change is next year
+ if ( $this->now->gt( Carbon::parse('last sunday of october')->startOfDay() ) ){
+ $this->year = $this->year+1;
+ }
+
+ $this->tc_march = Carbon::parse('last sunday of march ' . $this->year )->startOfDay();
+ $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)
+
+ $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.';
+
+ # 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 );
+ } else {
+ $this->daysago = $this->tc_oct->diffInDays( $this->now );
+ }
+
+ } else {
+ # next time change is in october this year, (last sunday in october)
+
+ $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->daysago = $this->tc_march->diffInDays( $this->now );
+ }
+
+ $this->dateText = $this->date->toDateString();
+
+ $this->daysuntil = $this->date->diffInDays($this->now);
+
+ $this->day = $this->date->day;
+ $this->month = $this->date->month;
+ $this->year = $this->date->year;
+
+ if ( 3 == $this->month ) {
+ $this->monthText = "März";
+ } else {
+ $this->monthText = "Oktober";
+ }
+ }
+
+ public function getData(){
+ $result = array();
+
+ $result["date"] = $this->date->toDateString();
+ $result["day"] = $this->date->day;
+ $result["month"] = $this->date->month;
+ $result["monthText"] = $this->monthText;
+ $result["year"] = $this->date->year;
+ $result["daysuntil"] = $this->daysuntil;
+ $result["daysago"] = $this->daysago;
+ $result["now"] = $this->now->toDateString();
+
+ return $result;
+ }
+ public function getJSON(){
+ return json_encode( $this->getData() );
+ }
+}
--
cgit v1.2.3