public function outputDuration()
 {
     $from = new DateTime($this->getFromDate());
     $to = new DateTime($this->getToDate());
     $output = 'Stored for ';
     $days = (int) $from->diff($to)->format('%d');
     $months = (int) $from->diff($to)->format('%m');
     $daysString = $days . ' day';
     if ($days > 1) {
         $daysString .= 's';
     }
     $monthsString = $months . ' month';
     if ($months > 1) {
         $monthsString .= 's';
     }
     if ($days > 0 && $months > 0) {
         return 'Request for ' . $monthsString . ', ' . $daysString;
     } else {
         if ($days > 0) {
             return 'Request for ' . $daysString;
         } else {
             if ($months > 0) {
                 return 'Request for ' . $monthsString;
             }
         }
     }
 }
function convertSecondsToReadable($seconds)
{
    //Find difference in time in a readable format
    $dtF = new DateTime("@0");
    $dtT = new DateTime("@{$seconds}");
    $readable["months"] = (int) $dtF->diff($dtT)->format('%m');
    $readable["days"] = (int) $dtF->diff($dtT)->format('%a');
    $readable["hours"] = (int) $dtF->diff($dtT)->format('%h');
    $readable["minutes"] = (int) $dtF->diff($dtT)->format('%i');
    $readable["seconds"] = (int) $dtF->diff($dtT)->format('%s');
    $result = "";
    $prev_value = false;
    return $readable;
}
Example #3
0
 public function make($date, array $to_date = [])
 {
     if (is_array($date)) {
         $dt = \DateTime::createFromFormat($date[1] ?: $this->format_in, $date[0]);
     } else {
         $dt = \DateTime::createFromFormat($this->format_in, $date);
     }
     $cmp_date = $dt->format($this->format_out);
     if (!empty($to_date) && is_array($to_date)) {
         $today_dt = \DateTime::createFromFormat($to_date[1] ?: $this->format_in, $to_date[0]);
     } else {
         $today_dt = new \DateTime();
     }
     $today = $today_dt->format($this->format_out);
     $yesterday = $today_dt->modify('-1 day')->format($this->format_out);
     $diff_days = $today_dt->diff($dt)->format('%a') + 1;
     $diff_years = $today_dt->diff($dt)->format('%y');
     if ($cmp_date == $today) {
         return 'сегодня';
     } else {
         if ($cmp_date == $yesterday) {
             return 'вчера';
         } else {
             if ($diff_years >= 1) {
                 return $this->prefix . 'более ' . $diff_years . ' ' . self::getDecline($diff_years, 'года', 'лет', 'лет') . $this->postfix;
             } else {
                 if ($diff_days >= 2) {
                     return $this->prefix . $diff_days . ' ' . self::getDecline($diff_days, 'день', 'дня', 'дней') . $this->postfix;
                 }
             }
         }
     }
     return null;
 }
Example #4
0
 /**
  * @see PeriodableInterface::getDuration
  */
 public function getDuration()
 {
     if (!$this->startDate instanceof \DateTime || !$this->endDate instanceof \DateTime) {
         return null;
     }
     return $this->startDate->diff($this->endDate);
 }
