Skip to content

Instantly share code, notes, and snippets.

@prismicdeveloper
Created March 31, 2015 09:44
Show Gist options
  • Save prismicdeveloper/4ac2db89bde0ca0c2b33 to your computer and use it in GitHub Desktop.
Save prismicdeveloper/4ac2db89bde0ca0c2b33 to your computer and use it in GitHub Desktop.
# Date and Timestamp predicates
dateBefore = Predicates::date_before('my.product.releaseDate', Time.new(2014, 6, 1))
dateAfter = Predicates::date_after('my.product.releaseDate', Time.new(2014, 1, 1))
dateBetween = Predicates::date_between('my.product.releaseDate', Time.new(2014, 1, 1), Time.new(2014, 6, 1))
dayOfMonth = Predicates::day_of_month('my.product.releaseDate', 14)
dayOfMonthAfter = Predicates::day_of_month_after('my.product.releaseDate', 14)
dayOfMonthBefore = Predicates::day_of_month_before('my.product.releaseDate', 14)
dayOfWeek = Predicates::day_of_week('my.product.releaseDate', 'Tuesday')
dayOfWeekAfter = Predicates::day_of_week_after('my.product.releaseDate', 'Wednesday')
dayOfWeekBefore = Predicates::day_of_week_before('my.product.releaseDate', 'Wednesday')
month = Predicates::month('my.product.releaseDate', 'June')
monthBefore = Predicates::month_before('my.product.releaseDate', 'June')
monthAfter = Predicates::month_after('my.product.releaseDate', 'June')
year = Predicates::year('my.product.releaseDate', 2014)
hour = Predicates::hour('my.product.releaseDate', 12)
hourBefore = Predicates::hour_before('my.product.releaseDate', 12)
hourAfter = Predicates::hour_after('my.product.releaseDate', 12)
# Accessing Date and Timestamp fields
date = doc.get_date('blog-post.date').value
date_year = date ? date.year : nil
update_time = doc.get_timestamp('blog-post.update')
update_hour = update_time ? update_time.value.hour : nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment