home_run 0.9.1-x86-mingw32 → 0.9.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  #include "date_ext.h"
2
2
 
3
+ #ifdef RHR_ENCODING
4
+ extern int rhrd_encoding_index;
5
+ #endif
6
+
3
7
  extern const unsigned char rhrd_days_in_month[];
4
8
  extern const long rhrd_cumulative_days_in_month[];
5
9
  extern const unsigned char rhrd_yday_to_month[];
@@ -115,7 +119,7 @@ void rhrdt__set_offset(rhrdt_t *dt, double offset) {
115
119
  long offset_min;
116
120
  offset_min = lround(offset * 1440);
117
121
  rhrdt__check_offset(offset_min);
118
- dt->offset = offset_min;
122
+ dt->offset = (short)offset_min;
119
123
  }
120
124
 
121
125
  /* Check if the time information consistutes a valid time. If not, raise an
@@ -138,16 +142,16 @@ void rhrdt__set_time(rhrdt_t *dt, long h, long m, long s, double offset) {
138
142
  if (h == 24 && m == 0 && s == 0) {
139
143
  RHRDT_FILL_JD(dt)
140
144
  dt->jd++;
141
- dt->flags &= ~RHR_HAVE_CIVIL;
145
+ dt->flags &= (unsigned char)~RHR_HAVE_CIVIL;
142
146
  h = 0;
143
147
  } else if (h < 0 || m < 0 || s < 0 || h > 23 || m > 59 || s > 59) {
144
148
  rb_raise(rb_eArgError, "invalid time: %ld hours, %ld minutes, %ld seconds", h, m, s);
145
149
  }
146
150
  rhrdt__set_offset(dt, offset);
147
151
 
148
- dt->hour = h;
149
- dt->minute = m;
150
- dt->second = s;
152
+ dt->hour = (unsigned char)h;
153
+ dt->minute = (unsigned char)m;
154
+ dt->second = (unsigned char)s;
151
155
  dt->flags |= RHR_HAVE_HMS;
152
156
  }
153
157
 
@@ -166,12 +170,12 @@ void rhrdt__jd_to_civil(rhrdt_t *date) {
166
170
  c = (long)floor((b - 122.1) / 365.25);
167
171
  d = (long)floor(365.25 * c);
168
172
  e = (long)floor((b - d) / 30.6001);
169
- date->day = b - d - (long)floor(30.6001 * e);
173
+ date->day = (unsigned char)(b - d - (long)floor(30.6001 * e));
170
174
  if (e <= 13) {
171
- date->month = e - 1;
175
+ date->month = (unsigned char)(e - 1);
172
176
  date->year = c - 4716;
173
177
  } else {
174
- date->month = e - 13;
178
+ date->month = (unsigned char)(e - 13);
175
179
  date->year = c - 4715;
176
180
  }
177
181
  date->flags |= RHR_HAVE_CIVIL;
@@ -182,10 +186,10 @@ void rhrdt__jd_to_civil(rhrdt_t *date) {
182
186
  * nanos field has already been filled in. */
183
187
  void rhrdt__nanos_to_hms(rhrdt_t *d) {
184
188
  unsigned int seconds;
185
- seconds = d->nanos/RHR_NANOS_PER_SECOND;
186
- d->hour = seconds/RHR_SECONDS_PER_HOUR;
187
- d->minute = (seconds % RHR_SECONDS_PER_HOUR)/60;
188
- d->second = seconds % 60;
189
+ seconds = (unsigned int)(d->nanos/RHR_NANOS_PER_SECOND);
190
+ d->hour = (unsigned char)(seconds/RHR_SECONDS_PER_HOUR);
191
+ d->minute = (unsigned char)((seconds % RHR_SECONDS_PER_HOUR)/60);
192
+ d->second = (unsigned char)(seconds % 60);
189
193
  d->flags |= RHR_HAVE_HMS;
190
194
  }
191
195
 
@@ -286,13 +290,13 @@ void rhrdt__now(rhrdt_t * dt) {
286
290
  rt = rb_funcall(rb_cTime, rhrd_id_now, 0);
287
291
  offset = NUM2LONG(rb_funcall(rt, rhrd_id_utc_offset, 0));
288
292
  t = NUM2LONG(rb_funcall(rt, rhrd_id_to_i, 0)) + offset;
289
- dt->jd = rhrd__unix_to_jd(t);
293
+ dt->jd = rhrd__unix_to_jd((long long)t);
290
294
  #ifdef RUBY19
291
295
  dt->nanos = rhrd__mod(t, RHR_SECONDS_PER_DAY) * RHR_NANOS_PER_SECOND + NUM2LONG(rb_funcall(rt, rhrd_id_nsec, 0));
292
296
  #else
293
297
  dt->nanos = rhrd__mod(t, RHR_SECONDS_PER_DAY) * RHR_NANOS_PER_SECOND + NUM2LONG(rb_funcall(rt, rhrd_id_usec, 0)) * 1000;
294
298
  #endif
295
- dt->offset = offset/60;
299
+ dt->offset = (short)(offset/60);
296
300
  dt->flags |= RHR_HAVE_JD | RHR_HAVE_NANOS;
297
301
  RHR_CHECK_JD(dt);
298
302
  }