Example #5
0
 /**
  * Show the user
  */
 public function showAction()
 {
     $user = $this->getUser();
     if (!is_object($user) || !$user instanceof UserInterface) {
         throw new AccessDeniedException('Este usuario no tiene acceso a esta seccion.');
     }
     $fecha = new \DateTime('now');
     $datos = array('Estado' => 'Sin relación a paciente o personal.');
     if ($this->getUser()->getIdTipoUsuario()->getNombre() == 'Paciente') {
         $repository = $this->getDoctrine()->getRepository('AsiClinicaBundle:Paciente');
         $paciente = $repository->findOneByIdusuario($this->getUser()->getId());
         if (isset($paciente)) {
             $edad = $fecha->diff($paciente->getFechanacimiento())->y;
             $datos = array('Nombre' => $paciente->getNombres() . ' ' . $paciente->getApellidos(), 'Género' => $paciente->getGenero(), 'Edad' => $edad, 'Teléfono' => $paciente->getTelefono(), 'Móvil' => $paciente->getMovil(), 'Lugar de nacimiento' => $paciente->getLugarnacimiento(), 'Dirección' => $paciente->getDireccion(), 'Departamento' => $paciente->getIdmunicipio()->getIddepartamento()->getNombre(), 'Municipio' => $paciente->getIdmunicipio()->getNombre(), 'Fecha de registro' => $paciente->getFechacreacion()->format('Y-m-d'));
         }
     } else {
         $repository = $this->getDoctrine()->getRepository('AsiClinicaBundle:Personal');
         $personal = $repository->findOneByIdusuario($this->getUser()->getId());
         if (isset($personal)) {
             $edad = $fecha->diff($personal->getFechanacimiento())->y;
             $datos = array('Nombre' => $personal->getNombres() . ' ' . $personal->getApellidos(), 'Edad' => $edad, 'Teléfono' => $personal->getTelefono(), 'Móvil' => $personal->getMovil(), 'DUI' => $personal->getDui(), 'Dirección' => $personal->getDireccion(), 'Departamento' => $personal->getIdmunicipio()->getIddepartamento()->getNombre(), 'Municipio' => $personal->getIdmunicipio()->getNombre());
         }
     }
     return $this->render('FOSUserBundle:Profile:show.html.twig', array('user' => $user, 'datos' => $datos));
 }
Example #6
0
 private function sejam($waktu, $dimunculkan)
 {
     $today = new DateTime();
     $selisih = $today->diff($waktu)->i;
     echo "selisih menit: {$selisih}<br>";
     return $waktu > $today && $waktu->format("Y-m-d") == $today->format("Y-m-d") && $today->diff($waktu)->h == 0 && (0 <= $selisih && $selisih <= 59) && ($dimunculkan & 1 << 0) == 0;
 }
 /**
  * 
  * @return \DateInterval
  */
 private function getInterval()
 {
     if (is_null($this->interval)) {
         $this->interval = $this->currentTime->diff($this->comparatorTime);
     }
     return $this->interval;
 }
