date 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of date might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fa112c995a20e5310b0d736088be7c3abc5b3a6de817b4d511f65c957d6949e
4
- data.tar.gz: ed868848f6cfa0f172296a511d1f1fe82e833ac469d4ba342ff8bd8f208ffc1a
3
+ metadata.gz: 5bc19b4489b002663b78093d39f13ac29000d0457dd9e4c7d0a1c1c77fe623bf
4
+ data.tar.gz: ae8933e1cd0ecb6b2d9219e24ca857ec648eadf2e1b2893367cf1fb0d8ca7763
5
5
  SHA512:
6
- metadata.gz: cf7d8b67c199e8d4619893d5a4933663d64996a10d5baaf7381c6c9fe673cfed15d7ad04ff4df039f0704344568d5af2a469679cc670b208f3634125c456ba11
7
- data.tar.gz: 9ce68c93915cf79ecddf6ed8a705b15fdc0a3555491e60dcc5ea7c8db7fb894adc5d8fc01e1c3247cb68012e9ff4d10f9d8621ddadb486a032ea5418d3a15248
6
+ metadata.gz: 51f50fb953dbf4aa82c35e3e6145e0ce10c8696ec17f9577339297ee0cfc6b4fb8f0bfa05d353e2571f5963ef8f1a53dfe351b69b9acf756212b1283629f2b9d
7
+ data.tar.gz: ddc9ed30e31c2dc6bb29af2c25457338d46c73ca81d73cc6fb90312d5b837b8bd1784fc3e8236f36f7f4e74a2590e36637b3b4acfffa4119119f562ef3da7c30
@@ -51,18 +51,21 @@ static double positive_inf, negative_inf;
51
51
  #define f_add3(x,y,z) f_add(f_add(x, y), z)
52
52
  #define f_sub3(x,y,z) f_sub(f_sub(x, y), z)
53
53
 
54
- inline static VALUE
54
+ static VALUE date_initialize(int argc, VALUE *argv, VALUE self);
55
+ static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self);
56
+
57
+ inline static int
55
58
  f_cmp(VALUE x, VALUE y)
56
59
  {
57
60
  if (FIXNUM_P(x) && FIXNUM_P(y)) {
58
61
  long c = FIX2LONG(x) - FIX2LONG(y);
59
62
  if (c > 0)
60
- c = 1;
63
+ return 1;
61
64
  else if (c < 0)
62
- c = -1;
63
- return INT2FIX(c);
65
+ return -1;
66
+ return 0;
64
67
  }
65
- return rb_funcall(x, id_cmp, 1, y);
68
+ return rb_cmpint(rb_funcallv(x, id_cmp, 1, &y), x, y);
66
69
  }
67
70
 
68
71
  inline static VALUE
@@ -94,7 +97,7 @@ f_ge_p(VALUE x, VALUE y)
94
97
  {
95
98
  if (FIXNUM_P(x) && FIXNUM_P(y))
96
99
  return f_boolcast(FIX2LONG(x) >= FIX2LONG(y));
97
- return rb_funcall(x, rb_intern(">="), 1, y);
100
+ return rb_funcall(x, id_ge_p, 1, y);
98
101
  }
99
102
 
100
103
  inline static VALUE
@@ -102,7 +105,7 @@ f_eqeq_p(VALUE x, VALUE y)
102
105
  {
103
106
  if (FIXNUM_P(x) && FIXNUM_P(y))
104
107
  return f_boolcast(FIX2LONG(x) == FIX2LONG(y));
105
- return rb_funcall(x, rb_intern("=="), 1, y);
108
+ return rb_funcall(x, id_eqeq_p, 1, y);
106
109
  }
107
110
 
108
111
  inline static VALUE
@@ -236,11 +239,8 @@ f_negative_p(VALUE x)
236
239
  struct SimpleDateData
237
240
  {
238
241
  unsigned flags;
239
- VALUE nth; /* not always canonicalized */
240
242
  int jd; /* as utc */
241
- /* df is zero */
242
- /* sf is zero */
243
- /* of is zero */
243
+ VALUE nth; /* not always canonicalized */
244
244
  date_sg_t sg; /* 2298874..2426355 or -/+oo -- at most 22 bits */
245
245
  /* decoded as utc=local */
246
246
  int year; /* truncated */
@@ -259,11 +259,8 @@ struct SimpleDateData
259
259
  struct ComplexDateData
260
260
  {
261
261
  unsigned flags;
262
- VALUE nth; /* not always canonicalized */
263
262
  int jd; /* as utc */
264
- int df; /* as utc, in secs */
265
- VALUE sf; /* in nano secs */
266
- int of; /* in secs */
263
+ VALUE nth; /* not always canonicalized */
267
264
  date_sg_t sg; /* 2298874..2426355 or -/+oo -- at most 22 bits */
268
265
  /* decoded as local */
269
266
  int year; /* truncated */
@@ -277,6 +274,9 @@ struct ComplexDateData
277
274
  /* packed civil */
278
275
  unsigned pc;
279
276
  #endif
277
+ int df; /* as utc, in secs */
278
+ int of; /* in secs */
279
+ VALUE sf; /* in nano secs */
280
280
  };
281
281
 
282
282
  union DateData {
@@ -315,31 +315,31 @@ canon(VALUE x)
315
315
 
316
316
  #ifndef USE_PACK
317
317
  #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
318
- {\
318
+ do {\
319
319
  RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
320
320
  (x)->jd = _jd;\
321
321
  (x)->sg = (date_sg_t)(_sg);\
322
322
  (x)->year = _year;\
323
323
  (x)->mon = _mon;\
324
324
  (x)->mday = _mday;\
325
- (x)->flags = _flags;\
326
- }
325
+ (x)->flags = (_flags) & ~COMPLEX_DAT;\
326
+ } while (0)
327
327
  #else
328
328
  #define set_to_simple(obj, x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
329
- {\
329
+ do {\
330
330
  RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth)); \
331
331
  (x)->jd = _jd;\
332
332
  (x)->sg = (date_sg_t)(_sg);\
333
333
  (x)->year = _year;\
334
334
  (x)->pc = PACK2(_mon, _mday);\
335
- (x)->flags = _flags;\
336
- }
335
+ (x)->flags = (_flags) & ~COMPLEX_DAT;\
336
+ } while (0)
337
337
  #endif
338
338
 
339
339
  #ifndef USE_PACK
340
340
  #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
341
341
  _year, _mon, _mday, _hour, _min, _sec, _flags) \
342
- {\
342
+ do {\
343
343
  RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
344
344
  (x)->jd = _jd;\
345
345
  (x)->df = _df;\
@@ -352,12 +352,12 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \
352
352
  (x)->hour = _hour;\
353
353
  (x)->min = _min;\
354
354
  (x)->sec = _sec;\
355
- (x)->flags = _flags;\
356
- }
355
+ (x)->flags = (_flags) | COMPLEX_DAT;\
356
+ } while (0)
357
357
  #else
