Esempio n. 1
0
 public function testDateTimestamp()
 {
     $api = Api::get("https://lesbonneschoses.cdn.prismic.io/api");
     $results = $api->forms()->everything->query(Predicates::at("document.id", "UlfoxUnM0wkXYXbl"))->ref($api->master())->submit()->getResults();
     $doc = $results[0];
     // startgist:c6a5d3d570a585ea6941:prismic-dateTimestamp.php
     // Date and Timestamp predicates
     $dateBefore = Predicates::dateBefore("my.product.releaseDate", new DateTime('2014-6-1'));
     $dateAfter = Predicates::dateAfter("my.product.releaseDate", new DateTime('2014-1-1'));
     $dateBetween = Predicates::dateBetween("my.product.releaseDate", new DateTime('2014-1-1'), new DateTime('2014-6-1'));
     $dayOfMonth = Predicates::dayOfMonth("my.product.releaseDate", 14);
     $dayOfMonthAfter = Predicates::dayOfMonthAfter("my.product.releaseDate", 14);
     $dayOfMonthBefore = Predicates::dayOfMonthBefore("my.product.releaseDate", 14);
     $dayOfWeek = Predicates::dayOfWeek("my.product.releaseDate", "Tuesday");
     $dayOfWeekAfter = Predicates::dayOfWeekAfter("my.product.releaseDate", "Wednesday");
     $dayOfWeekBefore = Predicates::dayOfWeekBefore("my.product.releaseDate", "Wednesday");
     $month = Predicates::month("my.product.releaseDate", "June");
     $monthBefore = Predicates::monthBefore("my.product.releaseDate", "June");
     $monthAfter = Predicates::monthAfter("my.product.releaseDate", "June");
     $year = Predicates::year("my.product.releaseDate", 2014);
     $hour = Predicates::hour("my.product.releaseDate", 12);
     $hourBefore = Predicates::hourBefore("my.product.releaseDate", 12);
     $hourAfter = Predicates::hourAfter("my.product.releaseDate", 12);
     // Accessing Date and Timestamp fields
     $date = $doc->getDate("blog-post.date");
     $dateYear = $date->asDateTime()->format('Y');
     $updateTime = $doc->getTimestamp("blog-post.update");
     if ($updateTime) {
         $updateHour = $updateTime->asDateTime()->format('H');
     }
     // endgist
     $this->assertEquals($dateYear, '2013');
 }
Esempio n. 2
0
 public function archives($date, $page = 1)
 {
     if (!$date['month']) {
         $lowerBound = DateTime::createFromFormat('Y-m-d', $date['year'] - 1 . '-12-31');
         $upperBound = DateTime::createFromFormat('Y-m-d', $date['year'] + 1 . '-01-01');
     } elseif (!$date['day']) {
         $lowerBound = DateTime::createFromFormat('Y-m-d', $date['year'] . '-' . $date['month'] . '-01');
         $upperBound = clone $lowerBound;
         $lowerBound->modify('-1 day');
         $upperBound->modify('+1 month - 1 day');
     } else {
         $lowerBound = DateTime::createFromFormat('Y-m-d', $date['year'] . '-' . $date['month'] . '-' . $date['day']);
         $upperBound = clone $lowerBound;
         $lowerBound->modify('-1 day');
     }
     return $this->form()->query(array(Predicates::at('document.type', 'post'), Predicates::dateAfter('my.post.date', $lowerBound), Predicates::dateBefore('my.post.date', $upperBound)))->orderings('[my.post.date desc]')->page($page)->submit();
 }