/** * Determine if given date matches Capricorn * * Since Capricorn extends over two different * years we need some special logic * * @param Carbon $date * @return boolean */ public function match(Carbon $date) { $start1 = Carbon::create($date->year, $this->start['month'], $this->start['day'], 0, 0, 0); $end1 = Carbon::create($date->year, 12, 31, 0, 0, 0)->addDay(); $start2 = Carbon::create($date->year, 1, 1, 0, 0, 0); $end2 = Carbon::create($date->year, $this->end['month'], $this->end['day'], 0, 0, 0)->addDay(); return $date->between($start1, $end1) || $date->between($start2, $end2); }
/** * @param Request $request * @param $id * @param $code * * @return array|RedirectResponse * @Template() */ public function checkinAction(Request $request, $id, $code) { /* @var $ticket Ticket */ $ticket = $this->ticketRepo->getTicketByIdAndCode($id, $code)->getOrThrow(new NotFoundHttpException('Unknown ticket.')); // Do not allow double checkins if ($ticket->isCheckedIn()) { throw new BadRequestException('Already checked in!'); } // Do not allow checkins on the wrong day /* @var $event Event */ $event = $this->eventRepo->getNextEvent()->getOrThrow(new AccesDeniedHttpException('No event.')); $now = new Carbon(); $start = Carbon::createFromTimestamp($event->getStart()->getTimestamp()); $start->setTime(0, 0, 0); if ($ticket->isSunday()) { $start->modify('+1day'); } $end = clone $start; $end->setTime(23, 59, 59); if (!$now->between($start, $end)) { throw new BadRequestException('Wrong day!'); } // Record checkin $command = new CheckinCommand(); $command->ticket = $ticket; $this->commandBus->handle($command); return array('ticket' => $ticket); }
public function funkySinceDate() { $date = new Carbon($this->customer_since); if ($date->gt(Carbon::create(2009))) { return $date->year; } elseif ($date->between(Carbon::create(2000), Carbon::create(2009))) { return 'Oh-' . $date->year % 10; } elseif ($date->between(Carbon::create(1990), Carbon::create(1999))) { return 'ninety-' . $date->year % 10; } elseif ($date->between(Carbon::create(1980), Carbon::create(1989))) { return 'eighty-' . $date->year % 10; } elseif ($date->between(Carbon::create(1970), Carbon::create(1979))) { return 'UNIX-' . $date->year % 10; } else { return 'forever'; } }
/** * Check if rule matches a period * * @param RedirectRule $rule * @return bool */ private function matchesPeriod(RedirectRule $rule) { if ($rule->getFromDate() instanceof Carbon && $rule->getToDate() instanceof Carbon) { return $this->matchDate->between($rule->getFromDate(), $rule->getToDate()); } if ($rule->getFromDate() instanceof Carbon && $rule->getToDate() === null) { return $this->matchDate->gte($rule->getFromDate()); } if ($rule->getFromDate() === null && $rule->getToDate() instanceof Carbon) { return $this->matchDate->lte($rule->getToDate()); } return true; }
public function available() { date_default_timezone_set("America/Chicago"); $dbstart = DB::table('config')->where('name', '=', 'competition_start')->first(); $dbend = DB::table('config')->where('name', '=', 'competition_end')->first(); $startclear = 0; $endclear = 0; // If both are null if ($dbstart->val_datetime == '0000-00-00 00:00:00') { $startclear = 1; } if ($dbend->val_datetime == '0000-00-00 00:00:00') { $endclear = 1; } if ($startclear == 1 & $endclear == 1) { return 1; } // If both are valid dates, see if we're valid if ($startclear == 0 && $endclear == 0) { $cstart = new Carbon($dbstart->val_datetime); $cend = new Carbon($dbend->val_datetime); $now = new Carbon(); if ($now->between($cstart, $cend)) { return 1; } else { // Now we check if it's before or after the competition $msg = ""; if ($cend->lte(Carbon::now())) { $msg = "The competition ended at " . $dbend->val_datetime; } else { $msg = "The competition does not start until " . $dbstart->val_datetime; } return $msg; } } if ($endclear == 0) { $cend = new Carbon($dbend->val_datetime); if ($cend->gte(Carbon::now())) { return 1; } return "The competition is over."; } if ($startclear == 0) { $cstart = new Carbon($dbstart->val_datetime); if ($cstart->lte(Carbon::now())) { return 1; } return "The competition does not start until " . $cstart; } }
/** * Get the FY end date * * @param Carbon $dt Date to determine FY for * * @return Carbon Carbon instance set to the end of the FY for the input */ public function get(Carbon $dt = NULL) { if (!$dt) { $dt = new Carbon(); } /* Disregard times */ $dt->setTime(0, 0, 0); /* FY is based on the -end- of the FY, thus we will work backward to determine if we need to 'rollup' the FY from the input year */ $fyStart = Carbon::create($dt->year, $this->month, $this->day, 0, 0, 0); $fyEnd = clone $fyStart; $fyEnd->addYear()->subDay(); if (!$dt->between($fyStart, $fyEnd, TRUE)) { $fyEnd->year($dt->year); } return $fyEnd; }
/** * List unprinted tickets. */ public function queueAction() { /* @var $event Event */ $event = $this->eventRepo->getNextEvent()->getOrThrow(new AccesDeniedHttpException('No event.')); // Do not allow checkins on the wrong day $now = new Carbon(); $start = Carbon::createFromTimestamp($event->getStart()->getTimestamp()); $day = $start->setTime(0, 0, 0); $end = clone $start; $end->setTime(23, 59, 59); $day = $now->between($start, $end) ? Ticket::DAY_SATURDAY : Ticket::DAY_SUNDAY; $items = array(); foreach ($this->ticketRepo->getUnprintedTickets($event, $day) as $ticket) { $registration = $this->registrationRepo->getRegistrationForEmail($event, $ticket->getEmail())->get(); $type = null; $items[] = array('@context' => 'http://barcamp-rheinmain.de/jsonld/Ticket', '@subject' => $this->schemeAndHost . $this->router->generate('bcrmprint_ticket', array('id' => $ticket->getId(), 'code' => $ticket->getCode())), 'name' => $ticket->getName(), 'twitter' => $registration->getTwitter(), 'code' => $ticket->getCode(), 'day' => $ticket->getDay(), 'tags' => $registration->getTags()); } $data = array('items' => $items); $response = new Response(json_encode($data)); $response->setCharset('utf-8'); $response->headers->set('Content-Type', 'application/json'); return $response; }
public function checkPurchasability(Carbon $now = null) { $this->checkForQuantity(); if (!is_null($this->purchasable) && !$this->purchasable) { throw new NotForSaleException($this->getDesignation(), 2); } if (!is_null($this->min_purch_quantity) && $this->quantity < $this->min_purch_quantity) { throw new PurchaseQuantityException($this->getDesignation(), $this->min_purch_quantity, 1); } if (!is_null($this->max_purch_quantity) && $this->quantity > $this->max_purch_quantity) { throw new PurchaseQuantityException($this->getDesignation(), $this->max_purch_quantity, 2); } if (is_null($now)) { $now = new Carbon('now'); } if (!is_null($this->start_time) & !is_null($this->end_time)) { if (!$now->between($this->start_time, $this->end_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $this->start_time, $this->end_time, 1); } } else { if (!is_null($this->start_time) & is_null($this->end_time)) { if ($now->lt($this->start_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $this->start_time, null, 2); } } else { if (is_null($this->start_time) & !is_null($this->end_time)) { if ($now->gt($this->end_time)) { throw new OutsideSaleTimeException($this->getDesignation(), $now, $this->end_time, 3); } } } } if ($this->isSoldOut()) { throw new NotForSaleException($this->getDesignation(), 1); } return true; }
/** * Determine if given date matches the current zodiac sign * * @param Carbon $date * @return bool */ public function match(Carbon $date) { $start = Carbon::create($date->year, $this->start['month'], $this->start['day'], 0, 0, 0); $end = Carbon::create($date->year, $this->end['month'], $this->end['day'], 0, 0, 0)->addDay(); return $date->between($start, $end); }
/** * @param Carbon $start * @param Carbon $end * @param Collection $accounts * * @return View */ private function auditReport(Carbon $start, Carbon $end, Collection $accounts) { /** @var ARI $repos */ $repos = app(ARI::class); $auditData = []; $dayBefore = clone $start; $dayBefore->subDay(); /** @var Account $account */ foreach ($accounts as $account) { // balance the day before: $id = $account->id; $first = $repos->oldestJournalDate($account); $last = $repos->newestJournalDate($account); $exists = false; $journals = new Collection(); $dayBeforeBalance = Steam::balance($account, $dayBefore); /* * Is there even activity on this account between the requested dates? */ if ($start->between($first, $last) || $end->between($first, $last)) { $exists = true; $journals = $repos->journalsInPeriod(new Collection([$account]), [], $start, $end); } /* * Reverse set, get balances. */ $journals = $journals->reverse(); $startBalance = $dayBeforeBalance; /** @var TransactionJournal $journal */ foreach ($journals as $journal) { $journal->before = $startBalance; $transactionAmount = $journal->source_amount; // get currently relevant transaction: $destinations = TransactionJournal::destinationAccountList($journal)->pluck('id')->toArray(); if (in_array($account->id, $destinations)) { $transactionAmount = TransactionJournal::amountPositive($journal); } $newBalance = bcadd($startBalance, $transactionAmount); $journal->after = $newBalance; $startBalance = $newBalance; } /* * Reverse set again. */ $auditData[$id]['journals'] = $journals->reverse(); $auditData[$id]['exists'] = $exists; $auditData[$id]['end'] = $end->formatLocalized(strval(trans('config.month_and_day'))); $auditData[$id]['endBalance'] = Steam::balance($account, $end); $auditData[$id]['dayBefore'] = $dayBefore->formatLocalized(strval(trans('config.month_and_day'))); $auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance; } $reportType = 'audit'; $accountIds = join(',', $accounts->pluck('id')->toArray()); $hideable = ['buttons', 'icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date', 'from', 'to', 'budget', 'category', 'bill', 'internal_reference', 'notes', 'create_date', 'update_date']; $defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to']; return view('reports.audit.report', compact('start', 'end', 'reportType', 'accountIds', 'accounts', 'auditData', 'hideable', 'defaultShow')); }
/** * Determines if the instances contains a date. * * @see \Carbon\Carbon::between * @param CarbonDate $date * @param bool $equal Indicates if a > and < comparison should be used or <= or >= * @return bool */ public function contains(CarbonDate $date, $equal = true) { return $date->between($this->startDate, $this->endDate, $equal); }
/** * Search for tickets * * @param Request $request */ public function searchTicketAction(Request $request) { $event = $this->eventRepo->getNextEvent()->getOrThrow(new AccessDeniedHttpException('No event.')); // Do not allow checkins on the wrong day /* @var $event Event */ $now = new Carbon(); $start = Carbon::createFromTimestamp($event->getStart()->getTimestamp()); $start->setTime(0, 0, 0); $end = clone $start; $end->setTime(23, 59, 59); $day = $now->between($start, $end) ? Ticket::DAY_SATURDAY : Ticket::DAY_SUNDAY; $tickets = array_map(function (Ticket $ticket) { return array('code' => $ticket->getCode(), 'email' => $ticket->getEmail(), 'name' => $ticket->getName(), 'checkedIn' => $ticket->isCheckedIn(), 'day' => $ticket->getDay(), 'id' => $ticket->getId()); }, $this->ticketRepo->searchTickets($event, $day, $request->get('q'))); $data = array('items' => $tickets); $response = new Response(json_encode($data)); $response->setCharset('utf-8'); $response->headers->set('Content-Type', 'application/json'); return $response; }