358
358
  #define set_to_complex(obj, x, _nth, _jd ,_df, _sf, _of, _sg,\
359
359
  _year, _mon, _mday, _hour, _min, _sec, _flags) \
360
- {\
360
+ do {\
361
361
  RB_OBJ_WRITE((obj), &(x)->nth, canon(_nth));\
362
362
  (x)->jd = _jd;\
363
363
  (x)->df = _df;\
@@ -366,13 +366,13 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \
366
366
  (x)->sg = (date_sg_t)(_sg);\
367
367
  (x)->year = _year;\
368
368
  (x)->pc = PACK5(_mon, _mday, _hour, _min, _sec);\
369
- (x)->flags = _flags;\
370
- }
369
+ (x)->flags = (_flags) | COMPLEX_DAT;\
370
+ } while (0)
371
371
  #endif
372
372
 
373
373
  #ifndef USE_PACK
374
374
  #define copy_simple_to_complex(obj, x, y) \
375
- {\
375
+ do {\
376
376
  RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
377
377
  (x)->jd = (y)->jd;\
378
378
  (x)->df = 0;\
@@ -386,10 +386,10 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \
386
386
  (x)->min = 0;\
387
387
  (x)->sec = 0;\
388
388
  (x)->flags = (y)->flags;\
389
- }
389
+ } while (0)
390
390
  #else
391
391
  #define copy_simple_to_complex(obj, x, y) \
392
- {\
392
+ do {\
393
393
  RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
394
394
  (x)->jd = (y)->jd;\
395
395
  (x)->df = 0;\
@@ -399,12 +399,12 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \
399
399
  (x)->year = (y)->year;\
400
400
  (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
401
401
  (x)->flags = (y)->flags;\
402
- }
402
+ } while (0)
403
403
  #endif
404
404
 
405
405
  #ifndef USE_PACK
406
406
  #define copy_complex_to_simple(obj, x, y) \
407
- {\
407
+ do {\
408
408
  RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
409
409
  (x)->jd = (y)->jd;\
410
410
  (x)->sg = (date_sg_t)((y)->sg);\
@@ -412,17 +412,17 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \
412
412
  (x)->mon = (y)->mon;\
413
413
  (x)->mday = (y)->mday;\
414
414
  (x)->flags = (y)->flags;\
415
- }
415
+ } while (0)
416
416
  #else
417
417
  #define copy_complex_to_simple(obj, x, y) \
418
- {\
418
+ do {\
419
419
  RB_OBJ_WRITE((obj), &(x)->nth, (y)->nth);\
420
420
  (x)->jd = (y)->jd;\
421
421
  (x)->sg = (date_sg_t)((y)->sg);\
422
422
  (x)->year = (y)->year;\
423
423
  (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
424
424
  (x)->flags = (y)->flags;\
425
- }
425
+ } while (0)
426
426
  #endif
427
427
 
428
428
  /* base */
@@ -1109,7 +1109,7 @@ m_virtual_sg(union DateData *x)
1109
1109
  }
1110
1110
 
1111
1111
  #define canonicalize_jd(_nth, _jd) \
1112
- {\
1112
+ do {\
1113
1113
  if (_jd < 0) {\
1114
1114
  _nth = f_sub(_nth, INT2FIX(1));\
1115
1115
  _jd += CM_PERIOD;\
@@ -1118,7 +1118,7 @@ m_virtual_sg(union DateData *x)
1118
1118
  _nth = f_add(_nth, INT2FIX(1));\
1119
1119
  _jd -= CM_PERIOD;\
1120
1120
  }\
1121
- }
1121
+ } while (0)
1122
1122
 
1123
1123
  inline static void
1124
1124
  canonicalize_s_jd(VALUE obj, union DateData *x)
@@ -1928,13 +1928,13 @@ m_sec(union DateData *x)
1928
1928
  }
1929
1929
 
1930
1930
  #define decode_offset(of,s,h,m)\
1931
- {\
1931
+ do {\
1932
1932
  int a;\
1933
1933
  s = (of < 0) ? '-' : '+';\
1934
1934
  a = (of < 0) ? -of : of;\
1935
1935
  h = a / HOUR_IN_SECONDS;\
1936
1936
  m = a % HOUR_IN_SECONDS / MINUTE_IN_SECONDS;\
1937
- }
1937
+ } while (0)
1938
1938
 
1939
1939
  static VALUE
1940
1940
  of2str(int of)
@@ -2333,6 +2333,9 @@ VALUE date_zone_to_diff(VALUE);
2333
2333
  static int
2334
2334
  offset_to_sec(VALUE vof, int *rof)
