home_run 0.9.3-x86-mingw32 → 0.9.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +4 -0
  2. data/README.rdoc +0 -1
  3. data/ext/date_ext/date_ext.c +192 -191
  4. data/ext/date_ext/datetime.c +12 -11
  5. data/lib/1.8/date_ext.so +0 -0
  6. data/lib/1.9/date_ext.so +0 -0
  7. data/spec/date/add_month_spec.rb +5 -0
  8. data/spec/date/add_spec.rb +5 -0
  9. data/spec/date/civil_spec.rb +5 -1
  10. data/spec/date/commercial_spec.rb +5 -0
  11. data/spec/date/conversions_spec.rb +10 -0
  12. data/spec/date/downto_spec.rb +6 -0
  13. data/spec/date/julian_spec.rb +10 -0
  14. data/spec/date/minus_month_spec.rb +5 -0
  15. data/spec/date/minus_spec.rb +5 -0
  16. data/spec/date/next_prev_spec.rb +30 -1
  17. data/spec/date/ordinal_spec.rb +5 -0
  18. data/spec/date/parse_spec.rb +6 -0
  19. data/spec/date/parsing_spec.rb +11 -0
  20. data/spec/date/step_spec.rb +6 -0
  21. data/spec/date/strptime_spec.rb +6 -0
  22. data/spec/date/succ_spec.rb +5 -0
  23. data/spec/date/today_spec.rb +5 -0
  24. data/spec/date/upto_spec.rb +7 -0
  25. data/spec/datetime/add_month_spec.rb +5 -0
  26. data/spec/datetime/add_spec.rb +5 -0
  27. data/spec/datetime/constructor_spec.rb +10 -0
  28. data/spec/datetime/conversions_spec.rb +5 -0
  29. data/spec/datetime/downto_spec.rb +6 -0
  30. data/spec/datetime/minus_month_spec.rb +5 -2
  31. data/spec/datetime/minus_spec.rb +5 -0
  32. data/spec/datetime/next_prev_spec.rb +30 -0
  33. data/spec/datetime/now_spec.rb +5 -0
  34. data/spec/datetime/parse_spec.rb +6 -0
  35. data/spec/datetime/parsing_spec.rb +11 -0
  36. data/spec/datetime/step_spec.rb +6 -0
  37. data/spec/datetime/strptime_spec.rb +6 -0
  38. data/spec/datetime/succ_spec.rb +5 -0
  39. data/spec/datetime/upto_spec.rb +6 -0
  40. metadata +4 -4
