Projects/nettsiden-old
Projects
/
nettsiden-old
Archived
8
0
Fork 0

Merge branch 'master' of github.com:Programvareverkstedet/nettsiden

This commit is contained in:
Karl August Høivik 2016-08-15 20:58:47 +02:00
commit 41f72b647f
5 changed files with 120 additions and 3 deletions

View File

@ -1,12 +1,12 @@
<?php //declare(strict_types=1);
namespace pvv\side;
use \DateTime;
use \DateTimeImmutable;
interface RepeatingActivity extends Activity {
public function getNextEventFrom(DateTime $date) /* : Event */;
public function getNextEventFrom(DateTimeImmutable $date) /* : Event */;
public function getPreviousEventFrom(DateTime $date) /* : Event */;
public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */;
}

View File

@ -0,0 +1,47 @@
<?php //declare(strict_types=1);
namespace pvv\side\social;
use \DateTimeImmutable;
use \DateInterval;
class AnimekveldActivity {
public function nextDate(DateTimeImmutable $date) {
if ($date->format('H') > 20 || $date->format('H') == 19 && $date->format('i') > 30)
return $this->nextDate($date->add(new DateInterval('P1D')));
$date = $date->setTime(19, 30, 0);
if ($date->format('N') != 5)
return $this->nextDate($date->add(new DateInterval('P1D')));
return $date;
}
public function prevDate(DateTimeImmutable $date) {
if ($date->format('H') < 19 || $date->format('H') == 20 && $date->format('i') < 30)
return $this->prevDate($date->sub(new DateInterval('P1D')));
$date = $date->setTime(19, 30, 0);
if ($date->format('N') != 5)
return $this->prevDate($date->sub(new DateInterval('P1D')));
return $date;
}
public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ {
return new AnimekveldEvent($this->nextDate($date));
}
public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ {
return new AnimekveldEvent($this->prevDate($date));
}
public function getName() /* : string */ {
return "Animekveld";
}
public function getLocation() /* : Location */ {
return "Peppes Kjøpmansgata";
}
public function getOrganiser() /* : User */ {
return "Anders Christensen";
}
}

View File

@ -0,0 +1,52 @@
<?php //declare(strict_types=1);
namespace pvv\side\social;
use \pvv\side\RepeatingActivity;
use \DateTimeImmutable;
use \DateInterval;
class NerdepitsaActivity implements RepeatingActivity {
public function nextDate(DateTimeImmutable $date) {
if ($date->format('H') > 19)
return $this->nextDate($date->add(new DateInterval('P1D'))->setTime(19, 0, 0));
$date = $date->setTime(19, 0, 0);
if ($date->format('N') != 5)
return $this->nextDate($date->add(new DateInterval('P1D')));
if ($date->format('W') % 2)
return $this->nextDate($date->add(new DateInterval('P7D')));
return $date;
}
public function prevDate(DateTimeImmutable $date) {
if ($date->format('H') < 19)
return $this->prevDate($date->sub(new DateInterval('P1D'))->setTime(19, 0, 0));
$date = $date->setTime(19, 0, 0);
if ($date->format('N') != 5)
return $this->prevDate($date->sub(new DateInterval('P1D')));
if ($date->format('W') % 2)
return $this->prevDate($date->sub(new DateInterval('P7D')));
return $date;
}
public function getNextEventFrom(DateTimeImmutable $date) /* : Event */ {
return new NerdepitsaEvent($this->nextDate($date));
}
public function getPreviousEventFrom(DateTimeImmutable $date) /* : Event */ {
return new NerdepitsaEvent($this->prevDate($date));
}
public function getName() /* : string */ {
return "Nerdepitsa";
}
public function getLocation() /* : Location */ {
return "Peppes Kjøpmansgata";
}
public function getOrganiser() /* : User */ {
return "Anders Christensen";
}
}

View File

@ -0,0 +1,9 @@
<?php //declare(strict_types=1);
namespace pvv\side\social;
ini_set('date.timezone', 'Europe/Oslo');
require implode(DIRECTORY_SEPARATOR, [dirname(dirname(dirname(__DIR__))), '', '_autoload.php']);
$c = new AnimekveldActivity;
die($c->nextDate(new \DateTimeImmutable)->format(DATE_RFC2822));

View File

@ -0,0 +1,9 @@
<?php //declare(strict_types=1);
namespace pvv\side\social;
ini_set('date.timezone', 'Europe/Oslo');
require implode(DIRECTORY_SEPARATOR, [dirname(dirname(dirname(__DIR__))), '', '_autoload.php']);
$c = new NerdepitsaActivity;
die($c->prevDate(new \DateTimeImmutable)->format(DATE_RFC2822));