home_run 0.9.0-x86-mingw32 → 0.9.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,67 @@
1
+ #include "date_ext.h"
2
+
3
+ extern const unsigned char rhrd_days_in_month[];
4
+ extern const long rhrd_cumulative_days_in_month[];
5
+ extern const unsigned char rhrd_yday_to_month[];
6
+ extern const unsigned char rhrd_leap_yday_to_month[];
7
+
8
+ extern const char * rhrd__abbr_month_names[];
9
+ extern const char * rhrd__abbr_day_names[];
10
+
11
+ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self);
12
+ static VALUE rhrdt_to_s(VALUE self);
13
+ VALUE rhrdt__new_offset(VALUE self, double offset);
14
+ void rhrdt__jd_to_civil(rhrdt_t *date);
15
+ void rhrdt__nanos_to_hms(rhrdt_t *d);
16
+
17
+ extern VALUE rhrd_class;
18
+ extern VALUE rhrdt_class;
19
+ extern VALUE rhrdt_s_class;
20
+ extern ID rhrd_id__parse;
21
+ extern ID rhrd_id_cwday;
22
+ extern ID rhrd_id_cweek;
23
+ extern ID rhrd_id_cwyear;
24
+ extern ID rhrd_id_hash;
25
+ extern ID rhrd_id_now;
26
+ extern ID rhrd_id_offset;
27
+ extern ID rhrd_id_to_i;
28
+ #ifdef RUBY19
29
+ extern ID rhrd_id_nsec;
30
+ #else
31
+ extern ID rhrd_id_usec;
32
+ #endif
33
+ extern ID rhrd_id_utc_offset;
34
+ extern VALUE rhrd_sym_hour;
35
+ extern VALUE rhrd_sym_min;
36
+ extern VALUE rhrd_sym_offset;
37
+ extern VALUE rhrd_sym_sec;
38
+ extern VALUE rhrd_sym_sec_fraction;
39
+ extern VALUE rhrd_sym_seconds;
40
+
41
+ #ifdef RUBY19
42
+ extern ID rhrd_id__httpdate;
43
+ extern ID rhrd_id__iso8601;
44
+ extern ID rhrd_id__jisx0301;
45
+ extern ID rhrd_id__rfc2822;
46
+ extern ID rhrd_id__rfc3339;
47
+ extern ID rhrd_id__xmlschema;
48
+
49
+ extern ID rhrd_id_to_enum;
50
+ extern ID rhrd_id_localtime;
51
+ extern ID rhrd_id_utc;
52
+
53
+ extern VALUE rhrd_sym_step;
54
+ #endif
1
55
 
2
56
  /* Helper methods */
3
57
 