Example #8
0
            default:
                $format = '%y ' . Tools::declension($date_start->diff($now)->format('%y'), array('год', 'года', 'лет')) . ' %m ' . Tools::declension($date_start->diff($now)->format('%m'), array('месяц', 'месяца', 'месяцев')) . ' %d ' . Tools::declension($date_start->diff($now)->format('%d'), array('день', 'дня', 'дней'));
                break;
        }
        return $this->Text . ' ' . $date_start->diff($now)->format($format);
    }
    /**
	* Return slider position
Example #9
0
 public function fetch_report_data()
 {
     global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
     $month = FormLib::get('month', date('n'));
     $year = FormLib::get('year', date('Y'));
     $end_of_last_month = mktime(0, 0, 0, $month, 0, $year);
     $ts = mktime(0, 0, 0, $month, 1, $year);
     $end_of_next_month = mktime(0, 0, 0, $month, date('t', $ts), $year);
     $end_last_dt = new DateTime(date('Y-m-d', $end_of_last_month));
     $end_next_dt = new DateTime(date('Y-m-d', $end_of_next_month));
     $loans = new GumLoanAccountsModel($dbc);
     $data = array();
     foreach ($loans->find('loanDate') as $loan) {
         $record = array($loan->accountNumber(), number_format($loan->principal(), 2), number_format($loan->interestRate() * 100, 2) . '%', $loan->termInMonths(), date('Y-m-d', strtotime($loan->loanDate())));
         $loanDT = new DateTime(date('Y-m-d', strtotime($loan->loanDate())));
         $days1 = $loanDT->diff($end_last_dt)->format('%r%a');
         $days2 = $loanDT->diff($end_next_dt)->format('%r%a');
         $bal_before = $loan->principal() * pow(1.0 + $loan->interestRate(), $days1 / 365.25);
         if ($days1 < 0) {
             $bal_before = $loan->principal();
         }
         $bal_after = $loan->principal() * pow(1.0 + $loan->interestRate(), $days2 / 365.25);
         if ($days2 < 0) {
             $bal_after = $loan->principal();
         }
         $record[] = number_format($bal_before, 2);
         $record[] = number_format($bal_after, 2);
         $record[] = number_format($bal_after - $bal_before, 2);
         $data[] = $record;
     }
     return $data;
 }
 /**
  * Calculate the years, days and hours between two supplied dates.
  * @param \DateTime $startDate
  * @param \DateTime $endDate
  * @return string
  */
 public function __invoke(\DateTime $startDate, \DateTime $endDate)
 {
     /**
      * Check to ensure that valid dates are entered.
      */
     if ($endDate <= $startDate) {
         throw new \InvalidArgumentException("Please ensure that the end date is less than the start date.");
     }
     /**
      * Start by calculating the complete different between the two dates.
      */
     $interval = $startDate->diff($endDate);
     /**
      * Extract the number of years only and create a new DateInterval based on this.
      */
     $numberOfYears = $interval->y;
     $yearInterval = new \DateInterval('P' . $interval->y . 'Y');
     /**
      * Using the original start date, add the new, whole-year interval.
      * We're not using DateTimeImmutable so the original object will be updated.
      */
     $startDate->add($yearInterval);
     /**
      * Now we diff the modified start date with the end date again. This will give
      * a timestamp of < 1 year.
      */
     $subYearInterval = $startDate->diff($endDate);
     /**
      * Output the number of years, followed by the number of days in the foreshortened
      * interval and finally, the number of hours.
      *
      * This could be improved using localisation and pluralisation.
      */
     return $subYearInterval->format($numberOfYears . ' years, %a day(s) and %h hour(s)');
 }
 /**
  * Gets the interval between the two dates
  *
  * @return DateInterval
  */
 public function getDateInterval()
 {
     if (!$this->from && !$this->to) {
         return null;
     }
     return $this->from->diff($this->to);
 }
Example #12
0
 private function getAge($upload_date)
 {
     $ts = upload_date;
     $date = new DateTime("@{$ts}");
     $from = new DateTime($date->format('Y-m-d'));
     $to = new DateTime('today');
     $year = $from->diff($to)->y;
     $months = $from->diff($to)->m;
     $days = $from->diff($to)->days;
     $hours = $from->diff($to)->h;
     $minutes = $from->diff($to)->i;
     $age = 'Fresh';
     if ($year > 0) {
         $age = $year == 1 ? $year . " year" : $year . " years";
     } else {
         if ($months > 0) {
             $age = $months == 1 ? $months . " month" : $months . " months";
         } else {
             if ($days > 0) {
                 $age = $days == 1 ? $days . " day" : $days . " days";
             } else {
                 if ($hours > 0) {
                     $age = $hours == 1 ? $hours . " hour" : $hours . " hours";
                 } else {
                     if ($minutes > 0) {
                         $age = $minutes == 1 ? $minutes . " minute" : $minutes . " minutes";
                     }
                 }
             }
         }
     }
     return $age;
 }
Example #13
0
function get_months($date)
{
    $d1 = new DateTime($date);
    $current_time = date("Y-m-d");
    $d2 = new DateTime($current_time);
    //var_dump($d1->diff($d2)->m); // int(4)
    return $d1->diff($d2)->m + $d1->diff($d2)->y * 12;
}
 /**
  * @return bool
  */
 private static function isItTime()
 {
     $dateLastConfiguration = new \DateTime(\RedDevil\Config\RoutesConfig::$dateOfLastCheck);
     $now = new \DateTime();
     $hoursPassed = $now->diff($dateLastConfiguration)->days * 24 + $now->diff($dateLastConfiguration)->h;
     if ($hoursPassed > 1) {
         return true;
     }
     return false;
 }
 function it_checks_hourly()
 {
     $now = new \DateTime();
     $diff = $now->diff(new \DateTime('-3 minute'));
     $this->hourly($diff)->shouldBe(true);
     $diff = $now->diff(new \DateTime('-64 minutes'));
     $this->hourly($diff)->shouldBe(false);
     $diff = $now->diff(new \DateTime('-2 hours'));
     $this->hourly($diff)->shouldBe(false);
 }