2335
2335
  {
2336
+ int try_rational = 1;
2337
+
2338
+ again:
2336
2339
  switch (TYPE(vof)) {
2337
2340
  case T_FIXNUM:
2338
2341
  {
@@ -2359,10 +2362,11 @@ offset_to_sec(VALUE vof, int *rof)
2359
2362
  default:
2360
2363
  expect_numeric(vof);
2361
2364
  vof = f_to_r(vof);
2362
- #ifdef CANONICALIZATION_FOR_MATHN
2363
- if (!k_rational_p(vof))
2364
- return offset_to_sec(vof, rof);
2365
- #endif
2365
+ if (!k_rational_p(vof)) {
2366
+ if (!try_rational) Check_Type(vof, T_RATIONAL);
2367
+ try_rational = 0;
2368
+ goto again;
2369
+ }
2366
2370
  /* fall through */
2367
2371
  case T_RATIONAL:
2368
2372
  {
@@ -2371,17 +2375,10 @@ offset_to_sec(VALUE vof, int *rof)
2371
2375
 
2372
2376
  vs = day_to_sec(vof);
2373
2377
 
2374
- #ifdef CANONICALIZATION_FOR_MATHN
2375
2378
  if (!k_rational_p(vs)) {
2376
- if (!FIXNUM_P(vs))
2377
- return 0;
2378
- n = FIX2LONG(vs);
2379
- if (n < -DAY_IN_SECONDS || n > DAY_IN_SECONDS)
2380
- return 0;
2381
- *rof = (int)n;
2382
- return 1;
2379
+ vn = vs;
2380
+ goto rounded;
2383
2381
  }
2384
- #endif
2385
2382
  vn = rb_rational_num(vs);
2386
2383
  vd = rb_rational_den(vs);
2387
2384
 
@@ -2391,6 +2388,7 @@ offset_to_sec(VALUE vof, int *rof)
2391
2388
  vn = f_round(vs);
2392
2389
  if (!f_eqeq_p(vn, vs))
2393
2390
  rb_warning("fraction of offset is ignored");
2391
+ rounded:
2394
2392
  if (!FIXNUM_P(vn))
2395
2393
  return 0;
2396
2394
  n = FIX2LONG(vn);
@@ -2420,12 +2418,12 @@ offset_to_sec(VALUE vof, int *rof)
2420
2418
  /* date */
2421
2419
 
2422
2420
  #define valid_sg(sg) \
2423
- {\
2421
+ do {\
2424
2422
  if (!c_valid_start_p(sg)) {\
2425
2423
  sg = 0;\
2426
2424
  rb_warning("invalid start is ignored");\
2427
2425
  }\
2428
- }
2426
+ } while (0)
2429
2427
 
2430
2428
  static VALUE
2431
2429
  valid_jd_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
@@ -2968,7 +2966,7 @@ d_simple_new_internal(VALUE klass,
2968
2966
 
2969
2967
  obj = TypedData_Make_Struct(klass, struct SimpleDateData,
2970
2968
  &d_lite_type, dat);
2971
- set_to_simple(obj, dat, nth, jd, sg, y, m, d, flags & ~COMPLEX_DAT);
2969
+ set_to_simple(obj, dat, nth, jd, sg, y, m, d, flags);
2972
2970
 
2973
2971
  assert(have_jd_p(dat) || have_civil_p(dat));
2974
2972
 
@@ -2990,7 +2988,7 @@ d_complex_new_internal(VALUE klass,
2990
2988
  obj = TypedData_Make_Struct(klass, struct ComplexDateData,
2991
2989
  &d_lite_type, dat);
2992
2990
  set_to_complex(obj, dat, nth, jd, df, sf, of, sg,
2993
- y, m, d, h, min, s, flags | COMPLEX_DAT);
2991
+ y, m, d, h, min, s, flags);
2994
2992
 
2995
2993
  assert(have_jd_p(dat) || have_civil_p(dat));
2996
2994
  assert(have_df_p(dat) || have_time_p(dat));
@@ -3207,47 +3205,47 @@ s_trunc(VALUE s, VALUE *fr)
3207
3205
  }
3208
3206
 
3209
3207
  #define num2num_with_frac(s,n) \
3210
- {\
3208
+ do {\
3211
3209
  s = s##_trunc(v##s, &fr);\
3212
3210
  if (f_nonzero_p(fr)) {\
3213
3211
  if (argc > n)\
3214
3212
  rb_raise(rb_eArgError, "invalid fraction");\
3215
3213
  fr2 = fr;\
3216
3214
  }\
3217
- }
3215
+ } while (0)
3218
3216
 
3219
3217
  #define num2int_with_frac(s,n) \
3220
- {\
3218
+ do {\
3221
3219
  s = NUM2INT(s##_trunc(v##s, &fr));\
3222
3220
  if (f_nonzero_p(fr)) {\
3223
3221
  if (argc > n)\
3224
3222
  rb_raise(rb_eArgError, "invalid fraction");\
3225
3223
  fr2 = fr;\
3226
3224
  }\
3227
- }
3225
+ } while (0)
3228
3226
 
3229
3227
  #define canon24oc() \
3230
- {\
3228
+ do {\
3231
3229
  if (rh == 24) {\
3232
3230
  rh = 0;\
3233
3231
  fr2 = f_add(fr2, INT2FIX(1));\
3234
3232
  }\
3235
- }
3233
+ } while (0)
3236
3234
 
3237
3235
  #define add_frac() \
3238
- {\
3236
+ do {\
3239
3237
  if (f_nonzero_p(fr2))\
3240
3238
  ret = d_lite_plus(ret, fr2);\
3241
- }
3239
+ } while (0)
3242
3240
 
3243
3241
  #define val2sg(vsg,dsg) \
3244
- {\
3242
+ do {\
3245
3243
  dsg = NUM2DBL(vsg);\
3246
3244
  if (!c_valid_start_p(dsg)) {\
3247
3245
  dsg = DEFAULT_SG;\
3248
3246
  rb_warning("invalid start is ignored");\
3249
3247
  }\
3250
- }
3248
+ } while (0)
3251
3249
 
3252
3250
  static VALUE d_lite_plus(VALUE, VALUE);
3253
3251
 
@@ -3384,10 +3382,21 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
3384
3382
  */
3385
3383
  static VALUE
3386
3384
  date_s_civil(int argc, VALUE *argv, VALUE klass)
3385
+ {
3386
+ return date_initialize(argc, argv, d_lite_s_alloc_simple(klass));
3387
+ }
3388
+
3389
+ static VALUE
3390
+ date_initialize(int argc, VALUE *argv, VALUE self)
3387
3391
  {
3388
3392
  VALUE vy, vm, vd, vsg, y, fr, fr2, ret;
3389
3393
  int m, d;
3390
3394
  double sg;
3395
+ struct SimpleDateData *dat = rb_check_typeddata(self, &d_lite_type);
3396
+
3397
+ if (!simple_dat_p(dat)) {
3398
+ rb_raise(rb_eTypeError, "Date expected");
3399
+ }
3391
3400
 
3392
3401
  rb_scan_args(argc, argv, "04", &vy, &vm, &vd, &vsg);
3393
3402
 
@@ -3417,11 +3426,7 @@ date_s_civil(int argc, VALUE *argv, VALUE klass)
3417
3426
  &rm, &rd))
3418
3427
  rb_raise(rb_eArgError, "invalid date");
3419
3428
 
3420
- ret = d_simple_new_internal(klass,
3421
- nth, 0,
3422
- sg,
3423
- ry, rm, rd,
3424
- HAVE_CIVIL);
3429
+ set_to_simple(self, dat, nth, 0, sg, ry, rm, rd, HAVE_CIVIL);
3425
3430
  }
3426
3431
  else {
3427
3432
  VALUE nth;
@@ -3433,12 +3438,9 @@ date_s_civil(int argc, VALUE *argv, VALUE klass)
3433
3438
  &ns))
3434
3439
  rb_raise(rb_eArgError, "invalid date");
3435
3440
 
3436
- ret = d_simple_new_internal(klass,
3437
- nth, rjd,
3438
- sg,
3439
- ry, rm, rd,
3440
- HAVE_JD | HAVE_CIVIL);
3441
+ set_to_simple(self, dat, nth, rjd, sg, ry, rm, rd, HAVE_JD | HAVE_CIVIL);
3441
3442
  }
3443
+ ret = self;
3442
3444
  add_frac();
3443
3445
  return ret;
3444
3446
  }
@@ -3679,9 +3681,11 @@ date_s_today(int argc, VALUE *argv, VALUE klass)
3679
3681
  #define ref_hash0(k) rb_hash_aref(hash, k)
3680
3682
  #define del_hash0(k) rb_hash_delete(hash, k)
3681
3683
 