@@ -307,11 +307,11 @@ void rhrdt__now(rhrdt_t * dt) {
307
307
  * the number per day by subtracting from or adding to the jd.
308
308
  * It should ensure that the stored nanos value is in the range
309
309
  * [0, RHR_NANOS_PER_DAY). */
310
- VALUE rhrdt__from_jd_nanos(long jd, long long nanos, short offset) {
310
+ VALUE rhrdt__from_jd_nanos(VALUE klass, long jd, long long nanos, short offset) {
311
311
  long t;
312
312
  rhrdt_t *dt;
313
313
  VALUE new;
314
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, dt);
314
+ new = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
315
315
 
316
316
  if (nanos < 0) {
317
317
  t = (long)(nanos/RHR_NANOS_PER_DAY - 1);
@@ -363,7 +363,7 @@ VALUE rhrdt__add_days(VALUE self, double n) {
363
363
  RHRDT_FILL_NANOS(dt)
364
364
  l = (long)floor(n);
365
365
  nanos = llround((n - l) * RHR_NANOS_PER_DAY);
366
- return rhrdt__from_jd_nanos(rhrd__safe_add_long(dt->jd, l), dt->nanos + nanos, dt->offset);
366
+ return rhrdt__from_jd_nanos(rb_obj_class(self), rhrd__safe_add_long(dt->jd, l), dt->nanos + nanos, dt->offset);
367
367
  }
368
368
 
369
369
  /* Similar to rhrd__add_months, but for ruby DateTime
@@ -375,7 +375,7 @@ VALUE rhrdt__add_months(VALUE self, long n) {
375
375
  long x;
376
376
  Data_Get_Struct(self, rhrdt_t, d);
377
377
 
378
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, newd);
378
+ new = Data_Make_Struct(rb_obj_class(self), rhrdt_t, NULL, -1, newd);
379
379
  RHRDT_FILL_CIVIL(d)
380
380
  memcpy(newd, d, sizeof(rhrdt_t));
381
381
 
@@ -509,7 +509,7 @@ VALUE rhrdt__new_offset(VALUE self, double offset) {
509
509
  Data_Get_Struct(self, rhrdt_t, dt);
510
510
  RHRDT_FILL_JD(dt)
511
511
  RHRDT_FILL_NANOS(dt)
512
- return rhrdt__from_jd_nanos(dt->jd, dt->nanos - (dt->offset - offset_min)*RHR_NANOS_PER_MINUTE, (short)offset_min);
512
+ return rhrdt__from_jd_nanos(rb_obj_class(self), dt->jd, dt->nanos - (dt->offset - offset_min)*RHR_NANOS_PER_MINUTE, (short)offset_min);
513
513
  }
514
514
 
515
515
  /* Class methods */
@@ -1453,7 +1453,7 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1453
1453
  double step, limit;
1454
1454
  long long step_nanos, limit_nanos, current_nanos;
1455
1455
  long step_jd, limit_jd, current_jd;
1456
- VALUE rlimit, new, rstep, new_off;
1456
+ VALUE rlimit, new, rstep, new_off, klass;
1457
1457
  new_off = rhrdt__new_offset(self, 0.0);
1458
1458
  Data_Get_Struct(self, rhrdt_t, d);
1459
1459
  Data_Get_Struct(new_off, rhrdt_t, d0);
@@ -1475,6 +1475,7 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1475
1475
  break;
1476
1476
  }
1477
1477
  rlimit = argv[0];
1478
+ klass = rb_obj_class(self);
1478
1479
 
1479
1480
  #ifdef RUBY19
1480
1481
  if (!rb_block_given_p()) {
@@ -1510,12 +1511,12 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1510
1511
 
1511
1512
  current_jd = d0->jd;
1512
1513
  current_nanos = d0->nanos;
1513
- new = rhrdt__from_jd_nanos(current_jd, current_nanos, d->offset);
1514
+ new = rhrdt__from_jd_nanos(klass, current_jd, current_nanos, d->offset);
1514
1515
  if (limit_jd > current_jd || (limit_jd == current_jd && limit_nanos > current_nanos)) {
1515
1516
  if (step_jd > 0 || (step_jd == 0 && step_nanos > 0)) {
1516
1517
  while (limit_jd > current_jd || (limit_jd == current_jd && limit_nanos >= current_nanos)) {
1517
1518
  rb_yield(new);
1518
- new = rhrdt__from_jd_nanos(current_jd + step_jd, current_nanos + step_nanos, d->offset);
1519
+ new = rhrdt__from_jd_nanos(klass, current_jd + step_jd, current_nanos + step_nanos, d->offset);
1519
1520
  Data_Get_Struct(new, rhrdt_t, ndt);
1520
1521
  current_jd = ndt->jd;
1521
1522
  current_nanos = ndt->nanos;
@@ -1525,7 +1526,7 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1525
1526
  if (step_jd < 0 || (step_jd == 0 && step_nanos < 0)) {
1526
1527
  while (limit_jd < current_jd || (limit_jd == current_jd && limit_nanos <= current_nanos)) {
1527
1528
  rb_yield(new);
1528
- new = rhrdt__from_jd_nanos(current_jd + step_jd, current_nanos + step_nanos, d->offset);
1529
+ new = rhrdt__from_jd_nanos(klass, current_jd + step_jd, current_nanos + step_nanos, d->offset);
1529
1530
  Data_Get_Struct(new, rhrdt_t, ndt);
1530
1531
  current_jd = ndt->jd;
1531
1532
  current_nanos = ndt->nanos;
@@ -1924,7 +1925,7 @@ VALUE rhrdt__add_years(VALUE self, long n) {
1924
1925
  VALUE new;
1925
1926
  Data_Get_Struct(self, rhrdt_t, d);
1926
1927
 
1927
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, newd);
1928
+ new = Data_Make_Struct(rb_obj_class(self), rhrdt_t, NULL, -1, newd);
1928
1929
  RHRDT_FILL_CIVIL(d)
1929
1930
  memcpy(newd, d, sizeof(rhrdt_t));
1930
1931
 
@@ -2605,7 +2606,7 @@ static VALUE rhrdt_to_time(VALUE self) {
2605
2606
  Data_Get_Struct(self, rhrdt_t, dt);
2606
2607
  RHRDT_FILL_JD(dt)
2607
2608
  RHRDT_FILL_NANOS(dt)
2608
- self = rhrdt__from_jd_nanos(dt->jd, dt->nanos - dt->offset * RHR_NANOS_PER_MINUTE, 0);
2609
+ self = rhrdt__from_jd_nanos(rb_obj_class(self), dt->jd, dt->nanos - dt->offset * RHR_NANOS_PER_MINUTE, 0);
2609
2610
  Data_Get_Struct(self, rhrdt_t, dt);
2610
2611
  RHRDT_FILL_CIVIL(dt)
2611
2612
  RHRDT_FILL_HMS(dt)
data/lib/1.8/date_ext.so CHANGED
Binary file
data/lib/1.9/date_ext.so CHANGED
Binary file
@@ -17,6 +17,11 @@ describe "Date#>>" do
17
17
  d.should == Date.civil(2008, 4, 30)
18
18
  end
19
19
 
20
+ it "should keep the same class as the receiver" do
21
+ c = Class.new(Date)
22
+ c.jd.>>(-10).should be_kind_of(c)
23
+ end
24
+
20
25
  it "should raise an error on non numeric parameters" do
21
26
  lambda { Date.civil(2007,2,27) >> "hello" }.should raise_error(TypeError)
22
27
  lambda { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError)
@@ -14,6 +14,11 @@ describe "Date#+" do
14
14
  d.should == Date.civil(2007, 2, 17)
15
15
  end
16
16
 
17
+ it "should keep the same class as the receiver" do
18
+ c = Class.new(Date)
19
+ c.jd.+(10).should be_kind_of(c)
20
+ end
21
+
17
22
  it "should raise an error on non numeric parameters" do
18
23
  lambda { Date.civil(2007,2,27) + "hello" }.should raise_error(TypeError)
19
24
  lambda { Date.civil(2007,2,27) + Date.new }.should raise_error(TypeError)
@@ -67,6 +67,11 @@ describe "Date.civil" do
67
67
  proc{Date.civil(2008, 2, 30)}.should raise_error(ArgumentError)
68
68
  proc{Date.civil(2009, 2, 29)}.should raise_error(ArgumentError)
69
69
  end
70
+
71
+ it "should keep the same class as the receiver" do
72
+ c = Class.new(Date)
73
+ c.civil.should be_kind_of(c)
74
+ end
70
75
  end
71
76
 
72
77
  describe "Date.new" do
@@ -143,5 +148,4 @@ describe "Date.valid_civil?" do
143
148
  Date.valid_civil?(2008, -11, -10).should == true
144
149
  end
145
150
  end
146
-
147
151
  end
@@ -91,6 +91,11 @@ describe "Date.commercial" do
91
91
  proc{Date.commercial(2008, 54, 6)}.should raise_error(ArgumentError)
92
92
  proc{Date.commercial(2009, 1, 8)}.should raise_error(ArgumentError)
93
93
  end
94
+
95
+ it "should keep the same class as the receiver" do
96
+ c = Class.new(Date)
97
+ c.commercial.should be_kind_of(c)
98
+ end
94
99
  end
95
100
 
96
101
  ruby_version_is "" ... "1.9" do
@@ -9,6 +9,11 @@ describe "Date#new_start" do
9
9
  Date.civil(1752, 9, 13).new_start(Date::ENGLAND).should == Date.civil(1752, 9, 13, Date::ENGLAND)
10
10
  end
11
11
 
12
+ it "should keep the same class as the receiver" do
13
+ c = Class.new(Date)
14
+ c.jd.new_start.should be_kind_of(c)
15
+ end
16
+
12
17
  ruby_version_is "" ... "1.9" do
13
18
  it "#newsg should be the same as new_start" do
14
19
  Date.civil(1582, 10, 14, Date::ENGLAND).newsg.should == Date.civil(1582, 10, 14, Date::ENGLAND).new_start
@@ -45,6 +50,11 @@ describe "Date#gregorian" do
45
50
  Date.civil(1582, 10, 14).gregorian.should == Date.civil(1582, 10, 14, Date::GREGORIAN)
46
51
  Date.civil(1752, 9, 14).gregorian.should == Date.civil(1752, 9, 14, Date::GREGORIAN)
47
52
  end
53
+
54
+ it "should keep the same class as the receiver" do
55
+ c = Class.new(Date)
56
+ c.jd.gregorian.should be_kind_of(c)
57
+ end
48
58
  end
49
59
 
50
60
  ruby_version_is "" ... "1.9" do
@@ -14,4 +14,10 @@ describe "Date#downto" do
14
14
  count.should == 17
15
15
  end
16
16
 
17
+ it "should keep the same class as the receiver" do
18
+ c = Class.new(Date)
19
+ c.jd.downto(c.jd - 2) do |d|
20
+ d.should be_kind_of(c)
21
+ end.should be_kind_of(c)
22
+ end
17
23
  end
@@ -24,6 +24,11 @@ describe "Date.jd" do
24
24
  proc{Date.jd(Date::JULIAN)}.should raise_error
25
25
  end
26
26
 
27
+ it "should keep the same class as the receiver" do
28
+ c = Class.new(Date)
29
+ c.jd.should be_kind_of(c)
30
+ end
31
+
27
32
  ruby_version_is "" ... "1.9" do
28
33
  it ".new1 should be the same as jd" do
29
34
  Date.new1(2454156).should == Date.jd(2454156)
@@ -43,6 +48,11 @@ describe "Date.new!" do
43
48
  Date.new!(2008, 1, 1).should == Date.jd(2008)
44
49
  end
45
50
 
51
+ it "should keep the same class as the receiver" do
52
+ c = Class.new(Date)
53
+ c.new!.should be_kind_of(c)
54
+ end
55
+
46
56
  it "should not accept more than 3 arguments" do
47
57
  proc{Date.new!(2008, 1, 1, 1)}.should raise_error(ArgumentError)
48
58
  end
@@ -16,6 +16,11 @@ describe "Date#<<" do
16
16
  d.should == Date.civil(2008, 2, 29)
17
17
  end
18
18
 
19
+ it "should keep the same class as the receiver" do
20
+ c = Class.new(Date)
21
+ c.jd.<<(-10).should be_kind_of(c)
22
+ end
23
+
19
24
  it "should raise an error on non numeric parameters" do
20
25
  lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
21
26
  lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError)
@@ -14,6 +14,11 @@ describe "Date#-" do
14
14
  d.should == Date.civil(2007, 5 ,2)
15
15
  end
16
16
 
17
+ it "should keep the same class as the receiver" do
18
+ c = Class.new(Date)
19
+ c.jd.-(10).should be_kind_of(c)
20
+ end
21
+
17
22
  it "should be able to compute the different between two dates" do
18
23
  (Date.civil(2007,2,27) - Date.civil(2007,2,27)).should == 0
19
24
  (Date.civil(2007,2,27) - Date.civil(2007,2,26)).should == 1
@@ -13,6 +13,11 @@ ruby_version_is "1.9" do
13
13
  it "should handle a negative argument by subtracting days" do
14
14
  (Date.civil(2007,2,27).next_day(-2)).should == Date.civil(2007, 2, 25)
15
15
  end
16
+
17
+ it "should keep the same class as the receiver" do
18
+ c = Class.new(Date)
19
+ c.jd.next_day.should be_kind_of(c)
20
+ end
16
21
  end
17
22
 
18
23
  describe "Date#prev_day" do
@@ -27,6 +32,11 @@ ruby_version_is "1.9" do
27
32
  it "should handle a negative argument by adding days" do
28
33
  (Date.civil(2007,2,27).prev_day(-2)).should == Date.civil(2007, 3, 1)
29
34
  end
35
+
36
+ it "should keep the same class as the receiver" do
37
+ c = Class.new(Date)
38
+ c.jd.prev_day.should be_kind_of(c)
39
+ end
30
40
  end
31
41
 
32
42
  describe "Date#next_month" do
@@ -47,6 +57,11 @@ ruby_version_is "1.9" do
47
57
  (Date.civil(2008,1,31).next_month).should == Date.civil(2008, 2, 29)
48
58
  (Date.civil(2007,1,31).next_month(3)).should == Date.civil(2007, 4, 30)
49
59
  end
60
+
61
+ it "should keep the same class as the receiver" do
62
+ c = Class.new(Date)
63
+ c.jd.next_month.should be_kind_of(c)
64
+ end
50
65
  end
51
66
 
52
67
  describe "Date#prev_month" do
@@ -67,6 +82,11 @@ ruby_version_is "1.9" do
67
82
  (Date.civil(2008,3,31).prev_month).should == Date.civil(2008, 2, 29)
68
83
  (Date.civil(2007,3,31).prev_month(4)).should == Date.civil(2006, 11, 30)
69
84
  end
85
+
86
+ it "should keep the same class as the receiver" do
87
+ c = Class.new(Date)
88
+ c.jd.prev_month.should be_kind_of(c)
89
+ end
70
90
  end
71
91
 
72
92
  describe "Date#next_year" do
@@ -85,6 +105,11 @@ ruby_version_is "1.9" do
85
105
  it "should handle adding a year where the new date is not a valid date" do
86
106
  (Date.civil(2008,2,29).next_year).should == Date.civil(2009, 2, 28)
87
107
  end
108
+
109
+ it "should keep the same class as the receiver" do
110
+ c = Class.new(Date)
111
+ c.jd.next_year.should be_kind_of(c)
112
+ end
88
113
  end
89
114
 
90
115
  describe "Date#prev_year" do
@@ -103,6 +128,10 @@ ruby_version_is "1.9" do
103
128
  it "should handle adding a year where the new date is not a valid date" do
104
129
  (Date.civil(2008,2,29).prev_year).should == Date.civil(2007, 2, 28)
105
130
  end
106
- end
107
131
 
132
+ it "should keep the same class as the receiver" do
133
+ c = Class.new(Date)
134
+ c.jd.prev_year.should be_kind_of(c)
135
+ end
136
+ end
108
137
  end
@@ -25,6 +25,11 @@ describe "Date.ordinal" do
25
25
  lambda { Date.ordinal(2008, 367) }.should raise_error(ArgumentError)
26
26
  end
27
27
 
28
+ it "should keep the same class as the receiver" do
29
+ c = Class.new(Date)
30
+ c.ordinal.should be_kind_of(c)
31
+ end
32
+
28
33
  ruby_version_is "" ... "1.9" do
29
34
  it ".new2 should be the same as ordinal" do
30
35
  Date.new2(2008, 10).should == Date.ordinal(2008, 10)
@@ -57,6 +57,12 @@ describe "Date.parse" do
57
57
  Date.parse('2008-10-11', true, 1).should == Date.civil(2008, 10, 11)
58
58
  end
59
59
 
60
+ it "should keep the same class as the receiver" do
61
+ c = Class.new(Date)
62
+ c.parse.should be_kind_of(c)
63
+ c.parse('20081011').should be_kind_of(c)
64
+ end
65
+
60
66
  it "raises errors for invalid dates" do
61
67
  lambda { Date.parse("") }.should raise_error(ArgumentError)
62
68
  lambda { Date.parse("2009-02-29") }.should raise_error(ArgumentError)
@@ -84,5 +84,16 @@ ruby_version_is "1.9" do
84
84
  it ".xmlschema should parse an ISO8601 format" do
85
85
  Date.xmlschema("2009-01-02").should == Date.new(2009, 1, 2)
86
86
  end
87
+
88
+ it "should keep the same class as the receiver" do
89
+ c = Class.new(Date)
90
+ c.httpdate("Fri, 02 Jan 2009 00:00:00 GMT").should be_kind_of(c)
91
+ c.iso8601("2009-01-02").should be_kind_of(c)
92
+ c.jisx0301("H21.01.02").should be_kind_of(c)
93
+ c.rfc2822("Fri, 2 Jan 2009 00:00:00 +0000").should be_kind_of(c)
94
+ c.rfc822("Fri, 2 Jan 2009 00:00:00 +0000").should be_kind_of(c)
95
+ c.rfc3339("2009-01-02T00:00:00+00:00").should be_kind_of(c)
96
+ c.xmlschema("2009-01-02").should be_kind_of(c)
97
+ end
87
98
  end
88
99
  end
@@ -128,4 +128,10 @@ describe "Date#step" do
128
128
  count.should == 0
129
129
  end
130
130
 
131
+ it "should keep the same class as the receiver" do
132
+ c = Class.new(Date)
133
+ c.jd.step(c.jd + 2) do |d|
134
+ d.should be_kind_of(c)
135
+ end.should be_kind_of(c)
136
+ end
131
137
  end
@@ -22,6 +22,12 @@ describe "Date#strptime" do
22
22
  Date.strptime('2008-10-11', '%Y-%m-%d', 1).should == Date.civil(2008, 10, 11)
23
23
  end
24
24
 
25
+ it "should keep the same class as the receiver" do
26
+ c = Class.new(Date)
27
+ c.strptime.should be_kind_of(c)
28
+ c.strptime('20081011', '%Y%m%d').should be_kind_of(c)
29
+ end
30
+
25
31
  it "raises errors for invalid dates" do
26
32
  lambda { Date.strptime("") }.should raise_error(ArgumentError)
27
33
  lambda { Date.strptime("", "") }.should raise_error(ArgumentError)
@@ -14,6 +14,11 @@ describe "Date#succ" do
14
14
  ds.succ.should == Date.ordinal(2009, 1)
15
15
  end
16
16
 
17
+ it "should keep the same class as the receiver" do
18
+ c = Class.new(Date)
19
+ c.jd.succ.should be_kind_of(c)
20
+ end
21
+
17
22
  it "should be aliased as next" do
18
23
  Date.civil(2008, 10, 11).next.should == Date.civil(2008, 10, 12)
19
24
  end
@@ -12,4 +12,9 @@ describe "Date.today" do
12
12
  it ".today should have an optional sg value" do
13
13
  Date.today(1).should == Date.today
14
14
  end
15
+
16
+ it "should keep the same class as the receiver" do
17
+ c = Class.new(Date)
18
+ c.today.should be_kind_of(c)
19
+ end
15
20
  end
@@ -14,4 +14,11 @@ describe "Date#upto" do
14
14
  count.should == 13
15
15
  end
16
16
 
17
+
18
+ it "should keep the same class as the receiver" do
19
+ c = Class.new(Date)
20
+ c.jd.upto(c.jd + 2) do |d|
21
+ d.should be_kind_of(c)
22
+ end.should be_kind_of(c)
23
+ end
17
24
  end
@@ -17,6 +17,11 @@ describe "DateTime#>>" do
17
17
  d.should == DateTime.civil(2008, 4, 30)
18
18
  end
19
19
 
20
+ it "should keep the same class as the receiver" do
21
+ c = Class.new(DateTime)
22
+ c.jd.>>(10).should be_kind_of(c)
23
+ end
24
+
20
25
  it "should raise an error on non numeric parameters" do
21
26
  lambda { DateTime.civil(2007,2,27) >> "hello" }.should raise_error(TypeError)
22
27
  lambda { DateTime.civil(2007,2,27) >> DateTime.new }.should raise_error(TypeError)
@@ -26,6 +26,11 @@ describe "DateTime#+" do
26
26
  d.should == DateTime.civil(2007, 2, 16, 12)
27
27
  end
28
28
 
29
+ it "should keep the same class as the receiver" do
30
+ c = Class.new(DateTime)
31
+ c.jd.+(10).should be_kind_of(c)
32
+ end
33
+
29
34
  it "should raise an error on non numeric parameters" do
30
35
  lambda { DateTime.civil(2007,2,27) + :hello }.should raise_error
31
36
  lambda { DateTime.civil(2007,2,27) + "hello" }.should raise_error
@@ -139,4 +139,14 @@ describe "DateTime constructors" do
139
139
  DateTime.ordinal(2008, 1, 0, 0, 0, 0).should == DateTime.ordinal(2008, 1, 0, 0, 0, 0)
140
140
  DateTime.ordinal(2008, 1, 1, 1, 1, 0.5, 1).should == DateTime.ordinal(2008, 1, 1, 1, 1, 0.5)
141
141
  end
142
+
143
+ it "should keep the same class as the receiver" do
144
+ c = Class.new(DateTime)
145
+ c.jd.should be_kind_of(c)
146
+ c.civil.should be_kind_of(c)
147
+ c.commercial.should be_kind_of(c)
148
+ c.ordinal.should be_kind_of(c)
149
+ c.new!.should be_kind_of(c)
150
+ c.new.should be_kind_of(c)
151
+ end
142
152
  end
@@ -9,6 +9,11 @@ describe "DateTime conversions" do
9
9
  DateTime.new(2008, 1, 1).new_offset(0.5).should == DateTime.new(2008, 1, 1)
10
10
  end
11
11
 
12
+ it "should keep the same class as the receiver" do
13
+ c = Class.new(DateTime)
14
+ c.jd.new_offset.should be_kind_of(c)
15
+ end
16
+
12
17
  ruby_version_is "" ... "1.9" do
13
18
  it "#newof should be a separate datetime with a modified offset" do
14
19
  DateTime.new(2008, 1, 1).newof(0.5).to_s.should == DateTime.new(2008, 1, 1, 12, 0, 0, 0.5).to_s
@@ -36,4 +36,10 @@ describe "DateTime#downto" do
36
36
  count.should == 17
37
37
  end
38
38
 
39
+ it "should keep the same class as the receiver" do
40
+ c = Class.new(DateTime)
41
+ c.jd.downto(c.jd - 2) do |d|
42
+ d.should be_kind_of(c)
43
+ end.should be_kind_of(c)
44
+ end
39
45
  end
@@ -1,7 +1,6 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
3
  describe "DateTime#<<" do
4
-
5
4
  it "should substract a number of months from a date" do
6
5
  (DateTime.civil(2007, 12, 27) << 10).should == DateTime.civil(2007,2,27)
7
6
  (DateTime.commercial(2007, 45, 5) << 10).should == DateTime.commercial(2007,2,2)
@@ -16,10 +15,14 @@ describe "DateTime#<<" do
16
15
  d.should == DateTime.civil(2008, 2, 29)
17
16
  end
18
17
 
18
+ it "should keep the same class as the receiver" do
19
+ c = Class.new(DateTime)
20
+ c.jd.<<(10).should be_kind_of(c)
21
+ end
22
+
19
23
  it "should raise an error on non numeric parameters" do
20
24
  lambda { DateTime.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
21
25
  lambda { DateTime.civil(2007,2,27) << DateTime.new }.should raise_error(TypeError)
22
26
  lambda { DateTime.civil(2007,2,27) << Object.new }.should raise_error(TypeError)
23
27
  end
24
-
25
28
  end
@@ -16,6 +16,11 @@ describe "DateTime#-" do
16
16
  (DateTime.ordinal(2008, 325, 6) - 315.25).should == DateTime.ordinal(2008, 10)
17
17
  end
18
18
 
19
+ it "should keep the same class as the receiver" do
20
+ c = Class.new(DateTime)
21
+ c.jd.-(10).should be_kind_of(c)
22
+ end
23
+
19
24
  it "should substract a negative number of days from a DateTime" do
20
25
  d = DateTime.civil(2007, 4, 19).-(-13)
21
26
  d.should == DateTime.civil(2007, 5 ,2)
@@ -18,6 +18,11 @@ ruby_version_is "1.9" do
18
18
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_day).day_fraction.should == 0.5
19
19
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_day).offset.should == 0.5
20
20
  end
21
+
22
+ it "should keep the same class as the receiver" do
23
+ c = Class.new(DateTime)
24
+ c.jd.next_day.should be_kind_of(c)
25
+ end
21
26
  end
22
27
 
23
28
  describe "DateTime#prev_day" do
@@ -37,6 +42,11 @@ ruby_version_is "1.9" do
37
42
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_day).day_fraction.should == 0.5
38
43
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_day).offset.should == 0.5
39
44
  end
45
+
46
+ it "should keep the same class as the receiver" do
47
+ c = Class.new(DateTime)
48
+ c.jd.prev_day.should be_kind_of(c)
49
+ end
40
50
  end
41
51
 
42
52
  describe "DateTime#next_month" do
@@ -62,6 +72,11 @@ ruby_version_is "1.9" do
62
72
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_month).day_fraction.should == 0.5
63
73
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_month).offset.should == 0.5
64
74
  end
75
+
76
+ it "should keep the same class as the receiver" do
77
+ c = Class.new(DateTime)
78
+ c.jd.next_month.should be_kind_of(c)
79
+ end
65
80
  end
66
81
 
67
82
  describe "DateTime#prev_month" do
@@ -87,6 +102,11 @@ ruby_version_is "1.9" do
87
102
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_month).day_fraction.should == 0.5
88
103
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_month).offset.should == 0.5
89
104
  end
105
+
106
+ it "should keep the same class as the receiver" do
107
+ c = Class.new(DateTime)
108
+ c.jd.prev_month.should be_kind_of(c)
109
+ end
90
110
  end
91
111
 
92
112
  describe "DateTime#next_year" do
@@ -110,6 +130,11 @@ ruby_version_is "1.9" do
110
130
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_year).day_fraction.should == 0.5
111
131
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).next_year).offset.should == 0.5
112
132
  end