Example #16
0
 public function shortenDataProvider()
 {
     $start = new \DateTime('2014-09-14 00:00:00');
     $end = new \DateTime('2014-09-16 12:00:00');
     $start2 = new \DateTime('2000-01-01 00:00:00');
     $end2 = new \DateTime('2001-01-01 00:00:00');
     $start3 = new \DateTime('2001-01-01 00:00:00');
     $end3 = new \DateTime('2002-01-01 00:00:00');
     return array(array(new \DateInterval('PT48H'), false, '00-00-00 48:00:00'), array(new \DateInterval('PT48H'), true, '00-00-02 00:00:00'), array(new \DateInterval('P2D'), false, '00-00-00 48:00:00'), array(new \DateInterval('P2D'), true, '00-00-02 00:00:00'), array(new \DateInterval('P33D'), true, '00-01-03 00:00:00'), array(new \DateInterval('PT61M'), true, '00-00-00 01:01:00'), array(new \DateInterval('PT61S'), true, '00-00-00 00:01:01'), array(new \DateInterval('P13M'), true, '01-01-00 00:00:00'), array(new \DateInterval('P366D'), true, '01-00-01 00:00:00'), array(new \DateInterval('P366D'), false, '00-00-00 8784:00:00'), array($start->diff($end), true, '00-00-02 12:00:00'), array($start->diff($end), false, '00-00-00 60:00:00'), array($start2->diff($end2), true, '01-00-00 00:00:00'), array($start2->diff($end2), false, '00-00-00 8784:00:00'), array($start3->diff($end3), true, '01-00-00 00:00:00'), array($start3->diff($end3), false, '00-00-00 8760:00:00'));
 }
Example #17
0
 /**
  *
  * @return string l'intitulé du voyage et les dates
  */
 public function __toString()
 {
     $interval = $this->date_debut->diff($this->date_fin);
     if ($interval->days < 1) {
         $str_date = "le " . $this->date_debut->format('d/m/Y') . ", " . $this->date_debut->format('H:i') . " / " . $this->date_fin->format('H:i');
     } else {
         $str_date = "du " . $this->date_debut->format('d/m/Y') . " à " . $this->date_debut->format('H:i') . " au " . $this->date_fin->format('d/m/Y') . " à " . $this->date_fin->format('H:i');
     }
     return $this->libelle . ' (' . $str_date . ')';
 }
Example #18
0
function secondsToTime($seconds) {
	$dtF = new DateTime("@0");
	$dtT = new DateTime("@$seconds");
	
	if($seconds > 60*60*24)
		return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes');
	elseif($seconds > 60*60)
		return $dtF->diff($dtT)->format('%h hours, %i minutes');
	else
		return $dtF->diff($dtT)->format('%i minutes');
}
Example #19
0
 /**
  * Save log and print results
  * @param int $tests
  * @param int $failed
  */
 public function save($tests = 0, $failed = 0)
 {
     $content = "====================================" . PHP_EOL;
     $content .= "Totaly runned {$tests} tests, and {$failed} tests failed." . PHP_EOL;
     $diff = $this->time->diff(new \DateTime(), TRUE);
     $content .= "Time of all tests " . $diff->format("%H:%I:%S") . "" . PHP_EOL;
     $content .= "... reported at " . date("j. n. Y H:i:s") . "" . PHP_EOL;
     $this->result .= PHP_EOL . PHP_EOL . $content;
     echo $content;
     file_put_contents($this->filename, $this->result);
 }
