Example #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');
 }