Esempio n. 1
0
 /**
  * @return string
  */
 public function __toString()
 {
     if ($this->interval != null) {
         return $this->interval->__toString();
     }
     return '';
 }
 private function GetDateOffsetFromToday($date, $timezone)
 {
     if (empty($date)) {
         return null;
     }
     $today = Date::Create(Date('Y'), Date('m'), Date('d'), 0, 0, 0, $timezone);
     $diff = DateDiff::BetweenDates($today, $date);
     return $diff->Days();
 }
Esempio n. 3
0
 /**
  * @param int $ownerId
  * @param SeriesUpdateScope|string $scope
  * @param string $title
  * @param DateRange $blackoutDate
  * @param IRepeatOptions $repeatOptions
  * @param int[] $resourceIds
  */
 public function Update($ownerId, $scope, $title, $blackoutDate, $repeatOptions, $resourceIds)
 {
     $this->ownerId = $ownerId;
     $this->title = $title;
     $this->resourceIds = array();
     foreach ($resourceIds as $rid) {
         $this->AddResourceId($rid);
     }
     if ($scope == SeriesUpdateScope::ThisInstance) {
         $this->blackouts = array();
         $this->AddBlackout(new Blackout($blackoutDate));
         $this->SetCurrentBlackout($blackoutDate);
         $this->Repeats(new RepeatNone());
     } else {
         $currentDate = $this->CurrentBlackout()->Date();
         $newDate = $blackoutDate;
         $startDiff = DateDiff::BetweenDates($currentDate->GetBegin(), $newDate->GetBegin());
         $endDiff = DateDiff::BetweenDates($currentDate->GetEnd(), $newDate->GetEnd());
         $earliestDate = $this->GetEarliestDate($blackoutDate);
         if (!$earliestDate->Equals($blackoutDate)) {
             $earliestDate = new DateRange($earliestDate->GetBegin()->ApplyDifference($startDiff), $earliestDate->GetEnd()->ApplyDifference($endDiff));
         }
         $this->blackouts = array();
         $this->AddBlackout(new Blackout($earliestDate));
         $this->SetCurrentBlackout($earliestDate);
         $this->Repeats($repeatOptions);
     }
     $this->isNew = $scope == SeriesUpdateScope::ThisInstance;
 }
Esempio n. 4
0
 /**
  * @static
  * @param Date $date1
  * @param Date $date2
  * @return DateDiff
  */
 public static function BetweenDates(Date $date1, Date $date2)
 {
     if ($date1->Equals($date2)) {
         return DateDiff::Null();
     }
     $compareDate = $date2;
     if ($date1->Timezone() != $date2->Timezone()) {
         $compareDate = $date2->ToTimezone($date1->Timezone());
     }
     return new DateDiff($compareDate->Timestamp() - $date1->Timestamp());
 }
Esempio n. 5
0
 public function testCanGetDifferenceFromTime()
 {
     $seconds = 12 * 60 * 60 + 60 * 35;
     $str1 = "0d12h35m";
     $diff1 = DateDiff::FromTimeString($str1);
     $this->assertEquals($seconds, $diff1->TotalSeconds());
     $this->assertEquals(12, $diff1->Hours());
     $this->assertEquals(35, $diff1->Minutes());
     $this->assertEquals(0, $diff1->Days());
     $this->assertEquals("12 hours 35 minutes", $diff1->__toString());
     $seconds2 = 4 * 24 * 60 * 60 + 12 * 60 * 60 + 60 * 35;
     $str2 = "4d12h35m";
     $diff2 = DateDiff::FromTimeString($str2);
     $this->assertEquals($seconds2, $diff2->TotalSeconds());
     $this->assertEquals(12, $diff2->Hours());
     $this->assertEquals(35, $diff2->Minutes());
     $this->assertEquals(4, $diff2->Days());
     $this->assertEquals("4 days 12 hours 35 minutes", $diff2->__toString());
     $diff3 = DateDiff::FromTimeString("25h0m");
     $this->assertEquals(25 * 60 * 60, $diff3->TotalSeconds());
     $this->assertEquals(0, DateDiff::FromTimeString("dhm")->TotalSeconds());
     $this->assertEquals(0, DateDiff::FromTimeString("hm")->TotalSeconds());
     $this->assertEquals(0, DateDiff::FromTimeString("dm")->TotalSeconds());
 }
Esempio n. 6
0
<?php

namespace JimmyDBurrell\DOBStats;

require_once '../db.php';
require_once './vendor/autoload.php';
date_default_timezone_set('America/Chicago');
$dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME;
$pdo = new \PDO($dsn, DB_USER, DB_PASS);
$beginDateTime = new \DateTime(date('Y-m-d', strtotime('-4 days')));
$beginDate = $beginDateTime->format('Y-m-d');
$sql = 'SELECT id,dob,created_at FROM app where id_customer = 24 order by id desc limit 2500';
$stmt = $pdo->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL]);
$stmt->execute();
$data = new DbRowIterator($stmt);
echo 'Getting the age and date-of-birth for drivers who applied after ' . $beginDate . "<br />" . PHP_EOL;
$lastPeriod = new LastPeriodIterator($data, $beginDate);
$ageTalley = new TalleyAge();
foreach ($lastPeriod as $pos => $row) {
    if ($row->dob > "") {
        $dateDiff = new DateDiff($row->dob);
        $age = $dateDiff->diffInYears();
        $ageTalley->countAndCategorize($age);
    } else {
        unset($age);
    }
}
// end foreach ($lastPeriod as $row)
echo "Finished processing {$pos} driver records.<br />" . PHP_EOL;
$output = new StatsOutput();
$output->cliOutput($ageTalley);