public function durasi() { $dari = new \DateTime($this->dari); $sampai = new \DateTime($this->sampai); $interval = $sampai->diff($dari); return $interval->format('%y tahun %m bulan %d hari'); }
public function umur() { $now = new \DateTime("now"); $tgl_lahir = new \DateTime($this->tgl_lahir); $interval = $tgl_lahir->diff($now); return $interval->format('%y tahun %m bulan %d hari'); }
public function toArray() { $data = parent::toArray(); if (!empty($data['photos'])) { $data['photos'] = $this->processPhotos($data['photos']); } $data['age'] = false; if (!empty($data['bdate'])) { $bdate = explode('.', $data['bdate']); if (count($bdate) >= 3) { $bdate = new \DateTime($bdate[2] . '-' . $bdate[1] . '-' . $bdate[0]); $now = new \DateTime(); $diff = $now->diff($bdate); $year = $diff->y; $age = trans_choice('main.age', $year, [], 'message', 'ru'); $data['age'] = $age; } } if ($data['age'] == false) { $year = rand(18, 25); $age = trans_choice('main.age', $year, [], 'message', 'ru'); $data['age'] = $age; } return $data; }
private static function compileSchema() { $upSchema = ""; $downSchema = ""; $schema = ""; $newSchema = ""; $count = 1; foreach (self::$schema as $name => $values) { if (in_array($name, self::$ignore)) { continue; } $upSchema .= "\n//\n// NOTE -- {$name}\n// --------------------------------------------------\n\n{$values['up']}"; $downSchema .= "\n{$values['down']}"; // } $schema = "<?php\n\n//\n// NOTE Migration Created: " . date("Y-m-d H:i:s") . "\n// --------------------------------------------------\n\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Database\\Migrations\\Migration;\n\nclass Create" . str_replace('_', '', Str::title($name)) . "Table extends Migration {\n//\n// NOTE - Make changes to the database.\n// --------------------------------------------------\n\npublic function up()\n{\n" . $upSchema . "\n" . self::$up . "\n}\n\n//\n// NOTE - Revert the changes to the database.\n// --------------------------------------------------\n\npublic function down()\n{\n" . $downSchema . "\n" . self::$down . "\n}\n}"; $date = new \DateTime($values['create']); //$filename = date('Y_m_d_His') . "_create_" . $name . "_table.php"; $filename = $date->format('Y_m_d_His') . $count . "_create_" . $name . "_table.php"; file_put_contents(__DIR__ . "/../database/migrations/{$filename}", $schema); $schema = ""; $upSchema = ""; $downSchema = ""; $count++; } return $schema; }
public function age() { if ($this->birthdate !== '0000-00-00') { $from = new \DateTime($this->birthdate); $to = new \DateTime('today'); return '(' . $from->diff($to)->y . ')'; } }
public function getHoursSpentAttribute() { $duration = new \DateTime('00:00'); $f = clone $duration; foreach ($this->times as $time) { $duration->add($time->duration); } return $f->diff($duration); }
/** * Gets the difference between 2 timestamps * * @param int $now * @param int $target * * @return array */ static function difference(int $now, int $target) : array { $nowdt = new \DateTime(); $nowdt->setTimestamp($now); $targetdt = new \DateTime(); $targetdt->setTimestamp($target); $diff = date_diff($nowdt, $targetdt, true); $subtract = $now - $target; return array('year' => $diff->y, 'month' => $diff->m, 'day' => $diff->d, 'hour' => $diff->h, 'minute' => $diff->i, 'second' => $diff->s, 'past' => $subtract > 0, 'time' => abs($subtract), 'target' => $target); }
public static function blockToTime($block, $baseDate = NULL) { $beginHours = 8; $hoursPassed = $block / 4; $minutesPassed = $block % 4 * 15; if ($baseDate == NULL) { $baseDate = new DateTime(); } return $baseDate->setTime($beginHours + $hoursPassed, $minutesPassed); }
public static function ageCalculator($dob) { if ($dob != '0000-00-00') { $birthdate = new \DateTime($dob); $today = new \DateTime('today'); $age = $birthdate->diff($today)->y; return $age; } else { return null; } }
public function getDurationInDays() { $duracao = 0; if ($this->int_data_alta === null) { $hoje = new \DateTime(); $duracao = $hoje->diff(\DateTime::createFromFormat('Y-m-d H:i:s', $this->int_data_encaminhamento)); } else { $dataAlta = \DateTime::createFromFormat('Y-m-d', $this->int_data_alta); $duracao = $dataAlta->diff(\DateTime::createFromFormat('Y-m-d H:i:s', $this->int_data_encaminhamento)); } return $duracao->format('%a'); }
public static function generateInvoiceId() { //needs recheck $invdesc = StockInvoice::orderBy('id', 'DESC')->first(); if ($invdesc != null) { $invDescId = $invdesc->invoice_id; $invDescIdNo = substr($invDescId, 7); $subinv1 = substr($invDescId, 6); $dd = substr($invDescId, 1, 2); $mm = substr($invDescId, 3, 2); $yy = substr($invDescId, 5, 2); //var_dump($invDescId." ".$dd." ".$mm." ".$yy); //echo "d1 ".$yy; $tz = 'Asia/Dhaka'; $timestamp = time(); $dt = new \DateTime("now", new \DateTimeZone($tz)); //first argument "must" be a string $dt->setTimestamp($timestamp); //adjust the object to correct timestamp $Today = $dt->format('d.m.Y'); $explodToday = explode(".", $Today); $dd2 = $explodToday[0]; $mm2 = $explodToday[1]; $yy1 = $explodToday[2]; $yy2 = substr($yy1, 2); //var_dump($dd2." ".$mm2." ".$yy2); if ($dd == $dd2 && $yy == $yy2 && $mm == $mm2) { $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . ($invDescIdNo + 1); //var_dump($invoiceidd); return $invoiceidd; } else { $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . "1"; return $invoiceidd; } } else { $tz = 'Asia/Dhaka'; $timestamp = time(); $dt = new \DateTime("now", new \DateTimeZone($tz)); //first argument "must" be a string $dt->setTimestamp($timestamp); //adjust the object to correct timestamp $Today = $dt->format('d.m.Y'); $explodToday = explode(".", $Today); $mm2 = $explodToday[1]; $dd2 = $explodToday[0]; $yy1 = $explodToday[2]; $yy2 = substr($yy1, 2); $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . "1"; //var_dump($invoiceidd); return $invoiceidd; } }
public function getDuracaoEmDias() { $tempo = ''; $hoje = new \DateTime(); $inicio = \DateTime::createFromFormat('Y-m-d', $this->tto_data_inicio); if ($this->tto_data_alta === null) { $tempo = $hoje->diff($inicio); } else { $alta = \DateTime::createFromFormat('Y-m-d', $this->tto_data_alta); $tempo = $alta->diff($inicio); } return $tempo->format('%a'); }
protected function pinoyTime($_date_string, $_date_format = 'Y-m-d h:i:s A') { // See: http://stackoverflow.com/questions/2505681/timezone-conversion-in-php // See: http://php.net/manual/en/timezones.asia.php if (!class_exists('DateTime')) { throw new Exception('Unable to use DateTime class when calling Xplog::pinoyTime() method.'); return false; } $datetime = new \DateTime($_date_string); $phil_time = new \DateTimeZone('Asia/Singapore'); // phil timezone $datetime->setTimezone($phil_time); return $datetime->format($_date_format); }
/** * Démarre l'application */ public function start() { date_default_timezone_set('Europe/Paris'); setlocale(LC_TIME, 'fr_FR.utf8', 'fra'); if ($_SERVER['REQUEST_URI'] !== '/favicon.ico') { $date = new \DateTime(); $log = new Logger($this->getConfig('title')); $log->pushHandler(new StreamHandler(ROOT . '/log/' . $date->format('d-m-Y') . '.log', Logger::INFO)); $log->info($_SERVER['REMOTE_ADDR'] . ' => ' . $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI']); } $router = $this->getRouter(); // scope them all require ROOT . '/config/route.php'; return $this->getRouter()->run(); }
public static function updateExistingDaily() { $date = new DateTime(); //The data in PRH api lags one day so get info for yesterday $date->add(DateInterval::createFromDateString('yesterday'))->format('Y-m-d'); //Construct the url from the base url and add a changed since $url = self::$URL . '&companyChangedSince=' . $date; $data = $self::fetchData($url); //Check whether a company can be found and save that company foreach ($data as $single) { if (Company::where('business_id', $data->businessId)->first()) { $ids[] .= self::saveData($single); } } return $ids; }
/** * @param $request * @return bool */ public function validate($request) { $validate = Validator::make($request, ['log_name' => 'required|max:50', 'level' => 'required|min:3|max:10', 'content' => 'required', 'site' => 'required|max:50']); if ($validate->fails()) { return false; } $this->container = $request; if ($this->validateAllowedFields() === false) { return false; } $this->StorageDriver->defineTable($this->container['site']); $this->site = $this->container['site']; $data_created = new \DateTime(); $this->container = ['data_created' => $data_created->format('Y-m-d H:i:s'), 'level' => WarehouseController::validateLevel($this->container['level']), 'log_name' => $this->container['log_name'], 'identifier' => isset($this->container['identifier']) ? $this->container['identifier'] : 'none', 'content' => $this->container['content']]; return true; }
public static function is_vip($user_id) { $user = User::find($user_id); if (count($user) < 1) { return false; } if ($user->vip < 1) { return false; } // Go crazy with this. Cannot figure out why $user->expire_at returns a string while $user->created_at returns an \DateTime object. $oldExpire = new \DateTime($user->expire_at); $now = new \DateTime(); if ($now->getTimestamp() - $oldExpire->getTimestamp() > 0) { // VIP was expired before. return false; } return true; }
public function getAgeAttribute() { if ($this->attributes['birthdate']) { $tz = new \DateTimeZone('Europe/Brussels'); $date = \DateTime::createFromFormat('Y-m-d', $this->attributes['birthdate']); return $date->diff(new \DateTime('now', $tz))->y; } return 0; }
public function getPrice($package, $booking) { if (!is_null($package->building->category->buildingCatName) && ($package->building->category->buildingCatName == 'Hotel' || $package->building->category->buildingCatName == 'Appartment')) { //$price = $checkIn = new \DateTime($booking->checkIn); $checkOut = new \DateTime($booking->checkOut); $noDays = $checkOut->diff($checkIn)->format("%a"); $price = $this->getPromotionalPrice($package, 0); $price['days'] = $noDays; } else { if (!is_null($package->building->category->buildingCatName) && ($package->building->category->buildingCatName == 'Bungalow' || $package->building->category->buildingCatName == 'Villa' || $package->building->category->buildingCatName == 'Penthouse' || $package->building->category->buildingCatName == 'House')) { $checkIn = new \DateTime($booking->checkIn); $checkOut = new \DateTime($booking->checkOut); $noDays = $checkOut->diff($checkIn)->format("%a"); $perprice = $this->getPromotionalPrice($package, 1); $price = $noDays * $perprice; } } return $price; }
public static function monthlySalesVsPurchase($params, $currentUser, $con) { if (!isset($params->month)) { throw new \Exception('Missing parameter'); } $picked = new \DateTime($params->month); $date = new \stdClass(); $date->start = new \DateTime($picked->format('Y-m-01')); $date->until = new \DateTime($picked->format('Y-m-t')); $results = Charts::getSalesVsPurchase($date, $con); return $results; }
public function scopeSearch($query, $request) { if (!empty($request['created_at_from']) && !empty($request['created_at_to'])) { $dtFrom = new \DateTime($request['created_at_from']); $dtTo = new \DateTime($request['created_at_to']); $query->whereBetween('created_at', [$dtFrom->format('Y-m-d 00:00:00'), $dtTo->format('Y-m-d 23:59:59')]); } if (!empty($request['id'])) { $query->where('id', (int) $request['id']); } if (!empty($request['title'])) { $query->where('title', 'like', "%" . $request['title'] . "%"); } if (!empty($request['status'])) { $query->where('status', $request['status']); } if (!empty($request['manager_id'])) { $query->where('manager_id', (int) $request['manager_id']); } if (!empty($request['client_id'])) { $query->where('client_id', (int) $request['client_id']); } return $query; }
public static function last7MonthsTransactions($params, $currentUser, $con) { $date = new \DateTime(Date('Y-m-01')); $date->sub(new \DateInterval('P7M')); $data = []; for ($i = 1; $i <= 7; $i++) { $date->add(new \DateInterval('P1M')); $sales = SalesQuery::create()->filterByStatus('Active')->filterBySecondPartyId($params->customer_id)->filterByDate(array('min' => $date->format('Y-m-01'), 'max' => $date->format('Y-m-t')))->withColumn('SUM(Sales.TotalPrice)', 'sales_total')->select(['sales_total'])->find($con); $row = ['month' => $date->format('Y-m-01'), 'sales' => isset($sales[0]) ? $sales[0] : 0]; $data[] = $row; } $results['success'] = true; $results['data'] = $data; return $results; }
/** * @return \Nette\Application\IRouter */ public function createRouter() { $router = new RouteList(); $router[] = new Route('user/<presenter>/<action>[[/<email>]/<token>]', array('module' => 'User', 'presenter' => 'Account', 'action' => 'default', "email" => null, 'token' => null)); $router[] = new Route('mail-box/<action received-read|received-unread|sent>[/page-<messagesTable-paginator-page>]', array('module' => 'Front', 'presenter' => 'MailBox', 'action' => 'receivedUnread')); $router[] = new Route('listing/<action overview|add>/<year>[/<month>]', array('module' => 'Front', 'presenter' => 'Listing', 'action' => 'overview', 'year' => null, 'month' => [Route::FILTER_IN => function ($monthName) { $date = \DateTime::createFromFormat('!F', $monthName); return $date !== false ? $date->format('n') : date('n'); }, Route::FILTER_OUT => function ($monthNumber) { if ($monthNumber < 0 or $monthNumber > 12) { return null; } $date = \DateTime::createFromFormat('!n', $monthNumber); if ($date === false) { return null; } return Nette\Utils\Strings::webalize($date->format('F')); }])); $router[] = new Route('<presenter>/<action>[/<id \\d+>]', array('module' => 'Front', 'presenter' => 'Listing', 'action' => 'overview', 'id' => null)); return $router; }
public function corrigeData($date, $format) { $retDate = new \DateTime($date); $weekDay = date('w', strtotime($date)); if ($this->antecipa_posterga == 'posterga') { if ($weekDay == 0) { $retDate->add(new \DateInterval('P1D')); } if ($weekDay == 6) { $retDate->add(new \DateInterval('P2D')); } } if ($this->antecipa_posterga == 'antecipa') { if ($weekDay == 0) { $retDate->sub(new \DateInterval('P2D')); } if ($weekDay == 6) { $retDate->sub(new \DateInterval('P1D')); } } return $retDate->format($format); }
public static function timeInterval($time) { $from = new \DateTime('00:00:00'); $to = new \DateTime($time); return $from->diff($to); }
public function getIdade() { $hoje = new \DateTimeImmutable(); $nascimento = \DateTime::createFromFormat('Y-m-d', $this->pac_nascimento); return (int) $nascimento->diff($hoje)->y; }
/** * ToDo: Use Carbon instead of DateTime * * get Age * * @return int Age in years */ public function getAgeAttribute() { if ($this->birthdate == null) { return null; } $reference = new \DateTime(); $born = new \DateTime($this->birthdate); if ($this->birthdate > $reference) { return null; } $diff = $reference->diff($born); return $diff->y; }
public function getSecondsAttribute() { $created_at = new \DateTime($this->created_at); $updated_at = new \DateTime($this->updated_at); return $updated_at->getTimestamp() - $created_at->getTimestamp(); }
/** * Override the eloquent date to string formatting method to ensure a correctly formatted date is returned. * * @param \DateTime $date * * @return string */ protected function serializeDate(\DateTime $date) { return $date->format('c'); }
function saveSetList($setList, $event) { $oldSetlists = $event->getSetListGroups(); foreach ($oldSetlists as $group) { $oldSetListItems = $group->getSetListItems(); $this->em->remove($oldSetListItems); } $this->em->remove($oldSetlists); $this->em->flush(); $setListGroup = new \App\Model\Entity\SetListGroup(); $setListGroup->setName('Program'); $setListGroup->setEvent($event); foreach ($setList as $day) { foreach ($day->times as $dayItem) { $setListItem = new \App\Model\Entity\setListItem(); $setListItem->setDateTime(\DateTime::createFromFormat('Y-m-d H:i', $day->day . ' ' . $dayItem->time)); $setListItem->setName($dayItem->name); $setListItem->setDescription($dayItem->description); $setListItem->setType('item'); $setListItem->setSetListGroup($setListGroup); $this->em->persist($setListItem); $setListGroup->addSetListItem($setListItem); } } $this->em->persist($setListGroup); $event->addSetListGroup($setListGroup); return $this->saveEvent($event); }