spec/date_range_spec.rb in appstats-0.11.7 vs spec/date_range_spec.rb in appstats-0.12.1
- old
+ new
@@ -30,10 +30,11 @@
date_range.should == date_range
date_range.should == same_date_range
date_range.should_not == another_date_range
end
+
end
describe "#parse" do
it "should understand nil" do
@@ -87,19 +88,19 @@
it "should understand this year" do
DateRange.parse(" this year ").should == DateRange.new(:from => EntryDate.new(:year => 2010), :to => nil, :format => :fixed_point )
end
it "should understand this quarter" do
- DateRange.parse(" this quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1), :to => nil, :format => :inclusive )
+ DateRange.parse(" this quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :quarter => 1), :to => nil, :format => :fixed_point )
end
it "should understand this month" do
DateRange.parse(" this month ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1), :to => nil, :format => :fixed_point )
end
it "should understand this week" do
- DateRange.parse(" this week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 11), :to => nil, :format => :inclusive )
+ DateRange.parse(" this week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 11, :week => 2), :to => nil, :format => :fixed_point )
end
it "should understand this day" do
DateRange.parse(" this day ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 15), :to => nil, :format => :fixed_point )
end
@@ -111,19 +112,19 @@
it "should understand last year" do
DateRange.parse(" last year ").should == DateRange.new(:from => EntryDate.new(:year => 2009), :to => nil, :format => :fixed_point )
end
it "should understand last quarter" do
- DateRange.parse(" last quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
+ DateRange.parse(" last quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :quarter => 4), :to => nil, :format => :fixed_point )
end
it "should understand last month" do
DateRange.parse(" last month ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12), :to => nil, :format => :fixed_point )
end
it "should understand last week" do
- DateRange.parse(" last week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10), :format => :inclusive )
+ DateRange.parse(" last week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4, :week => 1), :to => nil, :format => :fixed_point )
end
it "should understand last day" do
DateRange.parse(" last day ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 14), :to => nil, :format => :fixed_point )
end
@@ -135,11 +136,11 @@
it "should understand previous month" do
DateRange.parse(" previous month ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12), :to => nil, :format => :fixed_point )
end
it "should understand previous week" do
- DateRange.parse(" previous week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10), :format => :inclusive )
+ DateRange.parse(" previous week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4, :week => 1), :to => nil, :format => :fixed_point )
end
it "should understand previous day" do
DateRange.parse(" previous day ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 14), :to => nil, :format => :fixed_point )
end
@@ -153,25 +154,25 @@
DateRange.parse(" last 2 years ").should == DateRange.new(:from => EntryDate.new(:year => 2009), :to => nil, :format => :inclusive )
DateRange.parse(" last 3 years ").should == DateRange.new(:from => EntryDate.new(:year => 2008), :to => nil, :format => :inclusive )
end
it "should understand last X quarters" do
- DateRange.parse(" last 1 quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1), :to => nil, :format => :inclusive )
- DateRange.parse(" last 2 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => nil, :format => :inclusive )
- DateRange.parse(" last 3 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 7), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 1 quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :quarter => 1), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 2 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :quarter => 4), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 3 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 7, :quarter => 3), :to => nil, :format => :inclusive )
end
it "should understand last X months" do
DateRange.parse(" last 1 month ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1), :to => nil, :format => :inclusive )
DateRange.parse(" last 2 months ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12), :to => nil, :format => :inclusive )
DateRange.parse(" last 3 months ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 11), :to => nil, :format => :inclusive )
end
it "should understand last X weeks" do
- DateRange.parse(" last 1 week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 11), :to => nil, :format => :inclusive )
- DateRange.parse(" last 2 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4), :to => nil, :format => :inclusive )
- DateRange.parse(" last 3 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 28), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 1 week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 11, :week => 2), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 2 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4, :week => 1), :to => nil, :format => :inclusive )
+ DateRange.parse(" last 3 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 28, :week => 52), :to => nil, :format => :inclusive )
end
it "should understand last X days" do
DateRange.parse(" last 1 day ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 15), :to => nil, :format => :inclusive )
DateRange.parse(" last 2 days ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 14), :to => nil, :format => :inclusive )
@@ -187,25 +188,25 @@
DateRange.parse(" previous 2 years ").should == DateRange.new(:from => EntryDate.new(:year => 2008), :to => EntryDate.new(:year => 2009), :format => :inclusive )
DateRange.parse(" previous 3 years ").should == DateRange.new(:from => EntryDate.new(:year => 2007), :to => EntryDate.new(:year => 2009), :format => :inclusive )
end
it "should understand previous Y quarters" do
- DateRange.parse(" previous 1 quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
- DateRange.parse(" previous 2 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 7), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
- DateRange.parse(" previous 3 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 4), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
+ DateRange.parse(" previous 1 quarter ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :quarter => 4), :to => EntryDate.new(:year => 2009, :month => 12, :quarter => 4), :format => :inclusive )
+ DateRange.parse(" previous 2 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 7, :quarter => 3), :to => EntryDate.new(:year => 2009, :month => 12, :quarter => 4), :format => :inclusive )
+ DateRange.parse(" previous 3 quarters ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 4, :quarter => 2), :to => EntryDate.new(:year => 2009, :month => 12, :quarter => 4), :format => :inclusive )
end
it "should understand previous Y months" do
DateRange.parse(" previous 1 month ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
DateRange.parse(" previous 2 months ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 11), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
DateRange.parse(" previous 3 months ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => EntryDate.new(:year => 2009, :month => 12), :format => :inclusive )
end
it "should understand previous 2 weeks" do
- DateRange.parse(" previous 1 week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10), :format => :inclusive )
- DateRange.parse(" previous 2 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 28), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10), :format => :inclusive )
- DateRange.parse(" previous 3 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 21), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10), :format => :inclusive )
+ DateRange.parse(" previous 1 week ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 4, :week => 1), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10, :week => 1), :format => :inclusive )
+ DateRange.parse(" previous 2 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 28, :week => 52), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10, :week => 1), :format => :inclusive )
+ DateRange.parse(" previous 3 weeks ").should == DateRange.new(:from => EntryDate.new(:year => 2009, :month => 12, :day => 21, :week => 51), :to => EntryDate.new(:year => 2010, :month => 1, :day => 10, :week => 1), :format => :inclusive )
end
it "should understand previous 2 days" do
DateRange.parse(" previous 1 day ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 14), :to => EntryDate.new(:year => 2010, :month => 1, :day => 14), :format => :inclusive )
DateRange.parse(" previous 2 days ").should == DateRange.new(:from => EntryDate.new(:year => 2010, :month => 1, :day => 13), :to => EntryDate.new(:year => 2010, :month => 1, :day => 14), :format => :inclusive )
@@ -264,10 +265,19 @@
it "should be based on end_of time as-is for exclusive" do
DateRange.new(:from => EntryDate.new(:year => 2009), :format => :exclusive).from_date.to_s.should == Time.parse("2009-12-31 23:59:59").to_s
DateRange.new(:from => EntryDate.new(:year => 2009, :month => 2), :format => :exclusive).from_date.to_s.should == Time.parse("2009-02-28 23:59:59").to_s
DateRange.new(:from => EntryDate.new(:year => 2009, :month => 2, :day => 15), :format => :exclusive).from_date.to_s.should == Time.parse("2009-02-15 23:59:59").to_s
end
+
+ it "should handle fixed points" do
+ DateRange.new(:from => EntryDate.new(:year => 2009), :to => nil, :format => :fixed_point ).from_date.to_s.should == Time.parse("2009-01-01 00:00:00").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :quarter => 4), :to => nil, :format => :fixed_point ).from_date.to_s.should == Time.parse("2009-10-01 00:00:00").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :day => 2, :week => 39), :to => nil, :format => :fixed_point ).from_date.to_s.should == Time.parse("2009-09-28 00:00:00").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => nil, :format => :fixed_point ).from_date.to_s.should == Time.parse("2009-10-01 00:00:00").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :day => 3), :to => nil, :format => :fixed_point ).from_date.to_s.should == Time.parse("2009-10-03 00:00:00").to_s
+ DateRange.new(:from => nil, :to => nil, :format => :fixed_point ).from_date.should == nil
+ end
end
describe "#to_date" do
it "should handle nil" do
@@ -282,9 +292,18 @@
DateRange.new(:to => EntryDate.new(:year => 2009), :format => :inclusive).to_date.to_s.should == Time.parse("2009-12-31 23:59:59").to_s
DateRange.new(:to => EntryDate.new(:year => 2009, :month => 2), :format => :inclusive).to_date.to_s.should == Time.parse("2009-02-28 23:59:59").to_s
DateRange.new(:to => EntryDate.new(:year => 2009, :month => 2, :day => 15), :format => :inclusive).to_date.to_s.should == Time.parse("2009-02-15 23:59:59").to_s
end
+ it "should handle fixed points" do
+ DateRange.new(:from => EntryDate.new(:year => 2009), :to => nil, :format => :fixed_point ).to_date.to_s.should == Time.parse("2009-12-31 23:59:59").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10), :to => nil, :format => :fixed_point ).to_date.to_s.should == Time.parse("2009-10-31 23:59:59").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :quarter => 4), :to => nil, :format => :fixed_point ).to_date.to_s.should == Time.parse("2009-12-31 23:59:59").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :day => 2, :week => 39), :to => nil, :format => :fixed_point ).to_date.to_s.should == Time.parse("2009-10-04 23:59:59").to_s
+ DateRange.new(:from => EntryDate.new(:year => 2009, :month => 10, :day => 3), :to => nil, :format => :fixed_point ).to_date.to_s.should == Time.parse("2009-10-03 23:59:59").to_s
+
+ DateRange.new(:from => nil, :to => nil, :format => :fixed_point ).to_date.should == nil
+ end
end
describe "#to_sql" do
\ No newline at end of file