@@ -310,11 +314,11 @@ VALUE rhrdt__from_jd_nanos(long jd, long long nanos, short offset) {
310
314
  new = Data_Make_Struct(rhrdt_class, rhrdt_t, NULL, -1, dt);
311
315
 
312
316
  if (nanos < 0) {
313
- t = nanos/RHR_NANOS_PER_DAY - 1;
317
+ t = (long)(nanos/RHR_NANOS_PER_DAY - 1);
314
318
  nanos -= t * RHR_NANOS_PER_DAY;
315
319
  jd += t;
316
320
  } else if (nanos >= RHR_NANOS_PER_DAY) {
317
- t = nanos/RHR_NANOS_PER_DAY;
321
+ t = (long)(nanos/RHR_NANOS_PER_DAY);
318
322
  nanos -= t * RHR_NANOS_PER_DAY;
319
323
  jd += t;
320
324
  }
@@ -357,7 +361,7 @@ VALUE rhrdt__add_days(VALUE self, double n) {
357
361
  Data_Get_Struct(self, rhrdt_t, dt);
358
362
  RHRDT_FILL_JD(dt)
359
363
  RHRDT_FILL_NANOS(dt)
360
- l = floor(n);
364
+ l = (long)floor(n);
361
365
  nanos = llround((n - l) * RHR_NANOS_PER_DAY);
362
366
  return rhrdt__from_jd_nanos(rhrd__safe_add_long(dt->jd, l), dt->nanos + nanos, dt->offset);
363
367
  }
@@ -378,13 +382,13 @@ VALUE rhrdt__add_months(VALUE self, long n) {
378
382
  n = rhrd__safe_add_long(n, (long)(d->month));
379
383
  if(n > 1 && n <= 12) {
380
384
  newd->year = d->year;
381
- newd->month = n;
385
+ newd->month = (unsigned char)n;
382
386
  } else {
383
387
  x = n / 12;
384
388
  n = n % 12;
385
389
  if (n <= 0) {
386
390
  newd->year = d->year + x - 1;
387
- newd->month = n + 12;
391
+ newd->month = (unsigned char)(n + 12);
388
392
  } else {
389
393
  newd->year = d->year + x;
390
394
  newd->month = (unsigned char)n;
@@ -393,7 +397,7 @@ VALUE rhrdt__add_months(VALUE self, long n) {
393
397
  x = rhrd__days_in_month(newd->year, newd->month);
394
398
  newd->day = (unsigned char)(d->day > x ? x : d->day);
395
399
  RHR_CHECK_CIVIL(newd)
396
- newd->flags &= ~RHR_HAVE_JD;
400
+ newd->flags &= (unsigned char)~RHR_HAVE_JD;
397
401
  return new;
398
402
  }
399
403
 
@@ -430,9 +434,9 @@ void rhrdt__fill_from_hash(rhrdt_t *dt, VALUE hash) {
430
434
  dt->jd = rhrd__unix_to_jd(time_set);
431
435
  time_set = rhrd__modll(time_set, RHR_SECONDS_PER_DAY);
432
436
  dt->nanos = time_set*RHR_NANOS_PER_SECOND + nanos;
433
- dt->hour = time_set/RHR_SECONDS_PER_HOUR;
434
- dt->minute = (time_set - dt->hour * RHR_SECONDS_PER_HOUR)/60;
435
- dt->second = rhrd__mod(time_set, 60);
437
+ dt->hour = (unsigned char)(time_set/RHR_SECONDS_PER_HOUR);
438
+ dt->minute = (unsigned char)((time_set - dt->hour * RHR_SECONDS_PER_HOUR)/60);
439
+ dt->second = (unsigned char)rhrd__mod((long)time_set, 60);
436
440
  offset /= 60;
437
441
  rhrdt__check_offset(offset);
438
442
  RHR_CHECK_JD(dt);
@@ -505,7 +509,7 @@ VALUE rhrdt__new_offset(VALUE self, double offset) {
505
509
  Data_Get_Struct(self, rhrdt_t, dt);
506
510
  RHRDT_FILL_JD(dt)
507
511
  RHRDT_FILL_NANOS(dt)
508
- return rhrdt__from_jd_nanos(dt->jd, dt->nanos - (dt->offset - offset_min)*RHR_NANOS_PER_MINUTE, offset_min);
512
+ return rhrdt__from_jd_nanos(dt->jd, dt->nanos - (dt->offset - offset_min)*RHR_NANOS_PER_MINUTE, (short)offset_min);
509
513
  }
510
514
 
511
515
  /* Class methods */
@@ -541,7 +545,7 @@ static VALUE rhrdt_s__load(VALUE klass, VALUE string) {
541
545
 
542
546
  x = NUM2LONG(rb_ary_entry(ary, 2));
543
547
  rhrdt__check_offset(x);
544
- d->offset = x;
548
+ d->offset = (short)x;
545
549
 
546
550
  d->flags = RHR_HAVE_JD | RHR_HAVE_NANOS;
547
551
  return rd;
@@ -765,9 +769,9 @@ static VALUE rhrdt_s_new_b(int argc, VALUE *argv, VALUE klass) {
765
769
  rhrdt__set_offset(dt, offset);
766
770
  case 1:
767
771
  offset += NUM2DBL(argv[0]) + 0.5;
768
- dt->jd = offset;
772
+ dt->jd = (long)offset;
769
773
  RHR_CHECK_JD(dt)
770
- dt->nanos = (offset - dt->jd)*RHR_NANOS_PER_DAY;
774
+ dt->nanos = (long long)((offset - dt->jd)*RHR_NANOS_PER_DAY);
771
775
  dt->flags = RHR_HAVE_JD | RHR_HAVE_NANOS;
772
776
  break;
773
777
  default:
@@ -949,7 +953,7 @@ static VALUE rhrdt_ajd(VALUE self) {
949
953
  Data_Get_Struct(self, rhrdt_t, d);
950
954
  RHRDT_FILL_JD(d)
951
955
  RHRDT_FILL_NANOS(d)
952
- return rb_float_new(d->jd + d->nanos/RHR_NANOS_PER_DAYD - d->offset/1440.0 - 0.5);
956
+ return rb_float_new(d->jd + (double)d->nanos/RHR_NANOS_PER_DAYD - d->offset/1440.0 - 0.5);
953
957
  }
954
958
 
955
959
  /* call-seq:
@@ -963,7 +967,7 @@ static VALUE rhrdt_amjd(VALUE self) {
963
967
  Data_Get_Struct(self, rhrdt_t, d);
964
968
  RHRDT_FILL_JD(d)
965
969
  RHRDT_FILL_NANOS(d)
966
- return rb_float_new(d->jd + d->nanos/RHR_NANOS_PER_DAYD - d->offset/1440.0 - RHR_JD_MJD);
970
+ return rb_float_new(d->jd + (double)d->nanos/RHR_NANOS_PER_DAYD - d->offset/1440.0 - RHR_JD_MJD);
967
971
  }
968
972
 
969
973
  /* call-seq:
@@ -984,10 +988,10 @@ static VALUE rhrdt_asctime(VALUE self) {
984
988
  RHRDT_FILL_HMS(d)
985
989
 
986
990
  s = rb_str_buf_new(128);
987
- len = snprintf(RSTRING_PTR(s), 128, "%s %s %2hhi %02hhi:%02hhi:%02hhi %04li",
991
+ len = snprintf(RSTRING_PTR(s), 128, "%s %s %2i %02i:%02i:%02i %04li",
988
992
  rhrd__abbr_day_names[rhrd__jd_to_wday(d->jd)],
989
993
  rhrd__abbr_month_names[d->month],
990
- d->day, d->hour, d->minute, d->second,
994
+ (int)d->day, (int)d->hour, (int)d->minute, (int)d->second,
991
995
  d->year);
992
996
  if (len == -1 || len > 127) {
993
997
  rb_raise(rb_eNoMemError, "in DateTime#asctime (in snprintf)");
@@ -1096,7 +1100,7 @@ static VALUE rhrdt_day_fraction(VALUE self) {
1096
1100
  rhrdt_t *dt;
1097
1101
  Data_Get_Struct(self, rhrdt_t, dt);
1098
1102
  RHRDT_FILL_NANOS(dt)
1099
- return rb_float_new(dt->nanos/RHR_NANOS_PER_DAYD);
1103
+ return rb_float_new((double)dt->nanos/RHR_NANOS_PER_DAYD);
1100
1104
  }
1101
1105
 
1102
1106
  /* call-seq:
@@ -1142,8 +1146,8 @@ static VALUE rhrdt_eql_q(VALUE self, VALUE other) {
1142
1146
  long diff;
1143
1147
 
1144
1148
  if (RTEST(rb_obj_is_kind_of(other, rhrdt_class))) {
1145
- self = rhrdt__new_offset(self, 0);
1146
- other = rhrdt__new_offset(other, 0);
1149
+ self = rhrdt__new_offset(self, 0.0);
1150
+ other = rhrdt__new_offset(other, 0.0);
1147
1151
  Data_Get_Struct(self, rhrdt_t, dt);
1148
1152
  Data_Get_Struct(other, rhrdt_t, odt);
1149
1153
  return rhrdt__spaceship(dt, odt) == 0 ? Qtrue : Qfalse;
@@ -1170,8 +1174,9 @@ static VALUE rhrdt_eql_q(VALUE self, VALUE other) {
1170
1174
  */
1171
1175
  static VALUE rhrdt_hash(VALUE self) {
1172
1176
  rhrdt_t *d;
1177
+ VALUE new = rhrdt__new_offset(self, 0.0);
1173
1178
  RHR_CACHED_IV(self, rhrd_id_hash)
1174
- Data_Get_Struct(rhrdt__new_offset(self, 0), rhrdt_t, d);
1179
+ Data_Get_Struct(new, rhrdt_t, d);
1175
1180
  return rb_ivar_set(self, rhrd_id_hash, rb_funcall(rb_ary_new3(2, LONG2NUM(d->jd), LL2NUM(d->nanos)), rhrd_id_hash, 0));
1176
1181
  }
1177
1182
 
@@ -1208,8 +1213,8 @@ static VALUE rhrdt_inspect(VALUE self) {
1208
1213
  RHRDT_FILL_HMS(dt)
1209
1214
 
1210
1215
  s = rb_str_buf_new(128);
1211
- len = snprintf(RSTRING_PTR(s), 128, "#<DateTime %04li-%02hhi-%02hhiT%02hhi:%02hhi:%02hhi%+03i:%02i>",
1212
- dt->year, dt->month, dt->day, dt->hour, dt->minute, dt->second, dt->offset/60, abs(dt->offset % 60));
1216
+ len = snprintf(RSTRING_PTR(s), 128, "#<DateTime %04li-%02i-%02iT%02i:%02i:%02i%+03i:%02i>",
1217
+ dt->year, (int)dt->month, (int)dt->day, (int)dt->hour, (int)dt->minute, (int)dt->second, dt->offset/60, abs(dt->offset % 60));
1213
1218
  if (len == -1 || len > 127) {
1214
1219
  rb_raise(rb_eNoMemError, "in DateTime#inspect (in snprintf)");
1215
1220
  }
@@ -1357,7 +1362,7 @@ static VALUE rhrdt_new_offset(int argc, VALUE *argv, VALUE self) {
1357
1362
  * # => #<DateTime 2009-01-03T12:00:00+00:00>
1358
1363
  */
1359
1364
  static VALUE rhrdt_next(VALUE self) {
1360
- return rhrdt__add_days(self, 1);
1365
+ return rhrdt__add_days(self, 1.0);
1361
1366
  }
1362
1367
 
1363
1368
  /* call-seq:
@@ -1395,17 +1400,27 @@ static VALUE rhrdt_sec(VALUE self) {
1395
1400
  /* call-seq:
1396
1401
  * sec_fraction() -> Float
1397
1402
  *
1398
- * Returns a +Float+ representing the fraction of the second as a
1403
+ * On ruby 1.8, returns a +Float+ representing the fraction of the second as a
1399
1404
  * fraction of the day, which will always be in the range [0.0, 1/86400.0).
1400
1405
  *
1401
1406
  * (DateTime.civil(2009, 1, 2, 12, 13, 14) + (1.5/86400)).sec_fraction
1402
1407
  * # => 0.000005787037
1408
+ *
1409
+ * On ruby 1.9, returns a +Float+ representing the fraction of the second, which
1410
+ * will always be in the range [0,1).
1411
+ *
1412
+ * (DateTime.civil(2009, 1, 2, 12, 13, 14) + (1.5/86400)).sec_fraction
1413
+ * # => 0.5
1403
1414
  */
1404
1415
  static VALUE rhrdt_sec_fraction(VALUE self) {
1405
1416
  rhrdt_t *dt;
1406
1417
  Data_Get_Struct(self, rhrdt_t, dt);
1407
1418
  RHRDT_FILL_NANOS(dt)
1408
- return rb_float_new((dt->nanos % RHR_NANOS_PER_SECOND)/RHR_NANOS_PER_DAYD);
1419
+ #ifdef RUBY19
1420
+ return rb_float_new((double)(dt->nanos % RHR_NANOS_PER_SECOND)/RHR_NANOS_PER_SECONDD);
1421
+ #else
1422
+ return rb_float_new((double)(dt->nanos % RHR_NANOS_PER_SECOND)/RHR_NANOS_PER_DAYD);
1423
+ #endif
1409
1424
  }
1410
1425
 
1411
1426
  /* call-seq:
@@ -1438,9 +1453,10 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1438
1453
  double step, limit;
1439
1454
  long long step_nanos, limit_nanos, current_nanos;
1440
1455
  long step_jd, limit_jd, current_jd;
1441
- VALUE rlimit, new, rstep;
1456
+ VALUE rlimit, new, rstep, new_off;
1457
+ new_off = rhrdt__new_offset(self, 0.0);
1442
1458
  Data_Get_Struct(self, rhrdt_t, d);
1443
- Data_Get_Struct(rhrdt__new_offset(self, 0), rhrdt_t, d0);
1459
+ Data_Get_Struct(new_off, rhrdt_t, d0);
1444
1460
 
1445
1461
  switch(argc) {
1446
1462
  case 1:
@@ -1451,7 +1467,7 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1451
1467
  case 2:
1452
1468
  rstep = argv[1];
1453
1469
  step = NUM2DBL(rstep);
1454
- step_jd = floor(step);
1470
+ step_jd = (long)floor(step);
1455
1471
  step_nanos = llround((step - step_jd)*RHR_NANOS_PER_DAY);
1456
1472
  break;
1457
1473
  default:
@@ -1470,10 +1486,10 @@ static VALUE rhrdt_step(int argc, VALUE *argv, VALUE self) {
1470
1486
 
1471
1487
  if (RTEST(rb_obj_is_kind_of(rlimit, rb_cNumeric))) {
1472
1488
  limit = NUM2DBL(rlimit);
1473
- limit_jd = floor(limit);
1489
+ limit_jd = (long)floor(limit);
1474
1490
  limit_nanos = llround((limit - limit_jd)*RHR_NANOS_PER_DAY);
1475
1491
  } else if (RTEST((rb_obj_is_kind_of(rlimit, rhrdt_class)))) {
1476
- rlimit = rhrdt__new_offset(rlimit, 0);
1492
+ rlimit = rhrdt__new_offset(rlimit, 0.0);
1477
1493
  Data_Get_Struct(rlimit, rhrdt_t, ndt);
1478
1494
  RHRDT_FILL_JD(ndt)
1479
1495
  RHRDT_FILL_NANOS(ndt)
@@ -1571,8 +1587,8 @@ static VALUE rhrdt_to_s(VALUE self) {
1571
1587
  RHRDT_FILL_HMS(dt)
1572
1588
 
1573
1589
  s = rb_str_buf_new(128);
1574
- len = snprintf(RSTRING_PTR(s), 128, "%04li-%02hhi-%02hhiT%02hhi:%02hhi:%02hhi%+03i:%02i",
1575
- dt->year, dt->month, dt->day, dt->hour, dt->minute, dt->second, dt->offset/60, abs(dt->offset % 60));
1590
+ len = snprintf(RSTRING_PTR(s), 128, "%04li-%02i-%02iT%02i:%02i:%02i%+03i:%02i",
1591
+ dt->year, (int)dt->month, (int)dt->day, (int)dt->hour, (int)dt->minute, (int)dt->second, dt->offset/60, abs(dt->offset % 60));
1576
1592
  if (len == -1 || len > 127) {
1577
1593
  rb_raise(rb_eNoMemError, "in DateTime#to_s (in snprintf)");
1578
1594
  }
@@ -1772,8 +1788,8 @@ static VALUE rhrdt_op_minus(VALUE self, VALUE other) {
1772
1788
  return rhrdt__add_days(self, -NUM2DBL(other));
1773
1789
  }
1774
1790
  if (RTEST((rb_obj_is_kind_of(other, rhrdt_class)))) {
1775
- self = rhrdt__new_offset(self, 0);
1776
- other = rhrdt__new_offset(other, 0);
1791
+ self = rhrdt__new_offset(self, 0.0);
1792
+ other = rhrdt__new_offset(other, 0.0);
1777
1793
  Data_Get_Struct(self, rhrdt_t, dt);
1778
1794
  Data_Get_Struct(other, rhrdt_t, newdt);
1779
1795
  RHRDT_FILL_JD(dt)
@@ -1781,11 +1797,11 @@ static VALUE rhrdt_op_minus(VALUE self, VALUE other) {
1781
1797
  RHRDT_FILL_JD(newdt)
1782
1798
  RHRDT_FILL_NANOS(newdt)
1783
1799
  if (dt->nanos == newdt->nanos) {
1784
- return rb_float_new(dt->jd - newdt->jd);
1800
+ return rb_float_new((double)(dt->jd - newdt->jd));
1785
1801
  } else if (dt->jd == newdt->jd)
1786
- return rb_float_new((dt->nanos - newdt->nanos)/RHR_NANOS_PER_DAYD);
1802
+ return rb_float_new((double)(dt->nanos - newdt->nanos)/RHR_NANOS_PER_DAYD);
1787
1803
  else {
1788
- return rb_float_new((dt->jd - newdt->jd) + (dt->nanos - newdt->nanos)/RHR_NANOS_PER_DAYD);
1804
+ return rb_float_new((dt->jd - newdt->jd) + (double)(dt->nanos - newdt->nanos)/RHR_NANOS_PER_DAYD);
1789
1805
  }
1790
1806
  }
1791
1807
  if (RTEST((rb_obj_is_kind_of(other, rhrd_class)))) {
@@ -1794,7 +1810,7 @@ static VALUE rhrdt_op_minus(VALUE self, VALUE other) {
1794
1810
  RHRDT_FILL_JD(dt)
1795
1811
  RHRDT_FILL_NANOS(dt)
1796
1812
  RHR_FILL_JD(newd)
1797
- return rb_float_new((dt->jd - newd->jd) + dt->nanos/RHR_NANOS_PER_DAYD);
1813
+ return rb_float_new((dt->jd - newd->jd) + (double)dt->nanos/RHR_NANOS_PER_DAYD);
1798
1814
  }
1799
1815
  rb_raise(rb_eTypeError, "expected numeric or date");
1800
1816
  }
@@ -1865,8 +1881,8 @@ static VALUE rhrdt_op_spaceship(VALUE self, VALUE other) {
1865
1881
  int res;
1866
1882
 
1867
1883
  if (RTEST(rb_obj_is_kind_of(other, rhrdt_class))) {
1868
- self = rhrdt__new_offset(self, 0);
1869
- other = rhrdt__new_offset(other, 0);
1884
+ self = rhrdt__new_offset(self, 0.0);
1885
+ other = rhrdt__new_offset(other, 0.0);
1870
1886
  Data_Get_Struct(self, rhrdt_t, dt);
1871
1887
  Data_Get_Struct(other, rhrdt_t, odt);
1872
1888
  return LONG2NUM(rhrdt__spaceship(dt, odt));
@@ -1918,7 +1934,7 @@ VALUE rhrdt__add_years(VALUE self, long n) {
1918
1934
  }
1919
1935
 
1920
1936
  RHR_CHECK_CIVIL(newd)
1921
- newd->flags &= ~RHR_HAVE_JD;
1937
+ newd->flags &= (unsigned char)~RHR_HAVE_JD;
1922
1938
  return new;
1923
1939
  }
1924
1940
 
@@ -1943,7 +1959,7 @@ long rhrdt__add_iso_time_format(rhrdt_t *dt, char *str, long len, long i) {
1943
1959
  i = 9;
1944
1960
  }
1945
1961
 
1946
- l = snprintf(str + len, 128 - len, "T%02hhi:%02hhi:%02hhi", dt->hour, dt->minute, dt->second);
1962
+ l = snprintf(str + len, (size_t)(128 - len), "T%02i:%02i:%02i", (int)dt->hour, (int)dt->minute, (int)dt->second);
1947
1963
  if (l == -1 || l > 127) {
1948
1964
  rb_raise(rb_eNoMemError, "in DateTime formatting method (in snprintf)");
1949
1965
  }
@@ -1951,14 +1967,14 @@ long rhrdt__add_iso_time_format(rhrdt_t *dt, char *str, long len, long i) {
1951
1967
 
1952
1968
  if (i) {
1953
1969
  RHRDT_FILL_NANOS(dt)
1954
- l = snprintf(str + len, 128 - len, ".%09lli", dt->nanos % RHR_NANOS_PER_SECOND);
1970
+ l = snprintf(str + len, (size_t)(128 - len), ".%09lli", dt->nanos % RHR_NANOS_PER_SECOND);
1955
1971
  if (l == -1 || l > 127) {
1956
1972
  rb_raise(rb_eNoMemError, "in DateTime formatting method (in snprintf)");
1957
1973
  }
1958
1974
  len += i + 1;
1959
1975
  }
1960
1976
 
1961
- l = snprintf(str + len, 128 - len, "%+03i:%02i", dt->offset/60, abs(dt->offset % 60));
1977
+ l = snprintf(str + len, (size_t)(128 - len), "%+03i:%02i", dt->offset/60, abs(dt->offset % 60));
1962
1978
  if (l == -1 || l > 127) {
1963
1979
  rb_raise(rb_eNoMemError, "in DateTime formatting method (in snprintf)");
1964
1980
  }
@@ -2193,18 +2209,18 @@ static VALUE rhrdt_httpdate(VALUE self) {
2193
2209
  VALUE s;
2194
2210
  rhrdt_t *d;
2195
2211
  int len;
2196
- s = rhrdt__new_offset(self, 0);
2212
+ s = rhrdt__new_offset(self, 0.0);
2197
2213
  Data_Get_Struct(s, rhrdt_t, d);
2198
2214
  RHRDT_FILL_JD(d)
2199
2215
  RHRDT_FILL_CIVIL(d)
2200
2216
  RHRDT_FILL_HMS(d)
2201
2217
 
2202
2218
  s = rb_str_buf_new(128);
2203
- len = snprintf(RSTRING_PTR(s), 128, "%s, %02hhi %s %04li %02hhi:%02hhi:%02hhi GMT",
2219
+ len = snprintf(RSTRING_PTR(s), 128, "%s, %02i %s %04li %02i:%02i:%02i GMT",
2204
2220
  rhrd__abbr_day_names[rhrd__jd_to_wday(d->jd)],
2205
- d->day,
2221
+ (int)d->day,
2206
2222
  rhrd__abbr_month_names[d->month],
2207
- d->year, d->hour, d->minute, d->second);
2223
+ d->year, (int)d->hour, (int)d->minute, (int)d->second);
2208
2224
  if (len == -1 || len > 127) {
2209
2225
  rb_raise(rb_eNoMemError, "in DateTime#httpdate (in snprintf)");
2210
2226
  }
@@ -2250,7 +2266,7 @@ static VALUE rhrdt_iso8601(int argc, VALUE *argv, VALUE self) {
2250
2266
  s = rb_str_buf_new(128);
2251
2267
  str = RSTRING_PTR(s);
2252
2268
 
2253
- len = snprintf(str, 128, "%04li-%02hhi-%02hhi", dt->year, dt->month, dt->day);
2269
+ len = snprintf(str, 128, "%04li-%02i-%02i", dt->year, (int)dt->month, (int)dt->day);
2254
2270
  if (len == -1 || len > 127) {
2255
2271
  rb_raise(rb_eNoMemError, "in DateTime#to_s (in snprintf)");
2256
2272
  }
@@ -2301,7 +2317,7 @@ static VALUE rhrdt_jisx0301(int argc, VALUE *argv, VALUE self) {
2301
2317
  str = RSTRING_PTR(s);
2302
2318
 
2303
2319
  if (d->jd < 2405160) {
2304
- len = snprintf(str, 128, "%04li-%02hhi-%02hhi", d->year, d->month, d->day);
2320
+ len = snprintf(str, 128, "%04li-%02i-%02i", d->year, (int)d->month, (int)d->day);
2305
2321
  } else {
2306
2322
  if (d->jd >= 2447535) {
2307
2323
  c = 'H';
@@ -2316,7 +2332,7 @@ static VALUE rhrdt_jisx0301(int argc, VALUE *argv, VALUE self) {
2316
2332
  c = 'M';
2317
2333
  year = d->year - 1867;
2318
2334
  }
2319
- len = snprintf(RSTRING_PTR(s), 128, "%c%02li.%02hhi.%02hhi", c, year, d->month, d->day);
2335
+ len = snprintf(RSTRING_PTR(s), 128, "%c%02li.%02i.%02i", c, year, (int)d->month, (int)d->day);
2320
2336
  }
2321
2337
  if (len == -1 || len > 127) {
2322
2338
  rb_raise(rb_eNoMemError, "in DateTime#jisx0301 (in snprintf)");
@@ -2354,7 +2370,7 @@ static VALUE rhrdt_next_day(int argc, VALUE *argv, VALUE self) {
2354
2370
  break;
2355
2371
  }
2356
2372
 
2357
- return rhrdt__add_days(self, i);
2373
+ return rhrdt__add_days(self, (double)i);
2358
2374
  }
2359
2375
 
2360
2376
  /* call-seq:
@@ -2447,7 +2463,7 @@ static VALUE rhrdt_prev_day(int argc, VALUE *argv, VALUE self) {
2447
2463
  break;
2448
2464
  }
2449
2465
 
2450
- return rhrdt__add_days(self, i);
2466
+ return rhrdt__add_days(self, (double)i);
2451
2467
  }
2452
2468
 
2453
2469
  /* call-seq:
@@ -2531,11 +2547,11 @@ static VALUE rhrdt_rfc2822(VALUE self) {
2531
2547
  RHRDT_FILL_HMS(d)
2532
2548
 
2533
2549
  s = rb_str_buf_new(128);
2534
- len = snprintf(RSTRING_PTR(s), 128, "%s, %hhi %s %04li %02hhi:%02hhi:%02hhi %+03i%02i",
2550
+ len = snprintf(RSTRING_PTR(s), 128, "%s, %i %s %04li %02i:%02i:%02i %+03i%02i",
2535
2551
  rhrd__abbr_day_names[rhrd__jd_to_wday(d->jd)],
2536
- d->day,
2552
+ (int)d->day,
2537
2553
  rhrd__abbr_month_names[d->month],
2538
- d->year, d->hour, d->minute, d->second, d->offset/60, abs(d->offset % 60));
2554
+ d->year, (int)d->hour, (int)d->minute, (int)d->second, d->offset/60, abs(d->offset % 60));
2539
2555
  if (len == -1 || len > 127) {
2540
2556
  rb_raise(rb_eNoMemError, "in DateTime#rfc2822 (in snprintf)");
2541
2557
  }
@@ -2594,10 +2610,10 @@ static VALUE rhrdt_to_time(VALUE self) {
2594
2610
  RHRDT_FILL_CIVIL(dt)
2595
2611
  RHRDT_FILL_HMS(dt)
2596
2612
 
2597
- s = dt->nanos/RHR_NANOS_PER_SECOND;
2613
+ s = (long)(dt->nanos/RHR_NANOS_PER_SECOND);
2598
2614
  h = s/RHR_SECONDS_PER_HOUR;
2599
2615
  m = (s % RHR_SECONDS_PER_HOUR) / 60;
2600
- return rb_funcall(rb_funcall(rb_cTime, rhrd_id_utc, 6, LONG2NUM(dt->year), LONG2NUM(dt->month), LONG2NUM(dt->day), LONG2NUM(h), LONG2NUM(m), rb_float_new(s % 60 + (dt->nanos % RHR_NANOS_PER_SECOND)/RHR_NANOS_PER_SECONDD)), rhrd_id_localtime, 0);
2616
+ return rb_funcall(rb_funcall(rb_cTime, rhrd_id_utc, 6, LONG2NUM(dt->year), LONG2NUM(dt->month), LONG2NUM(dt->day), LONG2NUM(h), LONG2NUM(m), rb_float_new(s % 60 + (double)(dt->nanos % RHR_NANOS_PER_SECOND)/RHR_NANOS_PER_SECONDD)), rhrd_id_localtime, 0);
2601
2617
  }
2602
2618
 
2603
2619
  /* call-seq:
@@ -2624,7 +2640,7 @@ static VALUE rhrdt_time_to_datetime(VALUE self) {
2624
2640
  #else
2625
2641
  dt->nanos = rhrd__mod(t, RHR_SECONDS_PER_DAY) * RHR_NANOS_PER_SECOND + NUM2LONG(rb_funcall(self, rhrd_id_usec, 0)) * 1000;
2626
2642
  #endif
2627
- dt->offset = offset/60;
2643
+ dt->offset = (short)(offset/60);
2628
2644
  dt->flags |= RHR_HAVE_JD | RHR_HAVE_NANOS;
2629
2645
  RHR_CHECK_JD(dt);
2630
2646
  return rd;
@@ -3,4 +3,6 @@ $CFLAGS << " -DRUBY19" if RUBY_VERSION >= '1.9.0'
3
3
  $CFLAGS << " -DRUBY186" if RUBY_VERSION < '1.8.7'
4
4
  $CFLAGS << " -Wall " unless RUBY_PLATFORM =~ /solaris/
5
5
  $CFLAGS << ' -g -ggdb -rdynamic -O0 -DDEBUG' if ENV['DEBUG']
6
+ $CFLAGS << " -Wconversion -Wsign-compare -Wno-unused-parameter -Wwrite-strings -Wpointer-arith -fno-common -pedantic -Wno-long-long" if ENV['STRICT']
7
+ $CFLAGS << (ENV['CFLAGS'] || '')
6
8
  create_makefile("date_ext")
data/lib/1.8/date_ext.so CHANGED
Binary file
data/lib/1.9/date_ext.so CHANGED
Binary file
@@ -40,10 +40,19 @@ describe "DateTime#sec" do
40
40
  end
41
41
 
42
42
  describe "DateTime#sec_fraction" do
43
- it "should be the fraction of a second as a fraction of the day" do
44
- DateTime.new(2008, 1, 1).sec_fraction.should == 0.0
45
- DateTime.parse('12:13:15.678900').sec_fraction.should be_close(7.85763888888889e-06, 0.0000000000001)
46
- end
43
+ ruby_version_is "" ... "1.9" do
44
+ it "should be the fraction of a second as a fraction of the day" do
45
+ DateTime.new(2008, 1, 1).sec_fraction.should == 0.0
46
+ DateTime.parse('12:13:15.678900').sec_fraction.should be_close(7.85763888888889e-06, 0.0000000000001)
47
+ end
48
+ end
49
+
50
+ ruby_version_is "1.9" do
51
+ it "should be the fraction of a second" do
52
+ DateTime.new(2008, 1, 1).sec_fraction.should == 0.0
53
+ DateTime.parse('12:13:15.678900').sec_fraction.should be_close(0.6789, 0.0000000000001)
54
+ end
55
+ end
47
56
  end
48
57
 
49
58
  describe "DateTime#zone" do
@@ -1,7 +1,16 @@
1
1
  require File.expand_path('../../spec_helper', __FILE__)
2
2
 
3
- describe "DateTime#parse" do
3
+ describe "DateTime._parse" do
4
+ it "should return a hash of values" do
5
+ DateTime._parse("01:02:03").should == {:hour=>1, :min=>2, :sec=>3}
6
+ end
7
+
8
+ it "should have :sec_fraction entry be the fraction of second" do
9
+ DateTime._parse('12:13:15.678900')[:sec_fraction].should be_close(0.6789, 0.0000000000001)
10
+ end
11
+ end
4
12
 
13
+ describe "DateTime.parse" do
5
14
  it "should have defaults and an optional sg value" do
6
15
  DateTime.parse('2008-10-11').should == DateTime.civil(2008, 10, 11)
7
16
  DateTime.parse('2008-10-11', true).should == DateTime.civil(2008, 10, 11)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: home_run
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: x86-mingw32
12
12
  authors:
13
13
  - Jeremy Evans
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-31 00:00:00 -07:00
18
+ date: 2010-09-12 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies: []
21
21