Example #20
0
 protected function Body()
 {
     $ID = $this->getDopparamID();
     $this->setReportName('Заявка на списание основных средств №' . $ID);
     $Spisosnovakt = Spisosnovakt::find($ID)->joinWith(['idMol', 'idEmployee', 'idSchetuchet'])->one();
     $Spisosnovmaterials = Spisosnovmaterials::findAll(['id_spisosnovakt' => $ID]);
     $objPHPExcel = $this->getObjPHPExcel();
     $objPHPExcel->getActiveSheet()->setCellValue('A3', 'основных средств № ' . $Spisosnovakt->spisosnovakt_id . ' от ' . Yii::$app->formatter->asDate($Spisosnovakt->spisosnovakt_date));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 4, $Spisosnovakt->idMol->idperson->auth_user_fullname . ', ' . $Spisosnovakt->idMol->iddolzh->dolzh_name);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 5, $Spisosnovakt->idMol->idpodraz->podraz_name);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, 6, $Spisosnovakt->idSchetuchet->schetuchet_kod . ', ' . $Spisosnovakt->idSchetuchet->schetuchet_name);
     $num = 11;
     foreach ($Spisosnovmaterials as $ar) {
         $objPHPExcel->getActiveSheet()->insertNewRowBefore($num);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 10);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idMattraffic->idMaterial->material_name);
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(1, $num, 2, $num);
         $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, empty($ar->idMattraffic->idMaterial->material_serial) ? '-' : $ar->idMattraffic->idMaterial->material_serial);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, empty($ar->idMattraffic->idMaterial->material_release) ? '-' : Yii::$app->formatter->asDate($ar->idMattraffic->idMaterial->material_release));
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->spisosnovmaterials_number);
         if (!empty($ar->idMattraffic->idMaterial->material_release)) {
             $DateRelease = new \DateTime($ar->idMattraffic->idMaterial->material_release);
             $DateNow = new \DateTime();
             $Years = $DateNow->diff($DateRelease)->y;
             $Months = $DateNow->diff($DateRelease)->m;
             $CountYears = ($Years === 0 ? '' : $Years . ' л ') . ($Months === 0 ? '' : $Months . ' м');
         } else {
             $CountYears = '-';
         }
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $CountYears);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $ar->idMattraffic->idMaterial->material_price);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $num . ':I' . $num)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
         $num++;
     }
     $objPHPExcel->getActiveSheet()->removeRow($num);
     $crows = count($Spisosnovmaterials);
     $num = 12;
     $objPHPExcel->getActiveSheet()->unmergeCellsByColumnAndRow(1, $num + $crows - 1, 2, $num + $crows - 1);
     $objPHPExcel->getActiveSheet()->getStyle('C' . ($num + $crows - 1))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows, $Spisosnovakt->idMol->iddolzh->dolzh_name);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num + $crows, $Spisosnovakt->idMol->idperson->auth_user_fullname);
     if (isset($Spisosnovakt->idEmployee)) {
         $objPHPExcel->getActiveSheet()->insertNewRowBefore($num + $crows + 1);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num + $crows + 1, 'Иное ответственное лицо');
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num + $crows + 1, 1, $num + $crows + 1);
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num + $crows + 1, 4, $num + $crows + 1);
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(5, $num + $crows + 1, 8, $num + $crows + 1);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows + 1, $Spisosnovakt->idEmployee->iddolzh->dolzh_name);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num + $crows + 1, $Spisosnovakt->idEmployee->idperson->auth_user_fullname);
     } else {
         $objPHPExcel->getActiveSheet()->removeRow($num + $crows + 1);
     }
 }
 public function getIdadeAnimalAbreviadaAttribute()
 {
     if ($this->dataNascimentoAnimal) {
         $nasc = new \DateTime($this->dataNascimentoAnimal);
         $agora = new \DateTime(date("Y-m-d"));
         $diasAnimal = $agora->diff($nasc)->format("%a");
         $numeros = explode(',', $agora->diff($nasc)->format("%y,%m,%d"));
         return trans('Entities/Views/AnimalConsulta.idadeAnimalAbreviada', ['anos' => $numeros[0], 'meses' => $numeros[1], 'dias' => $numeros[2]]);
     }
     return 'N/D ';
 }
 private function calculate()
 {
     /* @var $units \Coduo\PHPHumanizer\DateTime\Unit[] */
     $units = array(new Year(), new Month(), new Day(), new Hour(), new Minute(), new Second());
     $diff = $this->fromDate->diff($this->toDate);
     foreach ($units as $unit) {
         if ($diff->{$unit->getDateIntervalSymbol()} > 0) {
             $this->units[] = $unit;
             $this->compoundResults[] = new CompoundResult($unit, $diff->{$unit->getDateIntervalSymbol()});
         }
     }
 }
