Dates and Times

Date and time logic has a well-deserved reputation as some of the most complex and irritating logic in any application. Testing calendar logic—including time-based reports, automatic logouts, and “1 day ago” text displays—can be a particular headache, but you can do a couple of things to simplify the time-logic beast.

Part of the Problem

We have a YAML file with some projects:

​ 
runway:
 name: Project Runway
​ 
start_date: ​2015-01-20​
​ 
​ 
greenlight:
 name: Project Greenlight
​ 
start_date: ​2015-02-04​
​ 
​ 
gutenberg:
 name: Project Gutenberg
​ 
start_date: ​2015-01-31​

We’d like to test some time-based code that might be used in a search or report result; this goes in test/unit/project_test.rb ...

Get Rails 4 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.