3682
- #define set_hash(k,v) rb_hash_aset(hash, ID2SYM(rb_intern(k)), v)
3683
- #define ref_hash(k) rb_hash_aref(hash, ID2SYM(rb_intern(k)))
3684
- #define del_hash(k) rb_hash_delete(hash, ID2SYM(rb_intern(k)))
3684
+ #define sym(x) ID2SYM(rb_intern(x""))
3685
+
3686
+ #define set_hash(k,v) set_hash0(sym(k), v)
3687
+ #define ref_hash(k) ref_hash0(sym(k))
3688
+ #define del_hash(k) del_hash0(sym(k))
3685
3689
 
3686
3690
  static VALUE
3687
3691
  rt_rewrite_frags(VALUE hash)
@@ -3718,8 +3722,6 @@ rt_rewrite_frags(VALUE hash)
3718
3722
  return hash;
3719
3723
  }
3720
3724
 
3721
- #define sym(x) ID2SYM(rb_intern(x))
3722
-
3723
3725
  static VALUE d_lite_year(VALUE);
3724
3726
  static VALUE d_lite_wday(VALUE);
3725
3727
  static VALUE d_lite_jd(VALUE);
@@ -4691,14 +4693,14 @@ dup_obj_as_complex(VALUE self)
4691
4693
  }
4692
4694
 
4693
4695
  #define val2off(vof,iof) \
4694
- {\
4696
+ do {\
4695
4697
  if (!offset_to_sec(vof, &iof)) {\
4696
4698
  iof = 0;\
4697
4699
  rb_warning("invalid offset is ignored");\
4698
4700
  }\
4699
- }
4701
+ } while (0)
4700
4702
 
4701
- #ifndef NDEBUG
4703
+ #if 0
4702
4704
  static VALUE
4703
4705
  d_lite_initialize(int argc, VALUE *argv, VALUE self)
4704
4706
  {
@@ -4751,7 +4753,7 @@ d_lite_initialize(int argc, VALUE *argv, VALUE self)
4751
4753
  "cannot load complex into simple");
4752
4754
 
4753
4755
  set_to_complex(self, &dat->c, nth, rjd, df, sf, of, sg,
4754
- 0, 0, 0, 0, 0, 0, HAVE_JD | HAVE_DF | COMPLEX_DAT);
4756
+ 0, 0, 0, 0, 0, 0, HAVE_JD | HAVE_DF);
4755
4757
  }
4756
4758
  }
4757
4759
  return self;
@@ -4770,8 +4772,28 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
4770
4772
  {
4771
4773
  get_d2(copy, date);
4772
4774
  if (simple_dat_p(bdat)) {
4773
- adat->s = bdat->s;
4774
- adat->s.flags &= ~COMPLEX_DAT;
4775
+ if (simple_dat_p(adat)) {
4776
+ adat->s = bdat->s;
4777
+ }
4778
+ else {
4779
+ adat->c.flags = bdat->s.flags | COMPLEX_DAT;
4780
+ adat->c.nth = bdat->s.nth;
4781
+ adat->c.jd = bdat->s.jd;
4782
+ adat->c.df = 0;
4783
+ adat->c.sf = INT2FIX(0);
4784
+ adat->c.of = 0;
4785
+ adat->c.sg = bdat->s.sg;
4786
+ adat->c.year = bdat->s.year;
4787
+ #ifndef USE_PACK
4788
+ adat->c.mon = bdat->s.mon;
4789
+ adat->c.mday = bdat->s.mday;
4790
+ adat->c.hour = bdat->s.hour;
4791
+ adat->c.min = bdat->s.min;
4792
+ adat->c.sec = bdat->s.sec;
4793
+ #else
4794
+ adat->c.pc = bdat->s.pc;
4795
+ #endif
4796
+ }
4775
4797
  }
4776
4798
  else {
4777
4799
  if (!complex_dat_p(adat))
@@ -4779,7 +4801,6 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
4779
4801
  "cannot load complex into simple");
4780
4802
 
4781
4803
  adat->c = bdat->c;
4782
- adat->c.flags |= COMPLEX_DAT;
4783
4804
  }
4784
4805
  }
4785
4806
  return copy;
@@ -5513,8 +5534,10 @@ d_lite_new_offset(int argc, VALUE *argv, VALUE self)
5513
5534
  static VALUE
5514
5535
  d_lite_plus(VALUE self, VALUE other)