Example #23
0
 protected function load_channels(&$plugin_cookies)
 {
     if (!ZTVTerminal::login()) {
         hd_print('Error: login_terminal');
         return;
     }
     $json_reply = ZTVApi::call(ZTVApi::get_playlists());
     if ($json_reply === false) {
         hd_print('Error: get_playlists');
         return;
     }
     $this->channels = new HashedArray();
     $this->groups = new HashedArray();
     if ($this->is_favorites_supported()) {
         $this->groups->put(new FavoritesGroup($this, '__favorites', ZTVConfig::FAV_CHANNEL_GROUP_CAPTION, ZTVConfig::FAV_CHANNEL_GROUP_ICON_PATH));
     }
     $this->groups->put(new AllChannelsGroup($this, ZTVConfig::ALL_CHANNEL_GROUP_CAPTION, ZTVConfig::ALL_CHANNEL_GROUP_ICON_PATH));
     $now = new DateTime('now');
     $use_proxy = isset($plugin_cookies->use_proxy) ? $plugin_cookies->use_proxy == 'yes' : false;
     foreach ($json_reply->result->medialist as $number => $media) {
         $mrl = $use_proxy ? str_replace('udp://@', 'http://' . $plugin_cookies->proxy_ip . ':' . $plugin_cookies->proxy_port . '/udp/', $media->mrl) : $media->mrl;
         $epg_start = ZTVApi::parse_datetime($media->epg_start);
         $epg_stop = ZTVApi::parse_datetime($media->epg_stop);
         if (is_null($epg_start) || is_null($epg_stop)) {
             $past_epg_days = 0;
             $future_epg_days = 0;
         } else {
             $epg_start_diff = $now->diff($epg_start);
             $epg_stop_diff = $now->diff($epg_stop);
             $past_epg_days = $epg_start_diff->days;
             $future_epg_days = $epg_stop_diff->days;
         }
         $channel = new ZTVChannel($media->id, $media->name, $media->logo == null ? 'plugin_file://icons/tv-missing.png' : $media->logo, $mrl, $number + 1, $past_epg_days, $future_epg_days);
         $this->channels->put($channel);
     }
     foreach ($json_reply->result->playlists as $category) {
         /* Remove any nonexistent channels from the group. */
         $items = array_filter($category->items, array($this, 'group_items_filter'));
         if (empty($items)) {
             continue;
         }
         $group = new DefaultGroup($category->id, $category->name, 'plugin_file://icons/' . basename($category->logo));
         foreach ($items as $item_id) {
             $channel = $this->channels->get($item_id);
             $channel->add_group($group);
             $group->add_channel($channel);
         }
         $this->groups->put($group);
     }
     $this->channels->usort(function ($a, $b) {
         return strnatcasecmp($a->get_number(), $b->get_number());
     });
 }
 public function isOldDay($day, $month, $year, $ecart = 0)
 {
     $now = new \DateTime();
     $date = new \DateTime($year . '-' . $month . '-' . $day);
     $ecart_mois = $now->diff($date)->format('%m');
     $ecart_jour = $now->diff($date)->format('%d');
     $ecart_heure = $now->diff($date)->format('%H');
     if ($ecart_mois >= 1 || $ecart_jour >= $ecart && $now > $date) {
         return true;
     }
     return false;
 }
 function daysToFinish($project)
 {
     if ($project->status == 3) {
         return 0;
     }
     $end = new \DateTime($project->due_date);
     $now = new \DateTime(date('Y-m-d'));
     if ($end < $now) {
         return -$now->diff($end)->days;
     } else {
         return $now->diff($end)->days;
     }
 }
