+
+ /**
+ * {@inheritdoc}
+ */
+ public function preUpdate(PreUpdateEventArgs $eventArgs) {
+ //Check that we have a session instance
+ if (($session = $eventArgs->getObject()) instanceof Session) {
+ //Set updated value
+ $session->setUpdated(new \DateTime('now'));
+ }
+ }
+
+ /**
+ * Wether if session is a premium day
+ *
+ * Consider as premium a day off for afternoon, the eve for evening and after
+ * Store computed result in premium member for afternoon and evening
+ *
+ * @TODO improve by moving day off computation in IntlUtil or HolidayUtil class ?
+ *
+ * @return bool Whether the date is day off or not
+ */
+ public function isPremium(): bool {
+ //Without date
+ if (empty($date = $this->date)) {
+ throw new \LogicException('Property date is empty');
+ }
+
+ //Without slot
+ if (empty($slot = $this->slot) || empty($slotTitle = $slot->getTitle())) {
+ throw new \LogicException('Property slot is empty');
+ }
+
+ //With evening and after slot
+ if ($slotTitle == 'Evening' || $slotTitle == 'After') {
+ //Evening and after session is considered premium when the eve is a day off
+ $date = (clone $date)->add(new \DateInterval('P1D'));
+ }
+
+ //Get day number
+ $w = $date->format('w');
+
+ //Check if weekend day
+ if ($w == 0 || $w == 6) {
+ //With afternoon and evening slot
+ if ($slotTitle == 'Afternoon' || $slotTitle == 'Evening') {
+ //Save premium
+ $this->premium = true;
+ }
+
+ //Date is weekend day
+ return true;
+ }
+
+ //Get date day
+ $d = $date->format('d');
+
+ //Get date month
+ $m = $date->format('m');
+
+ //Check if fixed holiday
+ if (
+ //Check if 1st january
+ ($d == 1 && $m == 1) ||
+ //Check if 1st may
+ ($d == 1 && $m == 5) ||
+ //Check if 8st may
+ ($d == 8 && $m == 5) ||
+ //Check if 14st july
+ ($d == 14 && $m == 7) ||
+ //Check if 15st august
+ ($d == 15 && $m == 8) ||
+ //Check if 1st november
+ ($d == 1 && $m == 11) ||
+ //Check if 11st november
+ ($d == 11 && $m == 11) ||
+ //Check if 25st december
+ ($d == 25 && $m == 12)
+ ) {
+ //With afternoon and evening slot
+ if ($slotTitle == 'Afternoon' || $slotTitle == 'Evening') {
+ //Save premium
+ $this->premium = true;
+ }
+
+ //Date is a fixed holiday
+ return true;
+ }
+
+ //Get eastern
+ $eastern = (new IntlUtil())->getEastern($date->format('Y'));
+
+ //Check dynamic holidays
+ if (
+ (clone $eastern)->add(new \DateInterval('P1D')) == $date ||
+ (clone $eastern)->add(new \DateInterval('P39D')) == $date ||
+ (clone $eastern)->add(new \DateInterval('P50D')) == $date
+ ) {
+ //With afternoon and evening slot
+ if ($slotTitle == 'Afternoon' || $slotTitle == 'Evening') {
+ //Save premium
+ $this->premium = true;
+ }
+
+ //Date is a dynamic holiday
+ return true;
+ }
+
+ //With afternoon and evening slot
+ if ($slotTitle == 'Afternoon' || $slotTitle == 'Evening') {
+ //Save premium
+ $this->premium = false;
+ }
+
+ //Date is not a holiday and week day
+ return false;
+ }