5515
5536
  {
5537
+ int try_rational = 1;
5516
5538
  get_d1(self);
5517
5539
 
5540
+ again:
5518
5541
  switch (TYPE(other)) {
5519
5542
  case T_FIXNUM:
5520
5543
  {
@@ -5724,18 +5747,21 @@ d_lite_plus(VALUE self, VALUE other)
5724
5747
  default:
5725
5748
  expect_numeric(other);
5726
5749
  other = f_to_r(other);
5727
- #ifdef CANONICALIZATION_FOR_MATHN
5728
- if (!k_rational_p(other))
5729
- return d_lite_plus(self, other);
5730
- #endif
5750
+ if (!k_rational_p(other)) {
5751
+ if (!try_rational) Check_Type(other, T_RATIONAL);
5752
+ try_rational = 0;
5753
+ goto again;
5754
+ }
5731
5755
  /* fall through */
5732
5756
  case T_RATIONAL:
5733
5757
  {
5734
5758
  VALUE nth, sf, t;
5735
5759
  int jd, df, s;
5736
5760
 
5737
- if (wholenum_p(other))
5738
- return d_lite_plus(self, rb_rational_num(other));
5761
+ if (wholenum_p(other)) {
5762
+ other = rb_rational_num(other);
5763
+ goto again;
5764
+ }
5739
5765
 
5740
5766
  if (f_positive_p(other))
5741
5767
  s = +1;
@@ -6154,6 +6180,7 @@ static VALUE
6154
6180
  d_lite_step(int argc, VALUE *argv, VALUE self)
6155
6181
  {
6156
6182
  VALUE limit, step, date;
6183
+ int c;
6157
6184
 
6158
6185
  rb_scan_args(argc, argv, "11", &limit, &step);
6159
6186
 
@@ -6168,25 +6195,22 @@ d_lite_step(int argc, VALUE *argv, VALUE self)
6168
6195
  RETURN_ENUMERATOR(self, argc, argv);
6169
6196
 
6170
6197
  date = self;
6171
- switch (FIX2INT(f_cmp(step, INT2FIX(0)))) {
6172
- case -1:
6198
+ c = f_cmp(step, INT2FIX(0));
6199
+ if (c < 0) {
6173
6200
  while (FIX2INT(d_lite_cmp(date, limit)) >= 0) {
6174
6201
  rb_yield(date);
6175
6202
  date = d_lite_plus(date, step);
6176
6203
  }
6177
- break;
6178
- case 0:
6204
+ }
6205
+ else if (c == 0) {
6179
6206
  while (1)
6180
6207
  rb_yield(date);
6181
- break;
6182
- case 1:
6208
+ }
6209
+ else /* if (c > 0) */ {
6183
6210
  while (FIX2INT(d_lite_cmp(date, limit)) <= 0) {
6184
6211
  rb_yield(date);
6185
6212
  date = d_lite_plus(date, step);
6186
6213
  }
6187
- break;
6188
- default:
6189
- abort();
6190
6214
  }
6191
6215
  return self;
6192
6216
  }
@@ -6241,10 +6265,10 @@ cmp_gen(VALUE self, VALUE other)
6241
6265
  get_d1(self);
6242
6266
 
6243
6267
  if (k_numeric_p(other))
6244
- return f_cmp(m_ajd(dat), other);
6268
+ return INT2FIX(f_cmp(m_ajd(dat), other));
6245
6269
  else if (k_date_p(other))
6246
- return f_cmp(m_ajd(dat), f_ajd(other));
6247
- return rb_num_coerce_cmp(self, other, rb_intern("<=>"));
6270
+ return INT2FIX(f_cmp(m_ajd(dat), f_ajd(other)));
6271
+ return rb_num_coerce_cmp(self, other, id_cmp);
6248
6272
  }
6249
6273
 
6250
6274
  static VALUE
@@ -6373,7 +6397,7 @@ equal_gen(VALUE self, VALUE other)
6373
6397
  return f_eqeq_p(m_real_local_jd(dat), other);
6374
6398
  else if (k_date_p(other))
6375
6399
  return f_eqeq_p(m_real_local_jd(dat), f_jd(other));
6376
- return rb_num_coerce_cmp(self, other, rb_intern("=="));
6400
+ return rb_num_coerce_cmp(self, other, id_eqeq_p);
6377
6401
  }
6378
6402
 
6379
6403
  /*
@@ -6471,7 +6495,7 @@ d_lite_to_s(VALUE self)
6471
6495
  static VALUE
6472
6496
  mk_inspect_raw(union DateData *x, VALUE klass)
6473
6497
  {
6474
- char flags[5];
6498
+ char flags[6];
6475
6499
 
6476
6500
  flags[0] = (x->flags & COMPLEX_DAT) ? 'C' : 'S';
6477
6501
  flags[1] = (x->flags & HAVE_JD) ? 'j' : '-';
@@ -6637,7 +6661,9 @@ tmx_m_of(union DateData *x)
6637
6661
  static char *
6638
6662
  tmx_m_zone(union DateData *x)
6639
6663
  {
6640
- return RSTRING_PTR(m_zone(x));
6664
+ VALUE zone = m_zone(x);
6665
+ /* TODO: fix potential dangling pointer */
6666
+ return RSTRING_PTR(zone);
6641
6667
  }
6642
6668
 
6643
6669
  static const struct tmx_funcs tmx_funcs = {
@@ -6787,7 +6813,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
6787
6813
  *
6788
6814
  * %M - Minute of the hour (00..59)
6789
6815
  *
6790
- * %S - Second of the minute (00..59)
6816
+ * %S - Second of the minute (00..60)
6791
6817
  *
6792
6818
  * %L - Millisecond of the second (000..999)
6793
6819
  * %N - Fractional seconds digits, default is 9 digits (nanosecond)
@@ -7101,6 +7127,10 @@ d_lite_marshal_dump(VALUE self)
7101
7127
  static VALUE
7102
7128
  d_lite_marshal_load(VALUE self, VALUE a)
7103
7129
  {
7130
+ VALUE nth, sf;
7131
+ int jd, df, of;
7132
+ double sg;
7133
+
7104
7134
  get_d1(self);
7105
7135
 
7106
7136
  rb_check_frozen(self);
@@ -7113,63 +7143,33 @@ d_lite_marshal_load(VALUE self, VALUE a)
7113
7143
  case 2: /* 1.6.x */
7114
7144
  case 3: /* 1.8.x, 1.9.2 */
7115
7145
  {
7116
- VALUE ajd, of, sg, nth, sf;
7117
- int jd, df, rof;
7118
- double rsg;
7119
-
7146
+ VALUE ajd, vof, vsg;
7120
7147
 
7121
7148
  if (RARRAY_LEN(a) == 2) {
7122
7149
  ajd = f_sub(RARRAY_AREF(a, 0), half_days_in_day);
7123
- of = INT2FIX(0);
7124
- sg = RARRAY_AREF(a, 1);
7125
- if (!k_numeric_p(sg))
7126
- sg = DBL2NUM(RTEST(sg) ? GREGORIAN : JULIAN);
7150
+ vof = INT2FIX(0);
7151
+ vsg = RARRAY_AREF(a, 1);
7152
+ if (!k_numeric_p(vsg))
7153
+ vsg = DBL2NUM(RTEST(vsg) ? GREGORIAN : JULIAN);
7127
7154
  }
7128
7155
  else {
7129
7156
  ajd = RARRAY_AREF(a, 0);
7130
- of = RARRAY_AREF(a, 1);
7131
- sg = RARRAY_AREF(a, 2);
7157
+ vof = RARRAY_AREF(a, 1);
7158
+ vsg = RARRAY_AREF(a, 2);
7132
7159
  }
7133
7160
 
7134
- old_to_new(ajd, of, sg,
7135
- &nth, &jd, &df, &sf, &rof, &rsg);
7136
-
7137
- if (!df && f_zero_p(sf) && !rof) {
7138
- set_to_simple(self, &dat->s, nth, jd, rsg, 0, 0, 0, HAVE_JD);
7139
- } else {
7140
- if (!complex_dat_p(dat))
7141
- rb_raise(rb_eArgError,
7142
- "cannot load complex into simple");
7143
-
7144
- set_to_complex(self, &dat->c, nth, jd, df, sf, rof, rsg,
7145
- 0, 0, 0, 0, 0, 0,
7146
- HAVE_JD | HAVE_DF | COMPLEX_DAT);
7147
- }
7161
+ old_to_new(ajd, vof, vsg,
7162
+ &nth, &jd, &df, &sf, &of, &sg);
7148
7163
  }
7149
7164
  break;
7150
7165
  case 6:
7151
7166
  {
7152
- VALUE nth, sf;
7153
- int jd, df, of;
7154
- double sg;
7155
-
7156
7167
  nth = RARRAY_AREF(a, 0);
7157
7168
  jd = NUM2INT(RARRAY_AREF(a, 1));
7158
7169
  df = NUM2INT(RARRAY_AREF(a, 2));
7159
7170
  sf = RARRAY_AREF(a, 3);
7160
7171
  of = NUM2INT(RARRAY_AREF(a, 4));
7161
7172
  sg = NUM2DBL(RARRAY_AREF(a, 5));
7162
- if (!df && f_zero_p(sf) && !of) {
7163
- set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
7164
- } else {
7165
- if (!complex_dat_p(dat))
7166
- rb_raise(rb_eArgError,
7167
- "cannot load complex into simple");
7168
-
7169
- set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
7170
- 0, 0, 0, 0, 0, 0,
7171
- HAVE_JD | HAVE_DF | COMPLEX_DAT);
7172
- }
7173
7173
  }
7174
7174
  break;
7175
7175
  default:
@@ -7177,6 +7177,18 @@ d_lite_marshal_load(VALUE self, VALUE a)
7177
7177
  break;
7178
7178
  }
7179
7179
 
7180
+ if (simple_dat_p(dat)) {
7181
+ if (df || !f_zero_p(sf) || of) {
7182
+ rb_raise(rb_eArgError,
7183
+ "cannot load complex into simple");
7184
+ }
7185
+ set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
7186
+ } else {
7187
+ set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
7188
+ 0, 0, 0, 0, 0, 0,
7189
+ HAVE_JD | HAVE_DF);
7190
+ }
7191
+
7180
7192
  if (FL_TEST(a, FL_EXIVAR)) {
7181
7193
  rb_copy_generic_ivar(self, a);
7182
7194
  FL_SET(self, FL_EXIVAR);
@@ -7356,10 +7368,21 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
7356
7368
  */
7357
7369
  static VALUE
7358
7370
  datetime_s_civil(int argc, VALUE *argv, VALUE klass)
7371
+ {
7372
+ return datetime_initialize(argc, argv, d_lite_s_alloc_complex(klass));
7373
+ }
7374
+
7375
+ static VALUE
7376
+ datetime_initialize(int argc, VALUE *argv, VALUE self)
7359
7377
  {
7360
7378
  VALUE vy, vm, vd, vh, vmin, vs, vof, vsg, y, fr, fr2, ret;
7361
7379
  int m, d, h, min, s, rof;
7362
7380
  double sg;
7381
+ struct ComplexDateData *dat = rb_check_typeddata(self, &d_lite_type);
7382
+
7383
+ if (!complex_dat_p(dat)) {
7384
+ rb_raise(rb_eTypeError, "DateTime expected");
7385
+ }
7363
7386
 
7364
7387
  rb_scan_args(argc, argv, "08", &vy, &vm, &vd, &vh, &vmin, &vs, &vof, &vsg);
7365
7388
 
@@ -7403,13 +7426,13 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass)
7403
7426
  rb_raise(rb_eArgError, "invalid date");
7404
7427
  canon24oc();
7405
7428
 
7406
- ret = d_complex_new_internal(klass,
7407
- nth, 0,
7408
- 0, INT2FIX(0),
7409
- rof, sg,
7410
- ry, rm, rd,
7411
- rh, rmin, rs,
7412
- HAVE_CIVIL | HAVE_TIME);
7429
+ set_to_complex(self, dat,
7430
+ nth, 0,
7431
+ 0, INT2FIX(0),
7432
+ rof, sg,
7433
+ ry, rm, rd,
7434
+ rh, rmin, rs,
7435
+ HAVE_CIVIL | HAVE_TIME);
7413
7436
  }
7414
7437
  else {
7415
7438
  VALUE nth;
@@ -7428,14 +7451,15 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass)
7428
7451
  time_to_df(rh, rmin, rs),
7429
7452
  rof);