Example #26
0
 private function calcularFerias()
 {
     foreach ($this->ferias as $k => $v) {
         $hoje = new \DateTime('now');
         $admissao = \DateTime::createFromFormat('d/m/Y', $v['data']);
         $aquisitivo_inicio = clone $admissao;
         $aquisitivo_fim = clone $admissao;
         $aquisitivo_fim->add(new \DateInterval('P12M'));
         $concessivo_inicio = clone $aquisitivo_fim;
         $concessivo_fim = clone $aquisitivo_fim;
         $concessivo_fim->add(new \DateInterval('P12M'));
         $this->ferias[$k]['periodo']['aquisitivo'] = sprintf('%s a %s', $aquisitivo_inicio->format('d/m/Y'), $aquisitivo_fim->format('d/m/Y'));
         $this->ferias[$k]['periodo']['concessivo'] = sprintf('%s a %s', $concessivo_inicio->format('d/m/Y'), $concessivo_fim->format('d/m/Y'));
         if ($hoje < $admissao) {
             $interval = $hoje->diff($admissao);
             $this->ferias[$k]['status'] = sprintf('Deverá ser contratado em %d dias.', $interval->days);
             $this->ferias[$k]['info'] = sprintf('Estas informações foram provavelmente fornecidas por Marty McFly ou Mãe Diná.');
         } elseif ($hoje >= $aquisitivo_inicio && $hoje < $aquisitivo_fim) {
             $interval_inicio = $hoje->diff($aquisitivo_inicio);
             $interval_fim = $hoje->diff($aquisitivo_fim);
             if ($interval_inicio->days < 90) {
                 $this->ferias[$k]['status'] = sprintf('Primeiros 90 dias de experiência.');
                 $this->ferias[$k]['info'] = sprintf('Você pode renovar o contrato em até 90 dias.');
             } elseif ($interval_fim->days < 30) {
                 $this->ferias[$k]['status'] = sprintf('Menos de 30 dias para o início do período concessivo.');
                 $this->ferias[$k]['info'] = sprintf('O período concessivo de férias é o prazo que a Lei estabelece para que o empregador conceda as férias ao empregado. Este prazo equivale aos 12 (doze) meses subsequentes a contar da data do período aquisitivo completado.');
             } else {
                 $this->ferias[$k]['status'] = sprintf('Dentro do período aquisitivo.');
                 $this->ferias[$k]['info'] = sprintf('O período aquisitivo de férias é o período de 12 (doze) meses a contar da data de admissão do empregado que, uma vez completados, gera o direito ao empregado de gozar os 30 (trinta) dias de férias.');
             }
         } elseif ($hoje >= $concessivo_inicio && $hoje < $concessivo_fim) {
             $interval = $hoje->diff($aquisitivo_fim);
             if ($interval->days < 30) {
                 $this->ferias[$k]['status'] = sprintf('Menos de 30 dias para o fim do período concessivo.');
                 $this->ferias[$k]['info'] = sprintf('Embora a lei estabeleça que as férias devam ser concedidas nos 12 (doze) meses subsequentes ao período aquisitivo, o entendimento jurisprudencial é que devam ser concedidas antes que vença o 2º período aquisitivo, ou seja, o término de gozo deve ser antes do vencimento dos 12 meses de concessão.');
             } else {
                 $this->ferias[$k]['status'] = sprintf('Direito a gozar férias.');
                 $this->ferias[$k]['info'] = sprintf('De acordo com a CLT, o empregador que não conceder as férias para o empregado ou que o fizer fora do período concessivo, é obrigado a pagar o valor equivalente em dobro, conforme o disposto nos artigos 134 e 137, podendo ainda sofrer sanções administrativas impostas pelo Ministério do Trabalho quando da fiscalização.');
             }
         } elseif ($hoje >= $concessivo_fim) {
             $interval_aquisitivo = $hoje->diff($aquisitivo_fim);
             $interval_concessivo = $hoje->diff($concessivo_fim);
             if ($interval_aquisitivo->y > 0) {
                 $this->ferias[$k]['status'] = sprintf('Férias de %d ano(s) vencidas. Direito a gozar férias de %d ano(s).', $interval_concessivo->y + 1, $interval_aquisitivo->y + 1);
             } else {
                 $this->ferias[$k]['status'] = sprintf('Férias de %d ano(s) vencidas.', $interval_concessivo->y + 1);
             }
             $this->ferias[$k]['info'] = sprintf('Todos os valores a que o empregado tem direito como o salário, as médias de variáveis, os adicionais previstos na legislação (noturno, insalubridade, periculosidade e etc.) e o 1/3 constitucional, devem ser considerados para o pagamento em dobro.');
         }
     }
 }
 function secondsToTime($seconds)
 {
     $dtF = new DateTime("@0");
     $dtT = new DateTime("@{$seconds}");
     if ($seconds > 60 * 60 * 24) {
         return $dtF->diff($dtT)->format('%a d: %hh: %i m');
     } else {
         if ($seconds > 60 * 60) {
             return $dtF->diff($dtT)->format('%hh %im');
         } else {
             return $dtF->diff($dtT)->format('%i min');
         }
     }
 }
