Example #1
0
 /**
  * Gets and sets the date for this Page object. This is typically passed in via the page headers
  *
  * @param  string $var string representation of a date
  * @return int         unix timestamp representation of the date
  */
 public function date($var = null)
 {
     if ($var !== null) {
         $this->date = Utils::date2timestamp($var);
     }
     if (!$this->date) {
         $this->date = $this->modified;
     }
     return $this->date;
 }
Example #2
0
 /**
  * Returns the items between a set of date ranges of either the page date field (default) or
  * an arbitrary datetime page field where end date is optional
  * Dates can be passed in as text that strtotime() can process
  * http://php.net/manual/en/function.strtotime.php
  *
  * @param      $startDate
  * @param bool $endDate
  * @param      $field
  *
  * @return $this
  * @throws \Exception
  */
 public function dateRange($startDate, $endDate = false, $field = false)
 {
     $start = Utils::date2timestamp($startDate);
     $end = $endDate ? Utils::date2timestamp($endDate) : strtotime("now +1000 years");
     $date_range = [];
     foreach ($this->items as $path => $slug) {
         $page = $this->pages->get($path);
         $date = $field ? strtotime($page->value($field)) : $page->date();
         if ($date > $start && $date < $end) {
             $date_range[$path] = $slug;
         }
     }
     $this->items = $date_range;
     return $this;
 }
Example #3
0
 public function testDate2timestamp()
 {
     $timestamp = strtotime('10 September 2000');
     $this->assertSame($timestamp, Utils::date2timestamp('10 September 2000'));
     $this->assertSame($timestamp, Utils::date2timestamp('2000-09-10 00:00:00'));
 }