58
+ /* Raise an ArgumentError if the offset is outside the allowed range. */
59
+ void rhrdt__check_offset(long offset) {
60
+ if (offset > RHR_MAX_OFFSET || offset < RHR_MIN_OFFSET) {
61
+ rb_raise(rb_eArgError, "invalid offset: %ld minutes", offset);
62
+ }
63
+ }
64
+
4
65
  /* Identical for rhrd__valid_civil, but for rhrdt_t. Not very
5
66
  * DRY, but the arguments get modified by the method and then
6
67
  * used to populate the rhrdt_t. Because the rhrd_t field structure
@@ -38,7 +99,7 @@ int rhrdt__valid_civil(rhrdt_t *dt, long year, long month, long day) {
38
99
  }
39
100
 
40
101
  if(!rhrd__valid_civil_limits(year, month, day)) {
41
- return 0;
102
+ rb_raise(rb_eRangeError, "datetime out of range: year = %li, month = %li, day = %li", year, month, day);
42
103
  }
43
104
 
44
105
  dt->year = year;
@@ -49,23 +110,21 @@ int rhrdt__valid_civil(rhrdt_t *dt, long year, long month, long day) {
49
110
  }
50
111
 
51
112
  /* Check if the given offset is valid. If so, set the offset field
52
- * in the rhrdt_t and return 1. Otherwise, return 0. */
53
- int rhrdt__valid_offset(rhrdt_t *dt, double offset) {
54
- if (offset < RHR_MIN_OFFSET_FRACT || offset > RHR_MAX_OFFSET_FRACT) {
55
- return 0;
56
- }
57
-
58
- dt->offset = lround(offset * 1440);
59
- return 1;
113
+ * in the rhrdt_t, otherwise, raise an ArgumentError. */
114
+ void rhrdt__set_offset(rhrdt_t *dt, double offset) {
115
+ long offset_min;
116
+ offset_min = lround(offset * 1440);
117
+ rhrdt__check_offset(offset_min);
118
+ dt->offset = offset_min;
60
119
  }
61
120
 
62
- /* Check if the time information consistutes a valid time. If not, return
63
- * 0. If so, fill in the fields in the rhrdt_t and return 1. This handles
121
+ /* Check if the time information consistutes a valid time. If not, raise an
122
+ * ArgumentError. If so, fill in the fields in the rhrdt_t. This handles
64
123
  * wrap around for negative hour, minute, and second arguments, and handles
65
124
  * an hour of 24 with no minute or second value as the 0th hour of the next
66
125
  * day, so either the julian day or civil day fields in the rhrdt_t should
67
126
  * be filled out before calling this method. */
68
- int rhrdt__valid_time(rhrdt_t *dt, long h, long m, long s, double offset) {
127
+ void rhrdt__set_time(rhrdt_t *dt, long h, long m, long s, double offset) {
69
128
  if (h < 0) {
70
129
  h += 24;
71
130
  }
@@ -82,17 +141,14 @@ int rhrdt__valid_time(rhrdt_t *dt, long h, long m, long s, double offset) {
82
141
  dt->flags &= ~RHR_HAVE_CIVIL;
83
142
  h = 0;
84
143
  } else if (h < 0 || m < 0 || s < 0 || h > 23 || m > 59 || s > 59) {
85
- return 0;
86
- }
87
- if(!rhrdt__valid_offset(dt, offset)) {
88
- return 0;
144
+ rb_raise(rb_eArgError, "invalid time: %ld hours, %ld minutes, %ld seconds", h, m, s);
89
145
  }
146
+ rhrdt__set_offset(dt, offset);
90
147
 
91
148
  dt->hour = h;
92
149
  dt->minute = m;
93
150
  dt->second = s;
94
151
  dt->flags |= RHR_HAVE_HMS;
95
- return 1;
96
152
  }
97
153
 
98
154
  /* Same as rhrd__civil_to_jd for rhrdt_t. */
@@ -172,7 +228,7 @@ int rhrdt__valid_commercial(rhrdt_t *d, long cwyear, long cweek, long cwday) {
172
228
  }
173
229
 
174
230
  if ((n.jd > RHR_JD_MAX) || (n.jd < RHR_JD_MIN)) {
175
- return 0;
231
+ rb_raise(rb_eRangeError, "datetime out of range");
176
232
  }
177
233
 
178
234
  d->jd = n.jd;
@@ -209,7 +265,7 @@ int rhrdt__valid_ordinal(rhrdt_t *d, long year, long yday) {
209
265
  }
210
266
 
211
267
  if(!rhrd__valid_civil_limits(year, month, day)) {
212
- return 0;
268
+ rb_raise(rb_eRangeError, "datetime out of range");
213
269
  }
214
270
 
215
271
  d->year = year;
@@ -251,7 +307,7 @@ VALUE rhrdt__from_jd_nanos(long jd, long long nanos, short offset) {
251
307
  long t;
252
308
  rhrdt_t *dt;
253
309
  VALUE new;
254
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, free, dt);
310
+ new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, dt);
255
311
 
256
312
  if (nanos < 0) {
257
313
  t = nanos/RHR_NANOS_PER_DAY - 1;
@@ -263,6 +319,7 @@ VALUE rhrdt__from_jd_nanos(long jd, long long nanos, short offset) {
263
319
  jd += t;
264
320
  }
265
321
  dt->jd = jd;
322
+ RHR_CHECK_JD(dt)
266
323
  dt->nanos = nanos;
267
324
  dt->offset = offset;
268
325
  dt->flags = RHR_HAVE_JD | RHR_HAVE_NANOS;
@@ -314,7 +371,7 @@ VALUE rhrdt__add_months(VALUE self, long n) {
314
371
  long x;
315
372
  Data_Get_Struct(self, rhrdt_t, d);
316
373
 
317
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, free, newd);
374
+ new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, newd);
318
375
  RHRDT_FILL_CIVIL(d)
319
376
  memcpy(newd, d, sizeof(rhrdt_t));
320
377
 
@@ -377,9 +434,7 @@ void rhrdt__fill_from_hash(rhrdt_t *dt, VALUE hash) {
377
434
  dt->minute = (time_set - dt->hour * RHR_SECONDS_PER_HOUR)/60;
378
435
  dt->second = rhrd__mod(time_set, 60);
379
436
  offset /= 60;
380
- if (offset > RHR_MAX_OFFSET_MINUTES || offset < RHR_MIN_OFFSET_MINUTES) {
381
- rb_raise(rb_eArgError, "invalid offset: %ld minutes", offset);
382
- }
437
+ rhrdt__check_offset(offset);
383
438
  RHR_CHECK_JD(dt);
384
439
  dt->flags = RHR_HAVE_JD | RHR_HAVE_NANOS | RHR_HAVE_HMS;
385
440
  return;
@@ -428,15 +483,13 @@ void rhrdt__fill_from_hash(rhrdt_t *dt, VALUE hash) {
428
483
  dt->flags |= RHR_HAVE_CIVIL;
429
484
  }
430
485
  if(time_set) {
431
- rhrdt__valid_time(dt, hour, minute, second, offset/RHR_SECONDS_PER_DAYD);
486
+ rhrdt__set_time(dt, hour, minute, second, offset/RHR_SECONDS_PER_DAYD);
432
487
  if(nanos) {
433
488
  RHRDT_FILL_NANOS(dt)
434
489
  dt->nanos += nanos;
435
490
  }
436
491
  } else if (offset) {
437
- if(!rhrdt__valid_offset(dt, offset/RHR_SECONDS_PER_DAYD)){
438
- rb_raise(rb_eArgError, "invalid date");
439
- }
492
+ rhrdt__set_offset(dt, offset/RHR_SECONDS_PER_DAYD);
440
493
  }
441
494
  }
442
495
 
@@ -447,10 +500,8 @@ VALUE rhrdt__new_offset(VALUE self, double offset) {
447
500
  rhrdt_t *dt;
448
501
  long offset_min;
449
502
 
450
- if(offset < RHR_MIN_OFFSET_FRACT || offset > RHR_MAX_OFFSET_FRACT) {
451
- rb_raise(rb_eArgError, "invalid offset (%f)", offset);
452
- }
453
503
  offset_min = lround(offset * 1440.0);
504
+ rhrdt__check_offset(offset_min);
454
505
  Data_Get_Struct(self, rhrdt_t, dt);
455
506
  RHRDT_FILL_JD(dt)
456
507
  RHRDT_FILL_NANOS(dt)
@@ -473,7 +524,7 @@ static VALUE rhrdt_s__load(VALUE klass, VALUE string) {
473
524
  rhrdt_t * d;
474
525
  long x;
475
526
  VALUE ary, rd;
476
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
527
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
477
528
 
478
529
  ary = rb_marshal_load(string);
479
530
  if (!RTEST(rb_obj_is_kind_of(ary, rb_cArray)) || RARRAY_LEN(ary) != 3) {
@@ -489,9 +540,7 @@ static VALUE rhrdt_s__load(VALUE klass, VALUE string) {
489
540
  }
490
541
 
491
542
  x = NUM2LONG(rb_ary_entry(ary, 2));
492
- if (x > RHR_MAX_OFFSET_MINUTES || x < RHR_MIN_OFFSET_MINUTES) {
493
- rb_raise(rb_eArgError, "invalid offset: %ld minutes", x);
494
- }
543
+ rhrdt__check_offset(x);
495
544
  d->offset = x;
496
545
 
497
546
  d->flags = RHR_HAVE_JD | RHR_HAVE_NANOS;
@@ -545,7 +594,7 @@ static VALUE rhrdt_s_civil(int argc, VALUE *argv, VALUE klass) {
545
594
  long minute = 0;
546
595
  long second = 0;
547
596
  double offset = 0.0;
548
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
597
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
549
598
 
550
599
  switch(argc) {
551
600
  case 0:
@@ -573,13 +622,9 @@ static VALUE rhrdt_s_civil(int argc, VALUE *argv, VALUE klass) {
573
622
  }
574
623
 
575
624
  if (!rhrdt__valid_civil(dt, year, month, day)) {
576
- RHR_CHECK_CIVIL(dt)
577
625
  rb_raise(rb_eArgError, "invalid date (year: %li, month: %li, day: %li)", year, month, day);
578
626
  }
579
- if (!rhrdt__valid_time(dt, hour, minute, second, offset)) {
580
- rb_raise(rb_eArgError, "invalid time (hour: %li, minute: %li, second: %li, offset: %f)", hour, minute, second, offset);
581
- }
582
-
627
+ rhrdt__set_time(dt, hour, minute, second, offset);
583
628
  return rdt;
584
629
  }
585
630
 
@@ -606,7 +651,7 @@ static VALUE rhrdt_s_commercial(int argc, VALUE *argv, VALUE klass) {
606
651
  long minute = 0;
607
652
  long second = 0;
608
653
  double offset = 0.0;
609
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
654
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
610
655
 
611
656
  switch(argc) {
612
657
  case 8:
@@ -638,13 +683,9 @@ static VALUE rhrdt_s_commercial(int argc, VALUE *argv, VALUE klass) {
638
683
  break;
639
684
  }
640
685
  if(!rhrdt__valid_commercial(dt, cwyear, cweek, cwday)) {
641
- RHR_CHECK_JD(dt)
642
686
  rb_raise(rb_eArgError, "invalid date (cwyear: %li, cweek: %li, cwday: %li)", cwyear, cweek, cwday);
643
687
  }
644
- if (!rhrdt__valid_time(dt, hour, minute, second, offset)) {
645
- rb_raise(rb_eArgError, "invalid time (hour: %li, minute: %li, second: %li, offset: %f)", hour, minute, second, offset);
646
- }
647
-
688
+ rhrdt__set_time(dt, hour, minute, second, offset);
648
689
  return rdt;
649
690
  }
650
691
 
@@ -662,7 +703,7 @@ static VALUE rhrdt_s_jd(int argc, VALUE *argv, VALUE klass) {
662
703
  long minute = 0;
663
704
  long second = 0;
664
705
  double offset = 0.0;
665
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
706
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
666
707
 
667
708
  switch(argc) {
668
709
  case 0:
@@ -687,10 +728,7 @@ static VALUE rhrdt_s_jd(int argc, VALUE *argv, VALUE klass) {
687
728
 
688
729
  RHR_CHECK_JD(dt)
689
730
  dt->flags = RHR_HAVE_JD;
690
- if (!rhrdt__valid_time(dt, hour, minute, second, offset)) {
691
- rb_raise(rb_eArgError, "invalid time (hour: %li, minute: %li, second: %li, offset: %f)", hour, minute, second, offset);
692
- }
693
-
731
+ rhrdt__set_time(dt, hour, minute, second, offset);
694
732
  return rdt;
695
733
  }
696
734
 
@@ -715,7 +753,7 @@ static VALUE rhrdt_s_jd(int argc, VALUE *argv, VALUE klass) {
715
753
  static VALUE rhrdt_s_new_b(int argc, VALUE *argv, VALUE klass) {
716
754
  double offset = 0;
717
755
  rhrdt_t *dt;
718
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
756
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
719
757
 
720
758
  switch(argc) {
721
759
  case 0:
@@ -724,12 +762,11 @@ static VALUE rhrdt_s_new_b(int argc, VALUE *argv, VALUE klass) {
724
762
  case 2:
725
763
  case 3:
726
764
  offset = NUM2DBL(argv[1]);
727
- if (!rhrdt__valid_offset(dt, offset)) {
728
- rb_raise(rb_eArgError, "invalid offset (%f)", offset);
729
- }
765
+ rhrdt__set_offset(dt, offset);
730
766
  case 1:
731
767
  offset += NUM2DBL(argv[0]) + 0.5;
732
768
  dt->jd = offset;
769
+ RHR_CHECK_JD(dt)
733
770
  dt->nanos = (offset - dt->jd)*RHR_NANOS_PER_DAY;
734
771
  dt->flags = RHR_HAVE_JD | RHR_HAVE_NANOS;
735
772
  break;
@@ -751,7 +788,7 @@ static VALUE rhrdt_s_new_b(int argc, VALUE *argv, VALUE klass) {
751
788
  */
752
789
  static VALUE rhrdt_s_now(int argc, VALUE *argv, VALUE klass) {
753
790
  rhrdt_t *dt;
754
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
791
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
755
792
 
756
793
  switch(argc) {
757
794
  case 0:
@@ -784,7 +821,7 @@ static VALUE rhrdt_s_ordinal(int argc, VALUE *argv, VALUE klass) {
784
821
  long second = 0;
785
822
  double offset = 0.0;
786
823
  rhrdt_t *dt;
787
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
824
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
788
825
 
789
826
  switch(argc) {
790
827
  case 7:
@@ -813,9 +850,7 @@ static VALUE rhrdt_s_ordinal(int argc, VALUE *argv, VALUE klass) {
813
850
  RHR_CHECK_JD(dt)
814
851
  rb_raise(rb_eArgError, "invalid date (year: %li, yday: %li)", year, day);
815
852
  }
816
- if (!rhrdt__valid_time(dt, hour, minute, second, offset)) {
817
- rb_raise(rb_eArgError, "invalid time (hour: %li, minute: %li, second: %li, offset: %f)", hour, minute, second, offset);
818
- }
853
+ rhrdt__set_time(dt, hour, minute, second, offset);
819
854
  return rdt;
820
855
  }
821
856
 
@@ -833,7 +868,7 @@ static VALUE rhrdt_s_ordinal(int argc, VALUE *argv, VALUE klass) {
833
868
  */
834
869
  static VALUE rhrdt_s_parse(int argc, VALUE *argv, VALUE klass) {
835
870
  rhrdt_t *dt;
836
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
871
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
837
872
 
838
873
  switch(argc) {
839
874
  case 0:
@@ -867,7 +902,7 @@ static VALUE rhrdt_s_parse(int argc, VALUE *argv, VALUE klass) {
867
902
  */
868
903
  static VALUE rhrdt_s_strptime(int argc, VALUE *argv, VALUE klass) {
869
904
  rhrdt_t *dt;
870
- VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, free, dt);
905
+ VALUE rdt = Data_Make_Struct(klass, rhrdt_t, NULL, -1, dt);
871
906
 
872
907
  switch(argc) {
873
908
  case 0:
@@ -1403,18 +1438,19 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1403
1438
  double step, limit;
1404
1439
  long long step_nanos, limit_nanos, current_nanos;
1405
1440
  long step_jd, limit_jd, current_jd;
1406
- VALUE rlimit, new;
1441
+ VALUE rlimit, new, rstep;
1407
1442
  Data_Get_Struct(self, rhrdt_t, d);
1408
1443
  Data_Get_Struct(rhrdt__new_offset(self, 0), rhrdt_t, d0);
1409
1444
 
1410
- rb_need_block();
1411
1445
  switch(argc) {
1412
1446
  case 1:
1413
1447
  step_nanos = 0;
1414
1448
  step_jd = 1;
1449
+ rstep = LONG2NUM(step_jd);
1415
1450
  break;
1416
1451
  case 2:
1417
- step = NUM2DBL(argv[1]);
1452
+ rstep = argv[1];
1453
+ step = NUM2DBL(rstep);
1418
1454
  step_jd = floor(step);
1419
1455
  step_nanos = llround((step - step_jd)*RHR_NANOS_PER_DAY);
1420
1456
  break;
@@ -1422,8 +1458,16 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1422
1458
  rb_raise(rb_eArgError, "wrong number of arguments: %i for 2", argc);
1423
1459
  break;
1424
1460
  }
1425
-
1426
1461
  rlimit = argv[0];
1462
+
1463
+ #ifdef RUBY19
1464
+ if (!rb_block_given_p()) {
1465
+ return rb_funcall(self, rhrd_id_to_enum, 3, rhrd_sym_step, rlimit, rstep);
1466
+ }
1467
+ #else
1468
+ rb_need_block();
1469
+ #endif
1470
+
1427
1471
  if (RTEST(rb_obj_is_kind_of(rlimit, rb_cNumeric))) {
1428
1472
  limit = NUM2DBL(rlimit);
1429
1473
  limit_jd = floor(limit);
@@ -1864,7 +1908,7 @@ VALUE rhrdt__add_years(VALUE self, long n) {
1864
1908
  VALUE new;
1865
1909
  Data_Get_Struct(self, rhrdt_t, d);
1866
1910
 
1867
- new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, free, newd);
1911
+ new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, newd);
1868
1912
  RHRDT_FILL_CIVIL(d)
1869
1913
  memcpy(newd, d, sizeof(rhrdt_t));
1870
1914
 
@@ -1943,7 +1987,7 @@ long rhrdt__add_iso_time_format(rhrdt_t *dt, char *str, long len, long i) {
1943
1987
  static VALUE rhrdt_s_httpdate(int argc, VALUE *argv, VALUE klass) {
1944
1988
  rhrdt_t *d;
1945
1989
  VALUE rd;
1946
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
1990
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
1947
1991
 
1948
1992
  switch(argc) {
1949
1993
  case 0:
@@ -1978,7 +2022,7 @@ static VALUE rhrdt_s_httpdate(int argc, VALUE *argv, VALUE klass) {
1978
2022
  static VALUE rhrdt_s_iso8601(int argc, VALUE *argv, VALUE klass) {
1979
2023
  rhrdt_t *d;
1980
2024
  VALUE rd;
1981
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
2025
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
1982
2026
 
1983
2027
  switch(argc) {
1984
2028
  case 0:
@@ -2013,7 +2057,7 @@ static VALUE rhrdt_s_iso8601(int argc, VALUE *argv, VALUE klass) {
2013
2057
  static VALUE rhrdt_s_jisx0301(int argc, VALUE *argv, VALUE klass) {
2014
2058
  rhrdt_t *d;
2015
2059
  VALUE rd;
2016
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
2060
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
2017
2061
 
2018
2062
  switch(argc) {
2019
2063
  case 0:
@@ -2048,7 +2092,7 @@ static VALUE rhrdt_s_jisx0301(int argc, VALUE *argv, VALUE klass) {
2048
2092
  static VALUE rhrdt_s_rfc2822(int argc, VALUE *argv, VALUE klass) {
2049
2093
  rhrdt_t *d;
2050
2094
  VALUE rd;
2051
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
2095
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
2052
2096
 
2053
2097
  switch(argc) {
2054
2098
  case 0:
@@ -2083,7 +2127,7 @@ static VALUE rhrdt_s_rfc2822(int argc, VALUE *argv, VALUE klass) {
2083
2127
  static VALUE rhrdt_s_rfc3339(int argc, VALUE *argv, VALUE klass) {
2084
2128
  rhrdt_t *d;
2085
2129
  VALUE rd;
2086
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
2130
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
2087
2131
 
2088
2132
  switch(argc) {
2089
2133
  case 0:
@@ -2118,7 +2162,7 @@ static VALUE rhrdt_s_rfc3339(int argc, VALUE *argv, VALUE klass) {
2118
2162
  static VALUE rhrdt_s_xmlschema(int argc, VALUE *argv, VALUE klass) {
2119
2163
  rhrdt_t *d;
2120
2164
  VALUE rd;
2121
- rd = Data_Make_Struct(klass, rhrdt_t, NULL, free, d);
2165
+ rd = Data_Make_Struct(klass, rhrdt_t, NULL, -1, d);
2122
2166
 
2123
2167
  switch(argc) {
2124
2168
  case 0:
@@ -2512,7 +2556,7 @@ static VALUE rhrdt_rfc2822(VALUE self) {
2512
2556
  static VALUE rhrdt_to_date(VALUE self) {
2513
2557
  rhrd_t *d;
2514
2558
  rhrdt_t *dt;
2515
- VALUE rd = Data_Make_Struct(rhrd_class, rhrd_t, NULL, free, d);
2559
+ VALUE rd = Data_Make_Struct(rhrd_class, rhrd_t, NULL, -1, d);
2516
2560
  Data_Get_Struct(self, rhrdt_t, dt);
2517
2561
 
2518
2562
  if (RHR_HAS_CIVIL(dt)) {
@@ -2570,7 +2614,7 @@ static VALUE rhrdt_time_to_datetime(VALUE self) {
2570
2614
  rhrdt_t *dt;
2571
2615
  VALUE rd;
2572
2616
  long t, offset;
2573
- rd = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, free, dt);
2617
+ rd = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, dt);
2574
2618
 
2575
2619
  offset = NUM2LONG(rb_funcall(self, rhrd_id_utc_offset, 0));
2576
2620
  t = NUM2LONG(rb_funcall(self, rhrd_id_to_i, 0)) + offset;
@@ -2680,7 +2724,6 @@ void Init_datetime(void) {
2680
2724
  /* Define class */
2681
2725
 
2682
2726
  rhrdt_class = rb_define_class("DateTime", rhrd_class);
2683
- rb_undef_alloc_func(rhrdt_class);
2684
2727
  rhrdt_s_class = rb_singleton_class(rhrdt_class);
2685
2728
 
2686
2729
  /* Define methods for all ruby versions*/
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+ $CFLAGS << " -DRUBY19" if RUBY_VERSION >= '1.9.0'
3
+ $CFLAGS << " -DRUBY186" if RUBY_VERSION < '1.8.7'
4
+ $CFLAGS << " -Wall " unless RUBY_PLATFORM =~ /solaris/
5
+ $CFLAGS << ' -g -ggdb -rdynamic -O0 -DDEBUG' if ENV['DEBUG']
6
+ create_makefile("date_ext")
Binary file
Binary file
@@ -1,7 +1,7 @@
1
1
  # format.rb: Written by Tadayoshi Funaba 1999-2009
2
2
  # $Id: format.rb,v 2.43 2008-01-17 20:16:31+09 tadf Exp $
3
3
 
4
- require 'date' unless defined?(Date)
4
+ require 'date' unless defined?(Date::ZONES)
5
5
 
6
6
  class Date
7
7
  # Holds some constants used by the pure ruby parsing code.
data/lib/date.rb ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require "date_ext"
3
+ rescue LoadError
4
+ raise unless RUBY_PLATFORM =~ /mswin|mingw/
5
+ require "#{RUBY_VERSION[0...3]}/date_ext"
6
+ end
7
+ require "date/format" unless defined?(Date::Format::ZONES)
data/lib/home_run.rb ADDED
@@ -0,0 +1,5 @@
1
+ Object.send(:remove_const, :Date) if defined?(Date)
2
+ Object.send(:remove_const, :DateTime) if defined?(DateTime)
3
+ dir = File.dirname(File.expand_path(__FILE__))
4
+ load File.join(dir, 'date.rb')
5
+ load File.join(dir, 'date', 'format.rb') unless defined?(Date::Format)
@@ -0,0 +1,7 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe "Date.allocate" do
4
+ it "should not be defined" do
5
+ proc{Date.allocate}.should raise_error
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ ruby_version_is "1.9" do
4
+ describe "Date string encoding methods" do
5
+ it "should return strings in US-ASCII encoding by default" do
6
+ d = Date.today
7
+ d.asctime.encoding.name.should == 'US-ASCII'
8
+ d.ctime.encoding.name.should == 'US-ASCII'
9
+ d.httpdate.encoding.name.should == 'US-ASCII'
10
+ d.inspect.encoding.name.should == 'US-ASCII'
11
+ d.iso8601.encoding.name.should == 'US-ASCII'
12
+ d.jisx0301.encoding.name.should == 'US-ASCII'
13
+ d.rfc2822.encoding.name.should == 'US-ASCII'
14
+ d.rfc3339.encoding.name.should == 'US-ASCII'
15
+ d.rfc822.encoding.name.should == 'US-ASCII'
16
+ d.strftime('%S:%M:%H').encoding.name.should == 'US-ASCII'
17
+ d.to_s.encoding.name.should == 'US-ASCII'
18
+ d.xmlschema.encoding.name.should == 'US-ASCII'
19
+ end
20
+
21
+ it "should return strings in default_internal encoding if set" do
22
+ begin
23
+ Encoding.default_internal = 'UTF-8'
24
+ d = Date.today
25
+ d.asctime.encoding.name.should == 'UTF-8'
26
+ d.ctime.encoding.name.should == 'UTF-8'
27
+ d.httpdate.encoding.name.should == 'UTF-8'
28
+ d.inspect.encoding.name.should == 'UTF-8'
29
+ d.iso8601.encoding.name.should == 'UTF-8'
30
+ d.jisx0301.encoding.name.should == 'UTF-8'
31
+ d.rfc2822.encoding.name.should == 'UTF-8'
32
+ d.rfc3339.encoding.name.should == 'UTF-8'
33
+ d.rfc822.encoding.name.should == 'UTF-8'
34
+ d.strftime('%S:%M:%H').encoding.name.should == 'UTF-8'
35
+ d.to_s.encoding.name.should == 'UTF-8'
36
+ d.xmlschema.encoding.name.should == 'UTF-8'
37
+ ensure
38
+ Encoding.default_internal = nil
39
+ end
40
+ end
41
+ end
42
+ end