smart_month 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +33 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/month.rb +26 -0
- data/lib/smart_month.rb +11 -0
- data/lib/smart_month/calculations.rb +87 -0
- data/lib/smart_month/collection.rb +51 -0
- data/lib/smart_month/extensions/date.rb +19 -0
- data/lib/smart_month/magic.rb +71 -0
- data/lib/smart_month/math.rb +41 -0
- data/lib/smart_month/rulesets.rb +151 -0
- data/lib/smart_month/util.rb +37 -0
- data/pkg/smart_month-1.0.0.gem +0 -0
- data/rdoc/classes/Date.html +209 -0
- data/rdoc/classes/Month.html +189 -0
- data/rdoc/classes/SmartMonth.html +136 -0
- data/rdoc/classes/SmartMonth/Calculations.html +383 -0
- data/rdoc/classes/SmartMonth/Collection.html +306 -0
- data/rdoc/classes/SmartMonth/Magic.html +214 -0
- data/rdoc/classes/SmartMonth/Magic/MonthFactory.html +178 -0
- data/rdoc/classes/SmartMonth/Math.html +311 -0
- data/rdoc/classes/SmartMonth/Rulesets.html +419 -0
- data/rdoc/classes/SmartMonth/Util.html +302 -0
- data/rdoc/classes/Time.html +152 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README.html +170 -0
- data/rdoc/files/lib/month_rb.html +113 -0
- data/rdoc/files/lib/smart_month/calculations_rb.html +101 -0
- data/rdoc/files/lib/smart_month/collection_rb.html +101 -0
- data/rdoc/files/lib/smart_month/extensions/date_rb.html +108 -0
- data/rdoc/files/lib/smart_month/magic_rb.html +101 -0
- data/rdoc/files/lib/smart_month/math_rb.html +101 -0
- data/rdoc/files/lib/smart_month/rulesets_rb.html +108 -0
- data/rdoc/files/lib/smart_month/util_rb.html +101 -0
- data/rdoc/files/lib/smart_month_rb.html +108 -0
- data/rdoc/fr_class_index.html +37 -0
- data/rdoc/fr_file_index.html +36 -0
- data/rdoc/fr_method_index.html +74 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/smart_month.gemspec +179 -0
- data/test/spec/date/accessor_spec.rb +91 -0
- data/test/spec/date/add_month_spec.rb +24 -0
- data/test/spec/date/add_spec.rb +23 -0
- data/test/spec/date/boat_spec.rb +20 -0
- data/test/spec/date/civil_spec.rb +28 -0
- data/test/spec/date/commercial_spec.rb +29 -0
- data/test/spec/date/constants_spec.rb +41 -0
- data/test/spec/date/conversions_spec.rb +153 -0
- data/test/spec/date/downto_spec.rb +18 -0
- data/test/spec/date/eql_spec.rb +10 -0
- data/test/spec/date/gregorian_spec.rb +28 -0
- data/test/spec/date/hash_spec.rb +14 -0
- data/test/spec/date/infinity_spec.rb +77 -0
- data/test/spec/date/julian_spec.rb +52 -0
- data/test/spec/date/minus_month_spec.rb +23 -0
- data/test/spec/date/minus_spec.rb +30 -0
- data/test/spec/date/new_spec.rb +9 -0
- data/test/spec/date/neww_spec.rb +9 -0
- data/test/spec/date/ordinal_spec.rb +29 -0
- data/test/spec/date/parse_spec.rb +149 -0
- data/test/spec/date/relationship_spec.rb +20 -0
- data/test/spec/date/shared/civil.rb +66 -0
- data/test/spec/date/shared/commercial.rb +39 -0
- data/test/spec/date/shared/parse.rb +54 -0
- data/test/spec/date/shared/parse_eu.rb +30 -0
- data/test/spec/date/shared/parse_us.rb +29 -0
- data/test/spec/date/step_spec.rb +56 -0
- data/test/spec/date/strftime_spec.rb +205 -0
- data/test/spec/date/strptime_spec.rb +143 -0
- data/test/spec/date/upto_spec.rb +18 -0
- data/test/spec/parsedate/parsedate.rb +95 -0
- data/test/spec/time/httpdate_spec.rb +21 -0
- data/test/spec/time/iso8601_spec.rb +7 -0
- data/test/spec/time/rfc2822_spec.rb +7 -0
- data/test/spec/time/rfc822_spec.rb +7 -0
- data/test/spec/time/shared/rfc2822.rb +65 -0
- data/test/spec/time/shared/xmlschema.rb +53 -0
- data/test/spec/time/xmlschema_spec.rb +7 -0
- data/test/spec_helper.rb +56 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/calculations_test.rb +82 -0
- data/test/unit/collection_test.rb +42 -0
- data/test/unit/magic_test.rb +37 -0
- data/test/unit/math_test.rb +30 -0
- data/test/unit/rulesets_test.rb +94 -0
- data/test/unit/samples/test_ruleset.yml +6 -0
- data/test/unit/util_test.rb +29 -0
- metadata +196 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#downto" do
|
5
|
+
|
6
|
+
it "should be able to step backward in time" do
|
7
|
+
ds = Date.civil(2000, 4, 14)
|
8
|
+
de = Date.civil(2000, 3, 29)
|
9
|
+
count = 0
|
10
|
+
ds.step(de, -1) do |d|
|
11
|
+
d.should <= ds
|
12
|
+
d.should >= de
|
13
|
+
count += 1
|
14
|
+
end
|
15
|
+
count.should == 17
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#eql?" do
|
5
|
+
it "should be able determine equality between date objects" do
|
6
|
+
Date.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 11))
|
7
|
+
Date.civil(2007, 10, 11).should eql(Date.civil(2007, 10, 12) - 1)
|
8
|
+
Date.civil(2007, 10, 11).should_not eql(Date.civil(2007, 10, 12))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#gregorian?" do
|
5
|
+
|
6
|
+
it "should mark a day before the calendar reform as Julian" do
|
7
|
+
Date.civil(1007, 2, 27).gregorian?.should == false
|
8
|
+
Date.civil(1907, 2, 27, Date.civil(2000, 1, 1).jd).gregorian?.should == false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should mark a day after the calendar reform as Julian" do
|
12
|
+
Date.civil(2007, 2, 27).gregorian?.should == true
|
13
|
+
Date.civil(1007, 2, 27, Date.civil(1000, 1, 1).jd).gregorian?.should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "Date#gregorian_leap?" do
|
19
|
+
|
20
|
+
it "should be able to determine whether a year is a leap year in the Gregorian calendar" do
|
21
|
+
Date.gregorian_leap?(1900).should == false
|
22
|
+
Date.gregorian_leap?(1999).should == false
|
23
|
+
Date.gregorian_leap?(2000).should == true
|
24
|
+
Date.gregorian_leap?(2002).should == false
|
25
|
+
Date.gregorian_leap?(2004).should == true
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#hash" do
|
5
|
+
|
6
|
+
it "should be able determine the hash value for a date" do
|
7
|
+
Date.civil(2004, 7, 12).respond_to?(:hash).should == true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be the case that the same date results in the same hash" do
|
11
|
+
Date.civil(2004, 7, 12).hash.should == Date.civil(2004, 7, 12).hash
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date::Infinity" do
|
5
|
+
|
6
|
+
it "should be able to check whether Infinity is zero" do
|
7
|
+
i = Date::Infinity.new
|
8
|
+
i.zero?.should == false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be able to check whether Infinity is finite" do
|
12
|
+
i1 = Date::Infinity.new
|
13
|
+
i1.finite?.should == false
|
14
|
+
i2 = Date::Infinity.new(-1)
|
15
|
+
i2.finite?.should == false
|
16
|
+
i3 = Date::Infinity.new(0)
|
17
|
+
i3.finite?.should == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to check whether Infinity is infinite" do
|
21
|
+
i1 = Date::Infinity.new
|
22
|
+
i1.infinite?.should == 1
|
23
|
+
i2 = Date::Infinity.new(-1)
|
24
|
+
i2.infinite?.should == -1
|
25
|
+
i3 = Date::Infinity.new(0)
|
26
|
+
i3.infinite?.should == nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be able to check whether Infinity is not a number" do
|
30
|
+
i1 = Date::Infinity.new
|
31
|
+
i1.nan?.should == false
|
32
|
+
i2 = Date::Infinity.new(-1)
|
33
|
+
i2.nan?.should == false
|
34
|
+
i3 = Date::Infinity.new(0)
|
35
|
+
i3.nan?.should == true
|
36
|
+
end
|
37
|
+
|
38
|
+
# These checks fail on MRI because of a bug in Date::Infinity#<=>
|
39
|
+
# Fixed in 1.8.7
|
40
|
+
ruby_bug "#", "1.8.6" do
|
41
|
+
it "should be able to compare Infinity objects" do
|
42
|
+
i1 = Date::Infinity.new
|
43
|
+
i2 = Date::Infinity.new(-1)
|
44
|
+
i3 = Date::Infinity.new(0)
|
45
|
+
i4 = Date::Infinity.new
|
46
|
+
(i4 <=> i1).should == 0
|
47
|
+
(i3 <=> i1).should == -1
|
48
|
+
(i2 <=> i1).should == -1
|
49
|
+
(i3 <=> i2).should == 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Also fails because of the same bug as the previous spec
|
54
|
+
# Fixed in 1.8.7
|
55
|
+
ruby_bug "#", "1.8.6" do
|
56
|
+
it "should be able to return plus Infinity for abs" do
|
57
|
+
i1 = Date::Infinity.new
|
58
|
+
i2 = Date::Infinity.new(-1)
|
59
|
+
i3 = Date::Infinity.new(0)
|
60
|
+
(i2.abs <=> i1).should == 0
|
61
|
+
(i3.abs <=> i1).should == 0
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
ruby_bug "#222", "1.8.6" do
|
66
|
+
it "should be able to use -@ and +@ for Date::Infinity" do
|
67
|
+
(Date::Infinity.new <=> +Date::Infinity.new).should == 0
|
68
|
+
(Date::Infinity.new(-1) <=> -Date::Infinity.new).should == 0
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should be able to coerce a Date::Infinity object" do
|
73
|
+
Date::Infinity.new.coerce(1).should == [-1, 1]
|
74
|
+
Date::Infinity.new(0).coerce(2).should == [0, 0]
|
75
|
+
Date::Infinity.new(-1).coerce(1.5).should == [1, -1]
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#jd" do
|
5
|
+
|
6
|
+
it "should be able to construct a Date object based on the Julian day" do
|
7
|
+
Date.jd(2454482).should == Date.civil(2008, 1, 16)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able to determine the Julian day for a Date object" do
|
11
|
+
Date.civil(2008, 1, 16).jd.should == 2454482
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "Date#julian?" do
|
17
|
+
|
18
|
+
it "should mark a day before the calendar reform as Julian" do
|
19
|
+
Date.civil(1007, 2, 27).julian?.should == true
|
20
|
+
Date.civil(1907, 2, 27, Date.civil(2000, 1, 1).jd).julian?.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should mark a day after the calendar reform as Julian" do
|
24
|
+
Date.civil(2007, 2, 27).julian?.should == false
|
25
|
+
Date.civil(1007, 2, 27, Date.civil(1000, 1, 1).jd).julian?.should == false
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "Date#julian_leap?" do
|
31
|
+
|
32
|
+
it "should be able to determine whether a year is a leap year in the Julian calendar" do
|
33
|
+
Date.julian_leap?(1900).should == true
|
34
|
+
Date.julian_leap?(1999).should == false
|
35
|
+
Date.julian_leap?(2000).should == true
|
36
|
+
Date.julian_leap?(2002).should == false
|
37
|
+
Date.julian_leap?(2004).should == true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "Date#valid_jd?" do
|
43
|
+
|
44
|
+
it "should be able to determine if a day number is a valid Julian day number, true for all numbers" do
|
45
|
+
# This might need to check the type of the jd parameter. Date.valid_jd?(:number) is of course
|
46
|
+
# bogus but returns itself with the current implementation
|
47
|
+
Date.valid_jd?(-100).should == -100
|
48
|
+
Date.valid_jd?(0).should == 0
|
49
|
+
Date.valid_jd?(100).should == 100
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#<<" do
|
5
|
+
|
6
|
+
it "should substract a number of months from a date" do
|
7
|
+
d = Date.civil(2007,2,27) << 10
|
8
|
+
d.should == Date.civil(2006, 4, 27)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should result in the last day of a month if the day doesn't exist" do
|
12
|
+
d = Date.civil(2008,3,31) << 1
|
13
|
+
d.should == Date.civil(2008, 2, 29)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise an error on non numeric parameters" do
|
17
|
+
lambda { Date.civil(2007,2,27) << :hello }.should raise_error(NoMethodError)
|
18
|
+
lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(NoMethodError)
|
19
|
+
lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(NoMethodError)
|
20
|
+
lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(NoMethodError)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
|
4
|
+
describe "Date#-" do
|
5
|
+
|
6
|
+
it "should substract a number of days from a Date" do
|
7
|
+
d = Date.civil(2007, 5 ,2) - 13
|
8
|
+
d.should == Date.civil(2007, 4, 19)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should substract a negative number of days from a Date" do
|
12
|
+
d = Date.civil(2007, 4, 19).-(-13)
|
13
|
+
d.should == Date.civil(2007, 5 ,2)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should be able to compute the different between two dates" do
|
17
|
+
(Date.civil(2007,2,27) - Date.civil(2007,2,27)).should == 0
|
18
|
+
(Date.civil(2007,2,27) - Date.civil(2007,2,26)).should == 1
|
19
|
+
(Date.civil(2006,2,27) - Date.civil(2007,2,27)).should == -365
|
20
|
+
(Date.civil(2008,2,27) - Date.civil(2007,2,27)).should == 365
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise an error on non numeric parameters" do
|
25
|
+
lambda { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError)
|
26
|
+
lambda { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
|
27
|
+
lambda { Date.civil(2007,2,27) - Object.new }.should raise_error(TypeError)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'date'
|
2
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
3
|
+
require File.dirname(__FILE__) + '/shared/commercial'
|
4
|
+
|
5
|
+
describe "Date#ordinal" do
|
6
|
+
|
7
|
+
it "should be able to construct a Date object from an ordinal date" do
|
8
|
+
lambda { Date.ordinal(1582, 287) }.should raise_error(ArgumentError)
|
9
|
+
Date.ordinal(1582, 288).should == Date.civil(1582, 10, 15)
|
10
|
+
Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "Date#valid_ordinal?" do
|
16
|
+
|
17
|
+
it "should be able to determine if the date is a valid ordinal date" do
|
18
|
+
Date.valid_ordinal?(1582, 287).should == nil
|
19
|
+
Date.valid_ordinal?(1582, 288).should == Date.civil(1582, 10, 15).jd
|
20
|
+
Date.valid_ordinal?(1582, 287, Date::ENGLAND).should_not == nil
|
21
|
+
Date.valid_ordinal?(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND).jd
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should be able to handle negative day numbers" do
|
25
|
+
Date.valid_ordinal?(1582, -79).should == nil
|
26
|
+
Date.valid_ordinal?(2007, -100).should == Date.valid_ordinal?(2007, 266)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
require File.dirname(__FILE__) + '/shared/parse'
|
3
|
+
require File.dirname(__FILE__) + '/shared/parse_us'
|
4
|
+
require File.dirname(__FILE__) + '/shared/parse_eu'
|
5
|
+
require 'date'
|
6
|
+
|
7
|
+
describe "Date#parse" do
|
8
|
+
# The space separator is also different, doesn't work for only numbers
|
9
|
+
it "can parse a day name into a Date object" do
|
10
|
+
d = Date.parse("friday")
|
11
|
+
d.should == Date.commercial(d.cwyear, d.cweek, 5)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can parse a month name into a Date object" do
|
15
|
+
d = Date.parse("october")
|
16
|
+
d.should == Date.civil(Date.today.year, 10)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can parse a month day into a Date object" do
|
20
|
+
d = Date.parse("5th")
|
21
|
+
d.should == Date.civil(Date.today.year, Date.today.month, 5)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Specs using numbers
|
25
|
+
it "can't handle a single digit" do
|
26
|
+
lambda{ Date.parse("1") }.should raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "can handle DD as month day number" do
|
30
|
+
d = Date.parse("10")
|
31
|
+
d.should == Date.civil(Date.today.year, Date.today.month, 10)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "can handle DDD as year day number" do
|
35
|
+
d = Date.parse("100")
|
36
|
+
if Date.gregorian_leap?(Date.today.year)
|
37
|
+
d.should == Date.civil(Date.today.year, 4, 9)
|
38
|
+
else
|
39
|
+
d.should == Date.civil(Date.today.year, 4, 10)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can handle MMDD as month and day" do
|
44
|
+
d = Date.parse("1108")
|
45
|
+
d.should == Date.civil(Date.today.year, 11, 8)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "can handle YYDDD as year and day number" do
|
49
|
+
d = Date.parse("10100")
|
50
|
+
d.should == Date.civil(10, 4, 10)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can handle YYMMDD as year month and day" do
|
54
|
+
d = Date.parse("201023")
|
55
|
+
d.should == Date.civil(20, 10, 23)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "can handle YYYYDDD as year and day number" do
|
59
|
+
d = Date.parse("1910100")
|
60
|
+
d.should == Date.civil(1910, 4, 10)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can handle YYYYMMDD as year and day number" do
|
64
|
+
d = Date.parse("19101101")
|
65
|
+
d.should == Date.civil(1910, 11, 1)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "Date#parse with '.' separator" do
|
70
|
+
before :all do
|
71
|
+
@sep = '.'
|
72
|
+
end
|
73
|
+
|
74
|
+
it_should_behave_like "date_parse"
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "Date#parse with '/' separator" do
|
78
|
+
before :all do
|
79
|
+
@sep = '/'
|
80
|
+
end
|
81
|
+
|
82
|
+
it_should_behave_like "date_parse"
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Date#parse with ' ' separator" do
|
86
|
+
before :all do
|
87
|
+
@sep = ' '
|
88
|
+
end
|
89
|
+
|
90
|
+
it_should_behave_like "date_parse"
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "Date#parse with '/' separator US-style" do
|
94
|
+
before :all do
|
95
|
+
@sep = '/'
|
96
|
+
end
|
97
|
+
|
98
|
+
it_should_behave_like "date_parse_us"
|
99
|
+
end
|
100
|
+
|
101
|
+
ruby_version_is "" ... "1.8.7" do
|
102
|
+
describe "Date#parse with '.' separator US-style" do
|
103
|
+
before :all do
|
104
|
+
@sep = '.'
|
105
|
+
end
|
106
|
+
|
107
|
+
it_should_behave_like "date_parse_us"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "Date#parse with '-' separator EU-style" do
|
112
|
+
before :all do
|
113
|
+
@sep = '-'
|
114
|
+
end
|
115
|
+
|
116
|
+
it_should_behave_like "date_parse_eu"
|
117
|
+
end
|
118
|
+
|
119
|
+
ruby_version_is "1.8.7" do
|
120
|
+
describe "Date#parse(.)" do
|
121
|
+
it "parses a YYYY.MM.DD string into a Date object" do
|
122
|
+
d = Date.parse("2007.10.01")
|
123
|
+
d.year.should == 2007
|
124
|
+
d.month.should == 10
|
125
|
+
d.day.should == 1
|
126
|
+
end
|
127
|
+
|
128
|
+
it "parses a DD.MM.YYYY string into a Date object" do
|
129
|
+
d = Date.parse("10.01.2007")
|
130
|
+
d.year.should == 2007
|
131
|
+
d.month.should == 1
|
132
|
+
d.day.should == 10
|
133
|
+
end
|
134
|
+
|
135
|
+
it "parses a YY.MM.DD string into a Date object" do
|
136
|
+
d = Date.parse("10.01.07")
|
137
|
+
d.year.should == 10
|
138
|
+
d.month.should == 1
|
139
|
+
d.day.should == 7
|
140
|
+
end
|
141
|
+
|
142
|
+
it "parses a YY.MM.DD string into a Date object using the year digits as 20XX" do
|
143
|
+
d = Date.parse("10.01.07", true)
|
144
|
+
d.year.should == 2010
|
145
|
+
d.month.should == 1
|
146
|
+
d.day.should == 7
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|