7430
7453
 
7431
- ret = d_complex_new_internal(klass,
7432
- nth, rjd2,
7433
- 0, INT2FIX(0),
7434
- rof, sg,
7435
- ry, rm, rd,
7436
- rh, rmin, rs,
7437
- HAVE_JD | HAVE_CIVIL | HAVE_TIME);
7454
+ set_to_complex(self, dat,
7455
+ nth, rjd2,
7456
+ 0, INT2FIX(0),
7457
+ rof, sg,
7458
+ ry, rm, rd,
7459
+ rh, rmin, rs,
7460
+ HAVE_JD | HAVE_CIVIL | HAVE_TIME);
7438
7461
  }
7462
+ ret = self;
7439
7463
  add_frac();
7440
7464
  return ret;
7441
7465
  }
@@ -8232,7 +8256,7 @@ dt_lite_to_s(VALUE self)
8232
8256
  *
8233
8257
  * %M - Minute of the hour (00..59)
8234
8258
  *
8235
- * %S - Second of the minute (00..59)
8259
+ * %S - Second of the minute (00..60)
8236
8260
  *
8237
8261
  * %L - Millisecond of the second (000..999)
8238
8262
  * %N - Fractional seconds digits, default is 9 digits (nanosecond)
@@ -8645,7 +8669,7 @@ datetime_to_date(VALUE self)
8645
8669
  VALUE new = d_lite_s_alloc_simple(cDate);
8646
8670
  {
8647
8671
  get_d1b(new);
8648
- copy_complex_to_simple(new, &bdat->s, &adat->c)
8672
+ copy_complex_to_simple(new, &bdat->s, &adat->c);
8649
8673
  bdat->s.jd = m_local_jd(adat);
8650
8674
  bdat->s.flags &= ~(HAVE_DF | HAVE_TIME | COMPLEX_DAT);
8651
8675
  return new;
@@ -9010,14 +9034,18 @@ mk_ary_of_str(long len, const char *a[])
9010
9034
  return o;
9011
9035
  }
9012
9036
 
9037
+ static VALUE
9038
+ d_lite_zero(VALUE x)
9039
+ {
9040
+ return INT2FIX(0);
9041
+ }
9042
+
9013
9043
  void
9014
9044
  Init_date_core(void)