Example #28
0
/**
 * Calculate the difference in months between two dates
 *
 * @param DateTime $from
 * @param DateTime $to
 * @return int
 */
function diffInMonths(DateTime $from, DateTime $to)
{
    // Count months from year and month diff
    $diff = $to->diff($from)->format('%y') * 12 + $to->diff($from)->format('%m');
    // If there is some day leftover, count it as the full month
    if ($to->diff($from)->format('%d') > 0) {
        $diff++;
    }
    // The month count isn't still right in some cases. This covers it.
    if ($from->format('d') >= $to->format('d')) {
        $diff++;
    }
    return $diff;
}
 /**
  * Calculates current uptime of the bot
  */
 public function doExecute()
 {
     parent::doExecute();
     $oNow = new DateTime();
     $oDifference = $this->__oStartDateTime->diff($oNow);
     $iYears = $oDifference->format('%y');
     $iDays = $oDifference->format('%d');
     $iHours = $oDifference->format('%H');
     $iMinutes = $oDifference->format('%I');
     $sResponse = $iYears ? $iYears . ' ' . Config::getInstance()->lang('YEARS') . ', ' : '';
     $sResponse .= $iDays ? $iDays . ' ' . Config::getInstance()->lang('DAYS') . ', ' : '';
     $sResponse .= $iHours . ':' . $iMinutes . ' ' . Config::getInstance()->lang('HOURS');
     $this->setReturnMessage($sResponse);
 }
Example #30
0
 /**
  * whether the time is between 15:00 to 17:00
  * @return bool
  */
 public static function isTimeAvailable()
 {
     $dt = new DateTime('now');
     $beginTime = new DateTime();
     $beginTime->setTime(15, 0);
     $endTime = new DateTime();
     $endTime->setTime(17, 0);
     $beginInterval = $dt->diff($beginTime);
     $endInterval = $dt->diff($endTime);
     if ($beginInterval->invert == 1 && $endInterval->invert == 0) {
         return true;
     }
     return false;
 }