133
+
134
+ it "should keep the same class as the receiver" do
135
+ c = Class.new(DateTime)
136
+ c.jd.next_year.should be_kind_of(c)
137
+ end
113
138
  end
114
139
 
115
140
  describe "DateTime#prev_year" do
@@ -133,6 +158,11 @@ ruby_version_is "1.9" do
133
158
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_year).day_fraction.should == 0.5
134
159
  (DateTime.civil(2007,2,27, 12, 0, 0, 0.5).prev_year).offset.should == 0.5
135
160
  end
161
+
162
+ it "should keep the same class as the receiver" do
163
+ c = Class.new(DateTime)
164
+ c.jd.prev_year.should be_kind_of(c)
165
+ end
136
166
  end
137
167
 
138
168
  end
@@ -15,4 +15,9 @@ describe "DateTime.now" do
15
15
  it "should accept an optional sg value" do
16
16
  DateTime.now(1).to_s.should == DateTime.now.to_s
17
17
  end
18
+
19
+ it "should keep the same class as the receiver" do
20
+ c = Class.new(DateTime)
21
+ c.now.should be_kind_of(c)
22
+ end
18
23
  end
@@ -18,6 +18,12 @@ describe "DateTime.parse" do
18
18
  DateTime.parse.should == DateTime.jd
