コード例 #1
0
ファイル: DateTimeSince.php プロジェクト: kl07/datetime
 /**
  * Calculates the difference between dates.
  *
  * @param   DateTime  $base         The base date.
  * @param   DateTime  $datetime     The date to compare to. Default is null and this means that
  *                                  the base date will be compared to the current time.
  *
  * @param   integer   $detailLevel  The level of detail to retrieve.
  *
  * @return  array
  *
  * @since   2.0.0
  */
 private function calc(DateTime $base, DateTime $datetime = null, $detailLevel = 1)
 {
     $this->translator = $base->getTranslator();
     $datetime = is_null($datetime) ? DateTime::now() : $datetime;
     $detailLevel = intval($detailLevel);
     $diff = $this->diffInUnits($base->diff($datetime, true), $detailLevel);
     $item = 'just_now';
     if (!$this->isNow($diff)) {
         $item = $base->isAfter($datetime) ? 'in' : 'ago';
     }
     return array($item, $diff);
 }
コード例 #2
0
ファイル: DateHelper.php プロジェクト: asika32764/natika
 /**
  * since
  *
  * @param   string|DateTime $date
  *
  * @return  string
  */
 public function since($date)
 {
     if (!$date instanceof DateTime) {
         $date = new DateTime($date);
     }
     $now = DateTime::now();
     $compare = DateTime::now();
     $compare = $compare->subDays(30);
     if ($date->isBefore($compare)) {
         return $date->format('l, d F Y');
     }
     return $now->since($date);
 }