9015
9045
  {
9016
9046
  #undef rb_intern
9017
9047
  #define rb_intern(str) rb_intern_const(str)
9018
9048
 
9019
- assert(fprintf(stderr, "assert() is now active\n"));
9020
-
9021
9049
  id_cmp = rb_intern("<=>");
9022
9050
  id_le_p = rb_intern("<=");
9023
9051
  id_ge_p = rb_intern(">=");
@@ -9233,23 +9261,22 @@ Init_date_core(void)
9233
9261
  */
9234
9262
  rb_define_const(cDate, "GREGORIAN", DBL2NUM(GREGORIAN));
9235
9263
 
9236
- rb_define_alloc_func(cDate, d_lite_s_alloc);
9264
+ rb_define_alloc_func(cDate, d_lite_s_alloc_simple);
9237
9265
 
9238
9266
  #ifndef NDEBUG
9239
- #define de_define_private_method rb_define_private_method
9240
- de_define_private_method(CLASS_OF(cDate), "_valid_jd?",
9267
+ rb_define_private_method(CLASS_OF(cDate), "_valid_jd?",
9241
9268
  date_s__valid_jd_p, -1);
9242
- de_define_private_method(CLASS_OF(cDate), "_valid_ordinal?",
9269
+ rb_define_private_method(CLASS_OF(cDate), "_valid_ordinal?",
9243
9270
  date_s__valid_ordinal_p, -1);
9244
- de_define_private_method(CLASS_OF(cDate), "_valid_civil?",
9271
+ rb_define_private_method(CLASS_OF(cDate), "_valid_civil?",
9245
9272
  date_s__valid_civil_p, -1);
9246
- de_define_private_method(CLASS_OF(cDate), "_valid_date?",
9273
+ rb_define_private_method(CLASS_OF(cDate), "_valid_date?",
9247
9274
  date_s__valid_civil_p, -1);
9248
- de_define_private_method(CLASS_OF(cDate), "_valid_commercial?",
9275
+ rb_define_private_method(CLASS_OF(cDate), "_valid_commercial?",
9249
9276
  date_s__valid_commercial_p, -1);
9250
- de_define_private_method(CLASS_OF(cDate), "_valid_weeknum?",
9277
+ rb_define_private_method(CLASS_OF(cDate), "_valid_weeknum?",
9251
9278
  date_s__valid_weeknum_p, -1);
9252
- de_define_private_method(CLASS_OF(cDate), "_valid_nth_kday?",
9279
+ rb_define_private_method(CLASS_OF(cDate), "_valid_nth_kday?",
9253
9280
  date_s__valid_nth_kday_p, -1);
9254
9281
  #endif
9255
9282
 
@@ -9262,11 +9289,11 @@ Init_date_core(void)
9262
9289
  date_s_valid_commercial_p, -1);
9263
9290
 
9264
9291
  #ifndef NDEBUG
9265
- de_define_private_method(CLASS_OF(cDate), "valid_weeknum?",
9292
+ rb_define_private_method(CLASS_OF(cDate), "valid_weeknum?",
9266
9293
  date_s_valid_weeknum_p, -1);
9267
- de_define_private_method(CLASS_OF(cDate), "valid_nth_kday?",
9294
+ rb_define_private_method(CLASS_OF(cDate), "valid_nth_kday?",
9268
9295
  date_s_valid_nth_kday_p, -1);
9269
- de_define_private_method(CLASS_OF(cDate), "zone_to_diff",
9296
+ rb_define_private_method(CLASS_OF(cDate), "zone_to_diff",
9270
9297
  date_s_zone_to_diff, 1);
9271
9298
  #endif
9272
9299
 
@@ -9277,21 +9304,18 @@ Init_date_core(void)
9277
9304
  date_s_gregorian_leap_p, 1);
9278
9305
 
9279
9306
  #ifndef NDEBUG
9280
- #define de_define_singleton_method rb_define_singleton_method
9281
- #define de_define_alias rb_define_alias
9282
- de_define_singleton_method(cDate, "new!", date_s_new_bang, -1);
9283
- de_define_alias(rb_singleton_class(cDate), "new_l!", "new");
9307
+ rb_define_singleton_method(cDate, "new!", date_s_new_bang, -1);
9308
+ rb_define_alias(rb_singleton_class(cDate), "new_l!", "new");
9284
9309
  #endif
9285
9310
 
9286
9311
  rb_define_singleton_method(cDate, "jd", date_s_jd, -1);
9287
9312
  rb_define_singleton_method(cDate, "ordinal", date_s_ordinal, -1);
9288
9313
  rb_define_singleton_method(cDate, "civil", date_s_civil, -1);
9289
- rb_define_singleton_method(cDate, "new", date_s_civil, -1);
9290
9314
  rb_define_singleton_method(cDate, "commercial", date_s_commercial, -1);
9291
9315
 
9292
9316
  #ifndef NDEBUG
9293
- de_define_singleton_method(cDate, "weeknum", date_s_weeknum, -1);
9294
- de_define_singleton_method(cDate, "nth_kday", date_s_nth_kday, -1);
9317
+ rb_define_singleton_method(cDate, "weeknum", date_s_weeknum, -1);
9318
+ rb_define_singleton_method(cDate, "nth_kday", date_s_nth_kday, -1);
9295
9319
  #endif
9296
9320
 
9297
9321
  rb_define_singleton_method(cDate, "today", date_s_today, -1);
@@ -9314,14 +9338,11 @@ Init_date_core(void)
9314
9338
  rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
9315
9339
  rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
9316
9340
 
9317
- #ifndef NDEBUG
9318
- #define de_define_method rb_define_method
9319
- de_define_method(cDate, "initialize", d_lite_initialize, -1);
9320
- #endif
9341
+ rb_define_method(cDate, "initialize", date_initialize, -1);
9321
9342
  rb_define_method(cDate, "initialize_copy", d_lite_initialize_copy, 1);
9322
9343
 
9323
9344
  #ifndef NDEBUG
9324
- de_define_method(cDate, "fill", d_lite_fill, 0);
9345
+ rb_define_method(cDate, "fill", d_lite_fill, 0);
9325
9346
  #endif
9326
9347
 
9327
9348
  rb_define_method(cDate, "ajd", d_lite_ajd, 0);
@@ -9343,8 +9364,8 @@ Init_date_core(void)
9343
9364
  rb_define_method(cDate, "cwday", d_lite_cwday, 0);
9344
9365
 
9345
9366
  #ifndef NDEBUG
9346
- de_define_private_method(cDate, "wnum0", d_lite_wnum0, 0);
9347
- de_define_private_method(cDate, "wnum1", d_lite_wnum1, 0);
9367
+ rb_define_private_method(cDate, "wnum0", d_lite_wnum0, 0);
9368
+ rb_define_private_method(cDate, "wnum1", d_lite_wnum1, 0);
9348
9369
  #endif
9349
9370
 
9350
9371
  rb_define_method(cDate, "wday", d_lite_wday, 0);
@@ -9358,18 +9379,14 @@ Init_date_core(void)
9358
9379
  rb_define_method(cDate, "saturday?", d_lite_saturday_p, 0);
9359
9380
 
9360
9381
  #ifndef NDEBUG
9361
- de_define_method(cDate, "nth_kday?", d_lite_nth_kday_p, 2);
9382
+ rb_define_method(cDate, "nth_kday?", d_lite_nth_kday_p, 2);
9362
9383
  #endif
9363
9384
 
9364
- rb_define_private_method(cDate, "hour", d_lite_hour, 0);
9365
- rb_define_private_method(cDate, "min", d_lite_min, 0);
9366
- rb_define_private_method(cDate, "minute", d_lite_min, 0);
9367
- rb_define_private_method(cDate, "sec", d_lite_sec, 0);
9368
- rb_define_private_method(cDate, "second", d_lite_sec, 0);
9369
- rb_define_private_method(cDate, "sec_fraction", d_lite_sec_fraction, 0);
9370
- rb_define_private_method(cDate, "second_fraction", d_lite_sec_fraction, 0);
9371
- rb_define_private_method(cDate, "offset", d_lite_offset, 0);
9372
- rb_define_private_method(cDate, "zone", d_lite_zone, 0);
9385
+ rb_define_private_method(cDate, "hour", d_lite_zero, 0);
9386
+ rb_define_private_method(cDate, "min", d_lite_zero, 0);
9387
+ rb_define_private_method(cDate, "minute", d_lite_zero, 0);
9388
+ rb_define_private_method(cDate, "sec", d_lite_zero, 0);
9389
+ rb_define_private_method(cDate, "second", d_lite_zero, 0);
9373
9390
 
9374
9391
  rb_define_method(cDate, "julian?", d_lite_julian_p, 0);
9375
9392
  rb_define_method(cDate, "gregorian?", d_lite_gregorian_p, 0);
@@ -9382,8 +9399,6 @@ Init_date_core(void)
9382
9399
  rb_define_method(cDate, "julian", d_lite_julian, 0);
9383
9400
  rb_define_method(cDate, "gregorian", d_lite_gregorian, 0);
9384
9401
 
9385
- rb_define_private_method(cDate, "new_offset", d_lite_new_offset, -1);
9386
-
9387
9402
  rb_define_method(cDate, "+", d_lite_plus, 1);
9388
9403
  rb_define_method(cDate, "-", d_lite_minus, 1);
9389
9404
 
@@ -9411,7 +9426,7 @@ Init_date_core(void)
9411
9426
 
9412
9427
  rb_define_method(cDate, "to_s", d_lite_to_s, 0);
9413
9428
  #ifndef NDEBUG
9414
- de_define_method(cDate, "inspect_raw", d_lite_inspect_raw, 0);
9429
+ rb_define_method(cDate, "inspect_raw", d_lite_inspect_raw, 0);
9415
9430
  #endif
9416
9431
  rb_define_method(cDate, "inspect", d_lite_inspect, 0);
9417
9432
 
@@ -9428,7 +9443,7 @@ Init_date_core(void)
9428
9443
  rb_define_method(cDate, "jisx0301", d_lite_jisx0301, 0);
9429
9444
 
9430
9445
  #ifndef NDEBUG
9431
- de_define_method(cDate, "marshal_dump_old", d_lite_marshal_dump_old, 0);
9446
+ rb_define_method(cDate, "marshal_dump_old", d_lite_marshal_dump_old, 0);
9432
9447
  #endif
9433
9448
  rb_define_method(cDate, "marshal_dump", d_lite_marshal_dump, 0);
9434
9449
  rb_define_method(cDate, "marshal_load", d_lite_marshal_load, 1);
@@ -9575,6 +9590,7 @@ Init_date_core(void)
9575
9590
  */
9576
9591
 
9577
9592
  cDateTime = rb_define_class("DateTime", cDate);
9593
+ rb_define_alloc_func(cDateTime, d_lite_s_alloc_complex);
9578
9594
 
9579
9595
  rb_define_singleton_method(cDateTime, "jd", datetime_s_jd, -1);
9580
9596
  rb_define_singleton_method(cDateTime, "ordinal", datetime_s_ordinal, -1);
@@ -9584,9 +9600,9 @@ Init_date_core(void)
9584
9600
  datetime_s_commercial, -1);
9585
9601
 
9586
9602
  #ifndef NDEBUG
9587
- de_define_singleton_method(cDateTime, "weeknum",
9603
+ rb_define_singleton_method(cDateTime, "weeknum",
9588
9604
  datetime_s_weeknum, -1);
9589
- de_define_singleton_method(cDateTime, "nth_kday",
9605
+ rb_define_singleton_method(cDateTime, "nth_kday",
9590
9606
  datetime_s_nth_kday, -1);
9591
9607
  #endif
9592
9608
 
@@ -9614,19 +9630,16 @@ Init_date_core(void)
9614
9630
  rb_define_singleton_method(cDateTime, "jisx0301",
9615
9631
  datetime_s_jisx0301, -1);
9616
9632
 
9617
- #define f_public(m,s) rb_funcall(m, rb_intern("public"), 1,\
9618
- ID2SYM(rb_intern(s)))
9619
-
9620
- f_public(cDateTime, "hour");
9621
- f_public(cDateTime, "min");
9622
- f_public(cDateTime, "minute");
9623
- f_public(cDateTime, "sec");
9624
- f_public(cDateTime, "second");
9625
- f_public(cDateTime, "sec_fraction");
9626
- f_public(cDateTime, "second_fraction");
9627
- f_public(cDateTime, "offset");
9628
- f_public(cDateTime, "zone");
9629
- f_public(cDateTime, "new_offset");
9633
+ rb_define_method(cDateTime, "hour", d_lite_hour, 0);
9634
+ rb_define_method(cDateTime, "min", d_lite_min, 0);
9635
+ rb_define_method(cDateTime, "minute", d_lite_min, 0);
9636
+ rb_define_method(cDateTime, "sec", d_lite_sec, 0);
9637
+ rb_define_method(cDateTime, "second", d_lite_sec, 0);
9638
+ rb_define_method(cDateTime, "sec_fraction", d_lite_sec_fraction, 0);
9639
+ rb_define_method(cDateTime, "second_fraction", d_lite_sec_fraction, 0);
9640
+ rb_define_method(cDateTime, "offset", d_lite_offset, 0);
9641
+ rb_define_method(cDateTime, "zone", d_lite_zone, 0);
9642
+ rb_define_method(cDateTime, "new_offset", d_lite_new_offset, -1);
9630
9643
 
9631
9644
  rb_define_method(cDateTime, "to_s", dt_lite_to_s, 0);
9632
9645
 
@@ -9654,15 +9667,15 @@ Init_date_core(void)
9654
9667
  #ifndef NDEBUG
9655
9668
  /* tests */
9656
9669
 
9657
- de_define_singleton_method(cDate, "test_civil", date_s_test_civil, 0);
9658
- de_define_singleton_method(cDate, "test_ordinal", date_s_test_ordinal, 0);
9659
- de_define_singleton_method(cDate, "test_commercial",
9670
+ rb_define_singleton_method(cDate, "test_civil", date_s_test_civil, 0);
9671
+ rb_define_singleton_method(cDate, "test_ordinal", date_s_test_ordinal, 0);
9672
+ rb_define_singleton_method(cDate, "test_commercial",
9660
9673
  date_s_test_commercial, 0);
9661
- de_define_singleton_method(cDate, "test_weeknum", date_s_test_weeknum, 0);
9662
- de_define_singleton_method(cDate, "test_nth_kday", date_s_test_nth_kday, 0);
9663
- de_define_singleton_method(cDate, "test_unit_conv",
9674
+ rb_define_singleton_method(cDate, "test_weeknum", date_s_test_weeknum, 0);
9675
+ rb_define_singleton_method(cDate, "test_nth_kday", date_s_test_nth_kday, 0);
9676
+ rb_define_singleton_method(cDate, "test_unit_conv",
9664
9677
  date_s_test_unit_conv, 0);
9665
- de_define_singleton_method(cDate, "test_all", date_s_test_all, 0);
9678
+ rb_define_singleton_method(cDate, "test_all", date_s_test_all, 0);
9666
9679
  #endif
9667
9680
  }
9668
9681