19
19
  end
20
20
 
21
+ it "should keep the same class as the receiver" do
22
+ c = Class.new(DateTime)
23
+ c.parse.should be_kind_of(c)
24
+ c.parse('2008-10-11').should be_kind_of(c)
25
+ end
26
+
21
27
  it "can't handle a empty string" do
22
28
  lambda{ DateTime.parse("") }.should raise_error(ArgumentError)
23
29
  end
@@ -77,5 +77,16 @@ ruby_version_is "1.9" do
77
77
  it ".xmlschema should parse an ISO8601 format" do
78
78
  DateTime.xmlschema("2009-01-02T03:04:05+12:00").should == DateTime.new(2009, 1, 2, 3, 4, 5, 0.5)
79
79
  end
80
+
81
+ it "should keep the same class as the receiver" do
82
+ c = Class.new(DateTime)
83
+ c.httpdate("Fri, 02 Jan 2009 00:00:00 GMT").should be_kind_of(c)
84
+ c.iso8601("2009-01-02").should be_kind_of(c)
85
+ c.jisx0301("H21.01.02").should be_kind_of(c)
86
+ c.rfc2822("Fri, 2 Jan 2009 00:00:00 +0000").should be_kind_of(c)
87
+ c.rfc822("Fri, 2 Jan 2009 00:00:00 +0000").should be_kind_of(c)
88
+ c.rfc3339("2009-01-02T00:00:00+00:00").should be_kind_of(c)
89
+ c.xmlschema("2009-01-02").should be_kind_of(c)
90
+ end
80
91
  end
81
92
  end
@@ -174,4 +174,10 @@ describe "DateTime#step" do
174
174
 
175
175
  end
176
176
 
177
+ it "should keep the same class as the receiver" do
178
+ c = Class.new(DateTime)
179
+ c.jd.step(c.jd + 2) do |d|
180
+ d.should be_kind_of(c)
181
+ end.should be_kind_of(c)
182
+ end
177
183
  end
@@ -21,6 +21,12 @@ describe "DateTime.strptime" do
21
21
  DateTime.strptime("2000-04-06T10:11:12+00:00").should == DateTime.civil(2000, 4, 6, 10, 11, 12)
22
22
  end
23
23
 
24
+ it "should keep the same class as the receiver" do
25
+ c = Class.new(DateTime)
26
+ c.strptime.should be_kind_of(c)
27
+ c.strptime('2008-10-11', '%Y-%m-%d').should be_kind_of(c)
28
+ end
29
+
24
30
  it "should be able to parse the hour in a 24 hour clock with leading zero" do
25
31
  DateTime.strptime("10", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 10, 0, 0)
26
32
  DateTime.strptime("09", '%H').should == DateTime.civil(@t.year, @t.mon, @t.day, 9, 0, 0)