diff options
| author | horus | 2020-02-20 15:35:53 +0100 |
|---|---|---|
| committer | horus | 2020-02-20 15:35:53 +0100 |
| commit | 0edb438872796902d3e4d3c2eea791f6af1956aa (patch) | |
| tree | 849dca17ee23b25ec81808d1c981afc64e8ca33b /app | |
| parent | 9ea335ab9c8f9e17e8ce8b6a7e76962bec7ed418 (diff) | |
| download | zeitumstellung-0edb438872796902d3e4d3c2eea791f6af1956aa.tar.gz | |
Supports iCal-Feed and styled website with bootstrap.css.
Diffstat (limited to 'app')
| -rw-r--r-- | app/Http/Controllers/HomeController.php | 28 | ||||
| -rw-r--r-- | app/Http/Controllers/iCalController.php | 34 | ||||
| -rw-r--r-- | app/Http/Middleware/TrustProxies.php | 2 | ||||
| -rw-r--r-- | app/Libraries/.Zeitumstellung.php.swp | bin | 12288 -> 0 bytes | |||
| -rw-r--r-- | app/Libraries/Zeitumstellung.php | 26 |
5 files changed, 70 insertions, 20 deletions
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php new file mode 100644 index 0000000..7cbc2c3 --- /dev/null +++ b/app/Http/Controllers/HomeController.php @@ -0,0 +1,28 @@ +<?php + +namespace App\Http\Controllers; + +use Illuminate\Http\Request; + +class HomeController extends Controller +{ + /** + * Create a new controller instance. + * + * @return void + */ + public function __construct() + { + $this->middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Contracts\Support\Renderable + */ + public function index() + { + return view('home'); + } +} diff --git a/app/Http/Controllers/iCalController.php b/app/Http/Controllers/iCalController.php index 928976e..f41f322 100644 --- a/app/Http/Controllers/iCalController.php +++ b/app/Http/Controllers/iCalController.php @@ -15,25 +15,31 @@ class iCalController extends Controller { * * @return Response */ - public function showPage(Request $request) { + public function icalFeed(Request $request) { - $tc = new Zeitumstellung(); - $data = $tc->getData(); $vCalendar = new Calendar('zeitumstellung.iamfabulous.de'); $vCalendar->setName('Zeitumstellung'); $vCalendar->setTimezone('Europe/Berlin'); - $vEvent = new Event(); - $vEvent - ->setDtStart(new \DateTime($tc->dateText)) - ->setDtEnd(new \DateTime($tc->dateText)) - ->setNoTime(true) - ->setSummary('Zeitumstellung') - ->setDescription($tc->description) - ->setDescriptionHTML($tc->descriptionHTML); + $tc = new Zeitumstellung(); + + for ( $i= 0; $i<3; $i++ ) { + + $vEvent = new Event(); + $vEvent + ->setDtStart(new \DateTime($tc->dateText)) + ->setDtEnd(new \DateTime($tc->dateText)) + ->setNoTime(true) + ->setSummary('Zeitumstellung') + ->setUrl( env("APP_URL") ) + ->setDescription($tc->description) + ->setDescriptionHTML($tc->descriptionHTML); - $vCalendar->addComponent($vEvent); + $vCalendar->addComponent($vEvent); + + $tc = $tc->next(); + } header('Content-Type: text/calendar; charset=utf-8'); @@ -43,4 +49,8 @@ class iCalController extends Controller { echo $vCalendar->render(); } + + public function showPage(Request $request) { + return view('index'); + } } diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index ee5b595..3625f37 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -12,7 +12,7 @@ class TrustProxies extends Middleware * * @var array|string */ - protected $proxies; + protected $proxies = [ '192.168.122.1' ]; /** * The headers that should be used to detect proxies. 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(); |
