Permalink
Browse files

added days_from_today and days_ago to Fixnum

  • Loading branch information...
cheezy committed Dec 29, 2012
1 parent 235f052 commit 42afa9e63a577099fe228b6138c7c0c3a21fdd8c
View
@@ -3,6 +3,8 @@
* Added today translator
* Added tomorrow translator
* Added yesterday translator
+ * Added days_from_today to Fixnum to provide translator
+ * Added days_ago to Fixnum to provide translator
=== Version 0.11 / 2012-12-22
* Enhancements
@@ -88,4 +88,6 @@ Feature: Functionality of the data_magic gem
And the value for "tomorrow" should be tomorrow's date
And the value for "yesterday" should be yesterday's date
-
+ Scenario: Specifying number of days from today
+ Then the value for "5daysfromtoday" should be five days from today
+ And the value for "5daysago" should be five days ago
@@ -87,3 +87,13 @@ class TestClass
yesterday = Date.today - 1
@data[key].should == yesterday.strftime('%D')
end
+
+Then /^the value for "(.*?)" should be five days from today$/ do |key|
+ the_day = Date.today + 5
+ @data[key].should == the_day.strftime('%D')
+end
+
+Then /^the value for "(.*?)" should be five days ago$/ do |key|
+ the_day = Date.today - 5
+ @data[key].should == the_day.strftime('%D')
+end
@@ -37,6 +37,8 @@ dm:
today: ~today
tomorrow: ~tomorrow
yesterday: ~yesterday
+ 5daysfromtoday: ~5.days_from_today
+ 5daysago: ~5.days_ago
other:
name: Cheezy
View
@@ -1,4 +1,5 @@
require 'data_magic/core_ext/string'
+require 'data_magic/core_ext/fixnum'
require "data_magic/version"
require "data_magic/translation"
require "data_magic/date_translation"
@@ -0,0 +1,11 @@
+class Fixnum
+ def days_from_today(format = '%D')
+ the_day = Date.today + self
+ the_day.strftime(format)
+ end
+
+ def days_ago(format = '%D')
+ the_day = Date.today - self
+ the_day.strftime(format)
+ end
+end
@@ -249,5 +249,36 @@ def set_field_value(value)
example.data_for('key').should have_field_value false
end
end
+
+ context "providing date values" do
+ it "should provide today's date" do
+ set_field_value '~today'
+ example.data_for('key').should have_field_value Date.today.strftime('%D')
+ end
+
+ it "should provide tomorrow's date" do
+ set_field_value '~tomorrow'
+ tomorrow = Date.today + 1
+ example.data_for('key').should have_field_value tomorrow.strftime('%D')
+ end
+
+ it "should provide yesterday's date" do
+ set_field_value '~yesterday'
+ yesterday = Date.today - 1
+ example.data_for('key').should have_field_value yesterday.strftime('%D')
+ end
+
+ it "should provide a date that is some number of days from now" do
+ set_field_value '~5.days_from_today'
+ the_date = Date.today + 5
+ example.data_for('key').should have_field_value the_date.strftime('%D')
+ end
+
+ it "should provide a date that is some number of days ago" do
+ set_field_value '~5.days_ago'
+ the_date = Date.today - 5
+ example.data_for('key').should have_field_value the_date.strftime('%D')
+ end
+ end
end
end

0 comments on commit 42afa9e

Please sign in to comment.