date 3.2.2 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/date/date_core.c CHANGED
@@ -465,6 +465,7 @@ c_find_ldoy(int y, double sg, int *rjd, int *ns)
465
465
  }
466
466
 
467
467
  #ifndef NDEBUG
468
+ /* :nodoc: */
468
469
  static int
469
470
  c_find_fdom(int y, int m, double sg, int *rjd, int *ns)
470
471
  {
@@ -621,6 +622,7 @@ c_jd_to_weeknum(int jd, int f, double sg, int *ry, int *rw, int *rd)
621
622
  }
622
623
 
623
624
  #ifndef NDEBUG
625
+ /* :nodoc: */
624
626
  static void
625
627
  c_nth_kday_to_jd(int y, int m, int n, int k, double sg, int *rjd, int *ns)
626
628
  {
@@ -646,6 +648,7 @@ c_jd_to_wday(int jd)
646
648
  }
647
649
 
648
650
  #ifndef NDEBUG
651
+ /* :nodoc: */
649
652
  static void
650
653
  c_jd_to_nth_kday(int jd, double sg, int *ry, int *rm, int *rn, int *rk)
651
654
  {
@@ -758,6 +761,8 @@ c_valid_civil_p(int y, int m, int d, double sg,
758
761
 
759
762
  if (m < 0)
760
763
  m += 13;
764
+ if (m < 1 || m > 12)
765
+ return 0;
761
766
  if (d < 0) {
762
767
  if (!c_find_ldom(y, m, sg, rjd, ns))
763
768
  return 0;
@@ -822,6 +827,7 @@ c_valid_weeknum_p(int y, int w, int d, int f, double sg,
822
827
  }
823
828
 
824
829
  #ifndef NDEBUG
830
+ /* :nodoc: */
825
831
  static int
826
832
  c_valid_nth_kday_p(int y, int m, int n, int k, double sg,
827
833
  int *rm, int *rn, int *rk, int *rjd, int *ns)
@@ -963,6 +969,7 @@ ns_to_day(VALUE n)
963
969
  }
964
970
 
965
971
  #ifndef NDEBUG
972
+ /* :nodoc: */
966
973
  static VALUE
967
974
  ms_to_sec(VALUE m)
968
975
  {
@@ -981,6 +988,7 @@ ns_to_sec(VALUE n)
981
988
  }
982
989
 
983
990
  #ifndef NDEBUG
991
+ /* :nodoc: */
984
992
  inline static VALUE
985
993
  ins_to_day(int n)
986
994
  {
@@ -1016,6 +1024,7 @@ day_to_sec(VALUE d)
1016
1024
  }
1017
1025
 
1018
1026
  #ifndef NDEBUG
1027
+ /* :nodoc: */
1019
1028
  static VALUE
1020
1029
  day_to_ns(VALUE d)
1021
1030
  {
@@ -1040,6 +1049,7 @@ sec_to_ns(VALUE s)
1040
1049
  }
1041
1050
 
1042
1051
  #ifndef NDEBUG
1052
+ /* :nodoc: */
1043
1053
  static VALUE
1044
1054
  isec_to_ns(int s)
1045
1055
  {
@@ -1066,6 +1076,7 @@ div_df(VALUE d, VALUE *f)
1066
1076
  }
1067
1077
 
1068
1078
  #ifndef NDEBUG
1079
+ /* :nodoc: */
1069
1080
  static VALUE
1070
1081
  div_sf(VALUE s, VALUE *f)
1071
1082
  {
@@ -1500,6 +1511,7 @@ m_df(union DateData *x)
1500
1511
  }
1501
1512
 
1502
1513
  #ifndef NDEBUG
1514
+ /* :nodoc: */
1503
1515
  static VALUE
1504
1516
  m_df_in_day(union DateData *x)
1505
1517
  {
@@ -1997,6 +2009,7 @@ expect_numeric(VALUE x)
1997
2009
  }
1998
2010
 
1999
2011
  #ifndef NDEBUG
2012
+ /* :nodoc: */
2000
2013
  static void
2001
2014
  civil_to_jd(VALUE y, int m, int d, double sg,
2002
2015
  VALUE *nth, int *ry,
@@ -2309,6 +2322,7 @@ valid_weeknum_p(VALUE y, int w, int d, int f, double sg,
2309
2322
  }
2310
2323
 
2311
2324
  #ifndef NDEBUG
2325
+ /* :nodoc: */
2312
2326
  static int
2313
2327
  valid_nth_kday_p(VALUE y, int m, int n, int k, double sg,
2314
2328
  VALUE *nth, int *ry,
@@ -2446,6 +2460,7 @@ valid_jd_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2446
2460
  }
2447
2461
 
2448
2462
  #ifndef NDEBUG
2463
+ /* :nodoc: */
2449
2464
  static VALUE
2450
2465
  date_s__valid_jd_p(int argc, VALUE *argv, VALUE klass)
2451
2466
  {
@@ -2466,13 +2481,16 @@ date_s__valid_jd_p(int argc, VALUE *argv, VALUE klass)
2466
2481
 
2467
2482
  /*
2468
2483
  * call-seq:
2469
- * Date.valid_jd?(jd[, start=Date::ITALY]) -> bool
2484
+ * Date.valid_jd?(jd, start = Date::ITALY) -> true
2470
2485
  *
2471
- * Just returns true. It's nonsense, but is for symmetry.
2486
+ * Implemented for compatibility;
2487
+ * returns +true+ unless +jd+ is invalid (i.e., not a Numeric).
2472
2488
  *
2473
- * Date.valid_jd?(2451944) #=> true
2489
+ * Date.valid_jd?(2451944) # => true
2474
2490
  *
2475
- * See also ::jd.
2491
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2492
+ *
2493
+ * Related: Date.jd.
2476
2494
  */
2477
2495
  static VALUE
2478
2496
  date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
@@ -2532,6 +2550,7 @@ valid_civil_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2532
2550
  }
2533
2551
 
2534
2552
  #ifndef NDEBUG
2553
+ /* :nodoc: */
2535
2554
  static VALUE
2536
2555
  date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
2537
2556
  {
@@ -2554,18 +2573,20 @@ date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
2554
2573
 
2555
2574
  /*
2556
2575
  * call-seq:
2557
- * Date.valid_civil?(year, month, mday[, start=Date::ITALY]) -> bool
2558
- * Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
2576
+ * Date.valid_civil?(year, month, mday, start = Date::ITALY) -> true or false
2577
+ *
2578
+ * Returns +true+ if the arguments define a valid ordinal date,
2579
+ * +false+ otherwise:
2580
+ *
2581
+ * Date.valid_date?(2001, 2, 3) # => true
2582
+ * Date.valid_date?(2001, 2, 29) # => false
2583
+ * Date.valid_date?(2001, 2, -1) # => true
2559
2584
  *
2560
- * Returns true if the given calendar date is valid, and false if not.
2561
- * Valid in this context is whether the arguments passed to this
2562
- * method would be accepted by ::new.
2585
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2563
2586
  *
2564
- * Date.valid_date?(2001,2,3) #=> true
2565
- * Date.valid_date?(2001,2,29) #=> false
2566
- * Date.valid_date?(2001,2,-1) #=> true
2587
+ * Date.valid_date? is an alias for Date.valid_civil?.
2567
2588
  *
2568
- * See also ::jd and ::civil.
2589
+ * Related: Date.jd, Date.new.
2569
2590
  */
2570
2591
  static VALUE
2571
2592
  date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
@@ -2621,6 +2642,7 @@ valid_ordinal_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2621
2642
  }
2622
2643
 
2623
2644
  #ifndef NDEBUG
2645
+ /* :nodoc: */
2624
2646
  static VALUE
2625
2647
  date_s__valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
2626
2648
  {
@@ -2642,14 +2664,17 @@ date_s__valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
2642
2664
 
2643
2665
  /*
2644
2666
  * call-seq:
2645
- * Date.valid_ordinal?(year, yday[, start=Date::ITALY]) -> bool
2667
+ * Date.valid_ordinal?(year, yday, start = Date::ITALY) -> true or false
2668
+ *
2669
+ * Returns +true+ if the arguments define a valid ordinal date,
2670
+ * +false+ otherwise:
2646
2671
  *
2647
- * Returns true if the given ordinal date is valid, and false if not.
2672
+ * Date.valid_ordinal?(2001, 34) # => true
2673
+ * Date.valid_ordinal?(2001, 366) # => false
2648
2674
  *
2649
- * Date.valid_ordinal?(2001,34) #=> true
2650
- * Date.valid_ordinal?(2001,366) #=> false
2675
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2651
2676
  *
2652
- * See also ::jd and ::ordinal.
2677
+ * Related: Date.jd, Date.ordinal.
2653
2678
  */
2654
2679
  static VALUE
2655
2680
  date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
@@ -2704,6 +2729,7 @@ valid_commercial_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2704
2729
  }
2705
2730
 
2706
2731
  #ifndef NDEBUG
2732
+ /* :nodoc: */
2707
2733
  static VALUE
2708
2734
  date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2709
2735
  {
@@ -2726,14 +2752,19 @@ date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2726
2752
 
2727
2753
  /*
2728
2754
  * call-seq:
2729
- * Date.valid_commercial?(cwyear, cweek, cwday[, start=Date::ITALY]) -> bool
2755
+ * Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
2756
+ *
2757
+ * Returns +true+ if the arguments define a valid commercial date,
2758
+ * +false+ otherwise:
2759
+ *
2760
+ * Date.valid_commercial?(2001, 5, 6) # => true
2761
+ * Date.valid_commercial?(2001, 5, 8) # => false
2730
2762
  *
2731
- * Returns true if the given week date is valid, and false if not.
2763
+ * See Date.commercial.
2732
2764
  *
2733
- * Date.valid_commercial?(2001,5,6) #=> true
2734
- * Date.valid_commercial?(2001,5,8) #=> false
2765
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2735
2766
  *
2736
- * See also ::jd and ::commercial.
2767
+ * Related: Date.jd, Date.commercial.
2737
2768
  */
2738
2769
  static VALUE
2739
2770
  date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
@@ -2760,6 +2791,7 @@ date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2760
2791
  }
2761
2792
 
2762
2793
  #ifndef NDEBUG
2794
+ /* :nodoc: */
2763
2795
  static VALUE
2764
2796
  valid_weeknum_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2765
2797
  {
@@ -2791,6 +2823,7 @@ valid_weeknum_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2791
2823
  }
2792
2824
  }
2793
2825
 
2826
+ /* :nodoc: */
2794
2827
  static VALUE
2795
2828
  date_s__valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2796
2829
  {
@@ -2811,6 +2844,7 @@ date_s__valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2811
2844
  return valid_weeknum_sub(5, argv2, klass, 1);
2812
2845
  }
2813
2846
 
2847
+ /* :nodoc: */
2814
2848
  static VALUE
2815
2849
  date_s_valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2816
2850
  {
@@ -2862,6 +2896,7 @@ valid_nth_kday_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2862
2896
  }
2863
2897
  }
2864
2898
 
2899
+ /* :nodoc: */
2865
2900
  static VALUE
2866
2901
  date_s__valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2867
2902
  {
@@ -2882,6 +2917,7 @@ date_s__valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2882
2917
  return valid_nth_kday_sub(5, argv2, klass, 1);
2883
2918
  }
2884
2919
 
2920
+ /* :nodoc: */
2885
2921
  static VALUE
2886
2922
  date_s_valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2887
2923
  {
@@ -2904,6 +2940,7 @@ date_s_valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2904
2940
  return Qtrue;
2905
2941
  }
2906
2942
 
2943
+ /* :nodoc: */
2907
2944
  static VALUE
2908
2945
  date_s_zone_to_diff(VALUE klass, VALUE str)
2909
2946
  {
@@ -2913,13 +2950,15 @@ date_s_zone_to_diff(VALUE klass, VALUE str)
2913
2950
 
2914
2951
  /*
2915
2952
  * call-seq:
2916
- * Date.julian_leap?(year) -> bool
2953
+ * Date.julian_leap?(year) -> true or false
2954
+ *
2955
+ * Returns +true+ if the given year is a leap year
2956
+ * in the {proleptic Julian calendar}[https://en.wikipedia.org/wiki/Proleptic_Julian_calendar], +false+ otherwise:
2917
2957
  *
2918
- * Returns true if the given year is a leap year of the proleptic
2919
- * Julian calendar.
2958
+ * Date.julian_leap?(1900) # => true
2959
+ * Date.julian_leap?(1901) # => false
2920
2960
  *
2921
- * Date.julian_leap?(1900) #=> true
2922
- * Date.julian_leap?(1901) #=> false
2961
+ * Related: Date.gregorian_leap?.
2923
2962
  */
2924
2963
  static VALUE
2925
2964
  date_s_julian_leap_p(VALUE klass, VALUE y)
@@ -2934,14 +2973,17 @@ date_s_julian_leap_p(VALUE klass, VALUE y)
2934
2973
 
2935
2974
  /*
2936
2975
  * call-seq:
2937
- * Date.gregorian_leap?(year) -> bool
2938
- * Date.leap?(year) -> bool
2976
+ * Date.gregorian_leap?(year) -> true or false
2977
+ *
2978
+ * Returns +true+ if the given year is a leap year
2979
+ * in the {proleptic Gregorian calendar}[https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar], +false+ otherwise:
2980
+ *
2981
+ * Date.gregorian_leap?(2000) # => true
2982
+ * Date.gregorian_leap?(2001) # => false
2939
2983
  *
2940
- * Returns true if the given year is a leap year of the proleptic
2941
- * Gregorian calendar.
2984
+ * Date.leap? is an alias for Date.gregorian_leap?.
2942
2985
  *
2943
- * Date.gregorian_leap?(1900) #=> false
2944
- * Date.gregorian_leap?(2000) #=> true
2986
+ * Related: Date.julian_leap?.
2945
2987
  */
2946
2988
  static VALUE
2947
2989
  date_s_gregorian_leap_p(VALUE klass, VALUE y)
@@ -3094,6 +3136,7 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg,
3094
3136
  }
3095
3137
 
3096
3138
  #ifndef NDEBUG
3139
+ /* :nodoc: */
3097
3140
  static VALUE
3098
3141
  date_s_new_bang(int argc, VALUE *argv, VALUE klass)
3099
3142
  {
@@ -3281,16 +3324,29 @@ static VALUE d_lite_plus(VALUE, VALUE);
3281
3324
 
3282
3325
  /*
3283
3326
  * call-seq:
3284
- * Date.jd([jd=0[, start=Date::ITALY]]) -> date
3327
+ * Date.jd(jd = 0, start = Date::ITALY) -> date
3328
+ *
3329
+ * Returns a new \Date object formed from the arguments:
3330
+ *
3331
+ * Date.jd(2451944).to_s # => "2001-02-03"
3332
+ * Date.jd(2451945).to_s # => "2001-02-04"
3333
+ * Date.jd(0).to_s # => "-4712-01-01"
3334
+ *
3335
+ * The returned date is:
3285
3336
  *
3286
- * Creates a date object denoting the given chronological Julian day
3287
- * number.
3337
+ * - Gregorian, if the argument is greater than or equal to +start+:
3288
3338
  *
3289
- * Date.jd(2451944) #=> #<Date: 2001-02-03 ...>
3290
- * Date.jd(2451945) #=> #<Date: 2001-02-04 ...>
3291
- * Date.jd(0) #=> #<Date: -4712-01-01 ...>
3339
+ * Date::ITALY # => 2299161
3340
+ * Date.jd(Date::ITALY).gregorian? # => true
3341
+ * Date.jd(Date::ITALY + 1).gregorian? # => true
3292
3342
  *
3293
- * See also ::new.
3343
+ * - Julian, otherwise
3344
+ *
3345
+ * Date.jd(Date::ITALY - 1).julian? # => true
3346
+ *
3347
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3348
+ *
3349
+ * Related: Date.new.
3294
3350
  */
3295
3351
  static VALUE
3296
3352
  date_s_jd(int argc, VALUE *argv, VALUE klass)
@@ -3329,19 +3385,33 @@ date_s_jd(int argc, VALUE *argv, VALUE klass)
3329
3385
 
3330
3386
  /*
3331
3387
  * call-seq:
3332
- * Date.ordinal([year=-4712[, yday=1[, start=Date::ITALY]]]) -> date
3388
+ * Date.ordinal(year = -4712, yday = 1, start = Date::ITALY) -> date
3389
+ *
3390
+ * Returns a new \Date object formed fom the arguments.
3391
+ *
3392
+ * With no arguments, returns the date for January 1, -4712:
3393
+ *
3394
+ * Date.ordinal.to_s # => "-4712-01-01"
3395
+ *
3396
+ * With argument +year+, returns the date for January 1 of that year:
3397
+ *
3398
+ * Date.ordinal(2001).to_s # => "2001-01-01"
3399
+ * Date.ordinal(-2001).to_s # => "-2001-01-01"
3400
+ *
3401
+ * With positive argument +yday+ == +n+,
3402
+ * returns the date for the +nth+ day of the given year:
3403
+ *
3404
+ * Date.ordinal(2001, 14).to_s # => "2001-01-14"
3333
3405
  *
3334
- * Creates a date object denoting the given ordinal date.
3406
+ * With negative argument +yday+, counts backward from the end of the year:
3335
3407
  *
3336
- * The day of year should be a negative or a positive number (as a
3337
- * relative day from the end of year when negative). It should not be
3338
- * zero.
3408
+ * Date.ordinal(2001, -14).to_s # => "2001-12-18"
3339
3409
  *
3340
- * Date.ordinal(2001) #=> #<Date: 2001-01-01 ...>
3341
- * Date.ordinal(2001,34) #=> #<Date: 2001-02-03 ...>
3342
- * Date.ordinal(2001,-1) #=> #<Date: 2001-12-31 ...>
3410
+ * Raises an exception if +yday+ is zero or out of range.
3343
3411
  *
3344
- * See also ::jd and ::new.
3412
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3413
+ *
3414
+ * Related: Date.jd, Date.new.
3345
3415
  */
3346
3416
  static VALUE
3347
3417
  date_s_ordinal(int argc, VALUE *argv, VALUE klass)
@@ -3389,29 +3459,7 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
3389
3459
  }
3390
3460
 
3391
3461
  /*
3392
- * call-seq:
3393
- * Date.civil([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) -> date
3394
- * Date.new([year=-4712[, month=1[, mday=1[, start=Date::ITALY]]]]) -> date
3395
- *
3396
- * Creates a date object denoting the given calendar date.
3397
- *
3398
- * In this class, BCE years are counted astronomically. Thus, the
3399
- * year before the year 1 is the year zero, and the year preceding the
3400
- * year zero is the year -1. The month and the day of month should be
3401
- * a negative or a positive number (as a relative month/day from the
3402
- * end of year/month when negative). They should not be zero.
3403
- *
3404
- * The last argument should be a Julian day number which denotes the
3405
- * day of calendar reform. Date::ITALY (2299161=1582-10-15),
3406
- * Date::ENGLAND (2361222=1752-09-14), Date::GREGORIAN (the proleptic
3407
- * Gregorian calendar) and Date::JULIAN (the proleptic Julian
3408
- * calendar) can be specified as a day of calendar reform.
3409
- *
3410
- * Date.new(2001) #=> #<Date: 2001-01-01 ...>
3411
- * Date.new(2001,2,3) #=> #<Date: 2001-02-03 ...>
3412
- * Date.new(2001,2,-1) #=> #<Date: 2001-02-28 ...>
3413
- *
3414
- * See also ::jd.
3462
+ * Same as Date.new.
3415
3463
  */
3416
3464
  static VALUE
3417
3465
  date_s_civil(int argc, VALUE *argv, VALUE klass)
@@ -3419,6 +3467,31 @@ date_s_civil(int argc, VALUE *argv, VALUE klass)
3419
3467
  return date_initialize(argc, argv, d_lite_s_alloc_simple(klass));
3420
3468
  }
3421
3469
 
3470
+ /*
3471
+ * call-seq:
3472
+ * Date.new(year = -4712, month = 1, mday = 1, start = Date::ITALY) -> date
3473
+ *
3474
+ * Returns a new \Date object constructed from the given arguments:
3475
+ *
3476
+ * Date.new(2022).to_s # => "2022-01-01"
3477
+ * Date.new(2022, 2).to_s # => "2022-02-01"
3478
+ * Date.new(2022, 2, 4).to_s # => "2022-02-04"
3479
+ *
3480
+ * Argument +month+ should be in range (1..12) or range (-12..-1);
3481
+ * when the argument is negative, counts backward from the end of the year:
3482
+ *
3483
+ * Date.new(2022, -11, 4).to_s # => "2022-02-04"
3484
+ *
3485
+ * Argument +mday+ should be in range (1..n) or range (-n..-1)
3486
+ * where +n+ is the number of days in the month;
3487
+ * when the argument is negative, counts backward from the end of the month.
3488
+ *
3489
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3490
+ *
3491
+ * Date.civil is an alias for Date.new.
3492
+ *
3493
+ * Related: Date.jd.
3494
+ */
3422
3495
  static VALUE
3423
3496
  date_initialize(int argc, VALUE *argv, VALUE self)
3424
3497
  {
@@ -3483,19 +3556,47 @@ date_initialize(int argc, VALUE *argv, VALUE self)
3483
3556
 
3484
3557
  /*
3485
3558
  * call-seq:
3486
- * Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) -> date
3559
+ * Date.commercial(cwyear = -4712, cweek = 1, cwday = 1, start = Date::ITALY) -> date
3560
+ *
3561
+ * Returns a new \Date object constructed from the arguments.
3562
+ *
3563
+ * Argument +cwyear+ gives the year, and should be an integer.
3564
+ *
3565
+ * Argument +cweek+ gives the index of the week within the year,
3566
+ * and should be in range (1..53) or (-53..-1);
3567
+ * in some years, 53 or -53 will be out-of-range;
3568
+ * if negative, counts backward from the end of the year:
3569
+ *
3570
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3571
+ * Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
3572
+ *
3573
+ * Argument +cwday+ gives the indes of the weekday within the week,
3574
+ * and should be in range (1..7) or (-7..-1);
3575
+ * 1 or -7 is Monday;
3576
+ * if negative, counts backward from the end of the week:
3577
+ *
3578
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3579
+ * Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
3580
+ *
3581
+ * When +cweek+ is 1:
3582
+ *
3583
+ * - If January 1 is a Friday, Saturday, or Sunday,
3584
+ * the first week begins in the week after:
3585
+ *
3586
+ * Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun"
3587
+ * Date.commercial(2023, 1, 1).to_s # => "2023-01-02"
3588
+ Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
3487
3589
  *
3488
- * Creates a date object denoting the given week date.
3590
+ * - Otherwise, the first week is the week of January 1,
3591
+ * which may mean some of the days fall on the year before:
3489
3592
  *
3490
- * The week and the day of week should be a negative or a positive
3491
- * number (as a relative week/day from the end of year/week when
3492
- * negative). They should not be zero.
3593
+ * Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed"
3594
+ * Date.commercial(2020, 1, 1).to_s # => "2019-12-30"
3595
+ Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
3493
3596
  *
3494
- * Date.commercial(2001) #=> #<Date: 2001-01-01 ...>
3495
- * Date.commercial(2002) #=> #<Date: 2001-12-31 ...>
3496
- * Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
3597
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3497
3598
  *
3498
- * See also ::jd and ::new.
3599
+ * Related: Date.jd, Date.new, Date.ordinal.
3499
3600
  */
3500
3601
  static VALUE
3501
3602
  date_s_commercial(int argc, VALUE *argv, VALUE klass)
@@ -3547,6 +3648,7 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
3547
3648
  }
3548
3649
 
3549
3650
  #ifndef NDEBUG
3651
+ /* :nodoc: */
3550
3652
  static VALUE
3551
3653
  date_s_weeknum(int argc, VALUE *argv, VALUE klass)
3552
3654
  {
@@ -3596,6 +3698,7 @@ date_s_weeknum(int argc, VALUE *argv, VALUE klass)
3596
3698
  return ret;
3597
3699
  }
3598
3700
 
3701
+ /* :nodoc: */
3599
3702
  static VALUE
3600
3703
  date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
3601
3704
  {
@@ -3670,11 +3773,14 @@ static void set_sg(union DateData *, double);
3670
3773
 
3671
3774
  /*
3672
3775
  * call-seq:
3673
- * Date.today([start=Date::ITALY]) -> date
3776
+ * Date.today(start = Date::ITALY) -> date
3777
+ *
3778
+ * Returns a new \Date object constructed from the present date:
3674
3779
  *
3675
- * Creates a date object denoting the present day.
3780
+ * Date.today.to_s # => "2022-07-06"
3781
+ *
3782
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3676
3783
  *
3677
- * Date.today #=> #<Date: 2011-06-11 ...>
3678
3784
  */
3679
3785
  static VALUE
3680
3786
  date_s_today(int argc, VALUE *argv, VALUE klass)
@@ -4265,16 +4371,20 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
4265
4371
 
4266
4372
  /*
4267
4373
  * call-seq:
4268
- * Date._strptime(string[, format='%F']) -> hash
4374
+ * Date._strptime(string, format = '%F') -> hash
4269
4375
  *
4270
- * Parses the given representation of date and time with the given
4271
- * template, and returns a hash of parsed elements. _strptime does
4272
- * not support specification of flags and width unlike strftime.
4376
+ * Returns a hash of values parsed from +string+
4377
+ * according to the given +format+:
4273
4378
  *
4274
- * Date._strptime('2001-02-03', '%Y-%m-%d')
4275
- * #=> {:year=>2001, :mon=>2, :mday=>3}
4379
+ * Date._strptime('2001-02-03', '%Y-%m-%d') # => {:year=>2001, :mon=>2, :mday=>3}
4276
4380
  *
4277
- * See also strptime(3) and #strftime.
4381
+ * For other formats, see
4382
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
4383
+ * (Unlike Date.strftime, does not support flags and width.)
4384
+ *
4385
+ * See also {strptime(3)}[https://man7.org/linux/man-pages/man3/strptime.3.html].
4386
+ *
4387
+ * Related: Date.strptime (returns a \Date object).
4278
4388
  */
4279
4389
  static VALUE
4280
4390
  date_s__strptime(int argc, VALUE *argv, VALUE klass)
@@ -4284,21 +4394,28 @@ date_s__strptime(int argc, VALUE *argv, VALUE klass)
4284
4394
 
4285
4395
  /*
4286
4396
  * call-seq:
4287
- * Date.strptime([string='-4712-01-01'[, format='%F'[, start=Date::ITALY]]]) -> date
4397
+ * Date.strptime(string = '-4712-01-01', format = '%F', start = Date::ITALY) -> date
4288
4398
  *
4289
- * Parses the given representation of date and time with the given
4290
- * template, and creates a date object. strptime does not support
4291
- * specification of flags and width unlike strftime.
4399
+ * Returns a new \Date object with values parsed from +string+,
4400
+ * according to the given +format+:
4292
4401
  *
4293
- * Date.strptime('2001-02-03', '%Y-%m-%d') #=> #<Date: 2001-02-03 ...>
4294
- * Date.strptime('03-02-2001', '%d-%m-%Y') #=> #<Date: 2001-02-03 ...>
4295
- * Date.strptime('2001-034', '%Y-%j') #=> #<Date: 2001-02-03 ...>
4296
- * Date.strptime('2001-W05-6', '%G-W%V-%u') #=> #<Date: 2001-02-03 ...>
4297
- * Date.strptime('2001 04 6', '%Y %U %w') #=> #<Date: 2001-02-03 ...>
4298
- * Date.strptime('2001 05 6', '%Y %W %u') #=> #<Date: 2001-02-03 ...>
4299
- * Date.strptime('sat3feb01', '%a%d%b%y') #=> #<Date: 2001-02-03 ...>
4402
+ * Date.strptime('2001-02-03', '%Y-%m-%d') # => #<Date: 2001-02-03>
4403
+ * Date.strptime('03-02-2001', '%d-%m-%Y') # => #<Date: 2001-02-03>
4404
+ * Date.strptime('2001-034', '%Y-%j') # => #<Date: 2001-02-03>
4405
+ * Date.strptime('2001-W05-6', '%G-W%V-%u') # => #<Date: 2001-02-03>
4406
+ * Date.strptime('2001 04 6', '%Y %U %w') # => #<Date: 2001-02-03>
4407
+ * Date.strptime('2001 05 6', '%Y %W %u') # => #<Date: 2001-02-03>
4408
+ * Date.strptime('sat3feb01', '%a%d%b%y') # => #<Date: 2001-02-03>
4300
4409
  *
4301
- * See also strptime(3) and #strftime.
4410
+ * For other formats, see
4411
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
4412
+ * (Unlike Date.strftime, does not support flags and width.)
4413
+ *
4414
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4415
+ *
4416
+ * See also {strptime(3)}[https://man7.org/linux/man-pages/man3/strptime.3.html].
4417
+ *
4418
+ * Related: Date._strptime (returns a hash).
4302
4419
  */
4303
4420
  static VALUE
4304
4421
  date_s_strptime(int argc, VALUE *argv, VALUE klass)
@@ -4339,15 +4456,24 @@ get_limit(VALUE opt)
4339
4456
  return 128;
4340
4457
  }
4341
4458
 
4459
+ #ifndef HAVE_RB_CATEGORY_WARN
4460
+ #define rb_category_warn(category, fmt) rb_warn(fmt)
4461
+ #endif
4462
+
4342
4463
  static void
4343
4464
  check_limit(VALUE str, VALUE opt)
4344
4465
  {
4466
+ size_t slen, limit;
4345
4467
  if (NIL_P(str)) return;
4346
- if (SYMBOL_P(str)) str = rb_sym2str(str);
4468
+ if (SYMBOL_P(str)) {
4469
+ rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
4470
+ "The ability to parse Symbol is an unintentional bug and is deprecated");
4471
+ str = rb_sym2str(str);
4472
+ }
4347
4473
 
4348
4474
  StringValue(str);
4349
- size_t slen = RSTRING_LEN(str);
4350
- size_t limit = get_limit(opt);
4475
+ slen = RSTRING_LEN(str);
4476
+ limit = get_limit(opt);
4351
4477
  if (slen > limit) {
4352
4478
  rb_raise(rb_eArgError,
4353
4479
  "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
@@ -4376,25 +4502,32 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4376
4502
 
4377
4503
  /*
4378
4504
  * call-seq:
4379
- * Date._parse(string[, comp=true], limit: 128) -> hash
4505
+ * Date._parse(string, comp = true, limit: 128) -> hash
4380
4506
  *
4381
- * Parses the given representation of date and time, and returns a
4382
- * hash of parsed elements.
4507
+ * <b>Note</b>:
4508
+ * This method recognizes many forms in +string+,
4509
+ * but it is not a validator.
4510
+ * For formats, see
4511
+ * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings]
4383
4512
  *
4384
- * This method *does not* function as a validator. If the input
4385
- * string does not match valid formats strictly, you may get a cryptic
4386
- * result. Should consider to use `Date._strptime` or
4387
- * `DateTime._strptime` instead of this method as possible.
4513
+ * If +string+ does not specify a valid date,
4514
+ * the result is unpredictable;
4515
+ * consider using Date._strptime instead.
4388
4516
  *
4389
- * If the optional second argument is true and the detected year is in
4390
- * the range "00" to "99", considers the year a 2-digit form and makes
4391
- * it full.
4517
+ * Returns a hash of values parsed from +string+:
4392
4518
  *
4393
- * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4519
+ * Date._parse('2001-02-03') # => {:year=>2001, :mon=>2, :mday=>3}
4394
4520
  *
4395
- * Raise an ArgumentError when the string length is longer than _limit_.
4396
- * You can stop this check by passing `limit: nil`, but note that
4397
- * it may take a long time to parse.
4521
+ * If +comp+ is +true+ and the given year is in the range <tt>(0..99)</tt>,
4522
+ * the current century is supplied;
4523
+ * otherwise, the year is taken as given:
4524
+ *
4525
+ * Date._parse('01-02-03', true) # => {:year=>2001, :mon=>2, :mday=>3}
4526
+ * Date._parse('01-02-03', false) # => {:year=>1, :mon=>2, :mday=>3}
4527
+ *
4528
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4529
+ *
4530
+ * Related: Date.parse(returns a \Date object).
4398
4531
  */
4399
4532
  static VALUE
4400
4533
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4404,27 +4537,36 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4404
4537
 
4405
4538
  /*
4406
4539
  * call-seq:
4407
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4540
+ * Date.parse(string = '-4712-01-01', comp = true, start = Date::ITALY, limit: 128) -> date
4408
4541
  *
4409
- * Parses the given representation of date and time, and creates a
4410
- * date object.
4542
+ * <b>Note</b>:
4543
+ * This method recognizes many forms in +string+,
4544
+ * but it is not a validator.
4545
+ * For formats, see
4546
+ * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings]
4547
+ * If +string+ does not specify a valid date,
4548
+ * the result is unpredictable;
4549
+ * consider using Date._strptime instead.
4411
4550
  *
4412
- * This method *does not* function as a validator. If the input
4413
- * string does not match valid formats strictly, you may get a cryptic
4414
- * result. Should consider to use `Date.strptime` instead of this
4415
- * method as possible.
4551
+ * Returns a new \Date object with values parsed from +string+:
4416
4552
  *
4417
- * If the optional second argument is true and the detected year is in
4418
- * the range "00" to "99", considers the year a 2-digit form and makes
4419
- * it full.
4553
+ * Date.parse('2001-02-03') # => #<Date: 2001-02-03>
4554
+ * Date.parse('20010203') # => #<Date: 2001-02-03>
4555
+ * Date.parse('3rd Feb 2001') # => #<Date: 2001-02-03>
4420
4556
  *
4421
- * Date.parse('2001-02-03') #=> #<Date: 2001-02-03 ...>
4422
- * Date.parse('20010203') #=> #<Date: 2001-02-03 ...>
4423
- * Date.parse('3rd Feb 2001') #=> #<Date: 2001-02-03 ...>
4557
+ * If +comp+ is +true+ and the given year is in the range <tt>(0..99)</tt>,
4558
+ * the current century is supplied;
4559
+ * otherwise, the year is taken as given:
4424
4560
  *
4425
- * Raise an ArgumentError when the string length is longer than _limit_.
4426
- * You can stop this check by passing `limit: nil`, but note that
4427
- * it may take a long time to parse.
4561
+ * Date.parse('01-02-03', true) # => #<Date: 2001-02-03>
4562
+ * Date.parse('01-02-03', false) # => #<Date: 0001-02-03>
4563
+ *
4564
+ * See:
4565
+ *
4566
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4567
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4568
+ *
4569
+ * Related: Date._parse (returns a hash).
4428
4570
  */
4429
4571
  static VALUE
4430
4572
  date_s_parse(int argc, VALUE *argv, VALUE klass)
@@ -4445,11 +4587,11 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4445
4587
 
4446
4588
  {
4447
4589
  int argc2 = 2;
4448
- VALUE argv2[3];
4590
+ VALUE argv2[3], hash;
4449
4591
  argv2[0] = str;
4450
4592
  argv2[1] = comp;
4451
4593
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4452
- VALUE hash = date_s__parse(argc2, argv2, klass);
4594
+ hash = date_s__parse(argc2, argv2, klass);
4453
4595
  return d_new_by_frags(klass, hash, sg);
4454
4596
  }
4455
4597
  }
@@ -4463,13 +4605,18 @@ VALUE date__jisx0301(VALUE);
4463
4605
 
4464
4606
  /*
4465
4607
  * call-seq:
4466
- * Date._iso8601(string, limit: 128) -> hash
4608
+ * Date._iso8601(string, limit: 128) -> hash
4467
4609
  *
4468
- * Returns a hash of parsed elements.
4610
+ * Returns a hash of values parsed from +string+, which should contain
4611
+ * an {ISO 8601 formatted date}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]:
4469
4612
  *
4470
- * Raise an ArgumentError when the string length is longer than _limit_.
4471
- * You can stop this check by passing `limit: nil`, but note that
4472
- * it may take a long time to parse.
4613
+ * d = Date.new(2001, 2, 3)
4614
+ * s = d.iso8601 # => "2001-02-03"
4615
+ * Date._iso8601(s) # => {:mday=>3, :year=>2001, :mon=>2}
4616
+ *
4617
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4618
+ *
4619
+ * Related: Date.iso8601 (returns a \Date object).
4473
4620
  */
4474
4621
  static VALUE
4475
4622
  date_s__iso8601(int argc, VALUE *argv, VALUE klass)
@@ -4484,18 +4631,22 @@ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4484
4631
 
4485
4632
  /*
4486
4633
  * call-seq:
4487
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4634
+ * Date.iso8601(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4488
4635
  *
4489
- * Creates a new Date object by parsing from a string according to
4490
- * some typical ISO 8601 formats.
4636
+ * Returns a new \Date object with values parsed from +string+,
4637
+ * which should contain
4638
+ * an {ISO 8601 formatted date}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]:
4491
4639
  *
4492
- * Date.iso8601('2001-02-03') #=> #<Date: 2001-02-03 ...>
4493
- * Date.iso8601('20010203') #=> #<Date: 2001-02-03 ...>
4494
- * Date.iso8601('2001-W05-6') #=> #<Date: 2001-02-03 ...>
4640
+ * d = Date.new(2001, 2, 3)
4641
+ * s = d.iso8601 # => "2001-02-03"
4642
+ * Date.iso8601(s) # => #<Date: 2001-02-03>
4495
4643
  *
4496
- * Raise an ArgumentError when the string length is longer than _limit_.
4497
- * You can stop this check by passing `limit: nil`, but note that
4498
- * it may take a long time to parse.
4644
+ * See:
4645
+ *
4646
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4647
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4648
+ *
4649
+ * Related: Date._iso8601 (returns a hash).
4499
4650
  */
4500
4651
  static VALUE
4501
4652
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
@@ -4514,23 +4665,29 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4514
4665
 
4515
4666
  {
4516
4667
  int argc2 = 1;
4517
- VALUE argv2[2];
4668
+ VALUE argv2[2], hash;
4518
4669
  argv2[0] = str;
4519
4670
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4520
- VALUE hash = date_s__iso8601(argc2, argv2, klass);
4671
+ hash = date_s__iso8601(argc2, argv2, klass);
4521
4672
  return d_new_by_frags(klass, hash, sg);
4522
4673
  }
4523
4674
  }
4524
4675
 
4525
4676
  /*
4526
4677
  * call-seq:
4527
- * Date._rfc3339(string, limit: 128) -> hash
4678
+ * Date._rfc3339(string, limit: 128) -> hash
4528
4679
  *
4529
- * Returns a hash of parsed elements.
4680
+ * Returns a hash of values parsed from +string+, which should be a valid
4681
+ * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]:
4530
4682
  *
4531
- * Raise an ArgumentError when the string length is longer than _limit_.
4532
- * You can stop this check by passing `limit: nil`, but note that
4533
- * it may take a long time to parse.
4683
+ * d = Date.new(2001, 2, 3)
4684
+ * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
4685
+ * Date._rfc3339(s)
4686
+ * # => {:year=>2001, :mon=>2, :mday=>3, :hour=>0, :min=>0, :sec=>0, :zone=>"+00:00", :offset=>0}
4687
+ *
4688
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4689
+ *
4690
+ * Related: Date.rfc3339 (returns a \Date object).
4534
4691
  */
4535
4692
  static VALUE
4536
4693
  date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -4545,16 +4702,22 @@ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4545
4702
 
4546
4703
  /*
4547
4704
  * call-seq:
4548
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4705
+ * Date.rfc3339(string = '-4712-01-01T00:00:00+00:00', start = Date::ITALY, limit: 128) -> date
4549
4706
  *
4550
- * Creates a new Date object by parsing from a string according to
4551
- * some typical RFC 3339 formats.
4707
+ * Returns a new \Date object with values parsed from +string+,
4708
+ * which should be a valid
4709
+ * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]:
4552
4710
  *
4553
- * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
4711
+ * d = Date.new(2001, 2, 3)
4712
+ * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
4713
+ * Date.rfc3339(s) # => #<Date: 2001-02-03>
4554
4714
  *
4555
- * Raise an ArgumentError when the string length is longer than _limit_.
4556
- * You can stop this check by passing `limit: nil`, but note that
4557
- * it may take a long time to parse.
4715
+ * See:
4716
+ *
4717
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4718
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4719
+ *
4720
+ * Related: Date._rfc3339 (returns a hash).
4558
4721
  */
4559
4722
  static VALUE
4560
4723
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -4573,23 +4736,28 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4573
4736
 
4574
4737
  {
4575
4738
  int argc2 = 1;
4576
- VALUE argv2[2];
4739
+ VALUE argv2[2], hash;
4577
4740
  argv2[0] = str;
4578
4741
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4579
- VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4742
+ hash = date_s__rfc3339(argc2, argv2, klass);
4580
4743
  return d_new_by_frags(klass, hash, sg);
4581
4744
  }
4582
4745
  }
4583
4746
 
4584
4747
  /*
4585
4748
  * call-seq:
4586
- * Date._xmlschema(string, limit: 128) -> hash
4749
+ * Date._xmlschema(string, limit: 128) -> hash
4587
4750
  *
4588
- * Returns a hash of parsed elements.
4751
+ * Returns a hash of values parsed from +string+, which should be a valid
4752
+ * XML date format:
4589
4753
  *
4590
- * Raise an ArgumentError when the string length is longer than _limit_.
4591
- * You can stop this check by passing `limit: nil`, but note that
4592
- * it may take a long time to parse.
4754
+ * d = Date.new(2001, 2, 3)
4755
+ * s = d.xmlschema # => "2001-02-03"
4756
+ * Date._xmlschema(s) # => {:year=>2001, :mon=>2, :mday=>3}
4757
+ *
4758
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4759
+ *
4760
+ * Related: Date.xmlschema (returns a \Date object).
4593
4761
  */
4594
4762
  static VALUE
4595
4763
  date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -4604,16 +4772,21 @@ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4604
4772
 
4605
4773
  /*
4606
4774
  * call-seq:
4607
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4775
+ * Date.xmlschema(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4608
4776
  *
4609
- * Creates a new Date object by parsing from a string according to
4610
- * some typical XML Schema formats.
4777
+ * Returns a new \Date object with values parsed from +string+,
4778
+ * which should be a valid XML date format:
4611
4779
  *
4612
- * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4780
+ * d = Date.new(2001, 2, 3)
4781
+ * s = d.xmlschema # => "2001-02-03"
4782
+ * Date.xmlschema(s) # => #<Date: 2001-02-03>
4613
4783
  *
4614
- * Raise an ArgumentError when the string length is longer than _limit_.
4615
- * You can stop this check by passing `limit: nil`, but note that
4616
- * it may take a long time to parse.
4784
+ * See:
4785
+ *
4786
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4787
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4788
+ *
4789
+ * Related: Date._xmlschema (returns a hash).
4617
4790
  */
4618
4791
  static VALUE
4619
4792
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -4632,24 +4805,31 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4632
4805
 
4633
4806
  {
4634
4807
  int argc2 = 1;
4635
- VALUE argv2[2];
4808
+ VALUE argv2[2], hash;
4636
4809
  argv2[0] = str;
4637
4810
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4638
- VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4811
+ hash = date_s__xmlschema(argc2, argv2, klass);
4639
4812
  return d_new_by_frags(klass, hash, sg);
4640
4813
  }
4641
4814
  }
4642
4815
 
4643
4816
  /*
4644
4817
  * call-seq:
4645
- * Date._rfc2822(string, limit: 128) -> hash
4646
- * Date._rfc822(string, limit: 128) -> hash
4818
+ * Date._rfc2822(string, limit: 128) -> hash
4647
4819
  *
4648
- * Returns a hash of parsed elements.
4820
+ * Returns a hash of values parsed from +string+, which should be a valid
4821
+ * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]:
4649
4822
  *
4650
- * Raise an ArgumentError when the string length is longer than _limit_.
4651
- * You can stop this check by passing `limit: nil`, but note that
4652
- * it may take a long time to parse.
4823
+ * d = Date.new(2001, 2, 3)
4824
+ * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
4825
+ * Date._rfc2822(s)
4826
+ * # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"+0000", :offset=>0}
4827
+ *
4828
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4829
+ *
4830
+ * Date._rfc822 is an alias for Date._rfc2822.
4831
+ *
4832
+ * Related: Date.rfc2822 (returns a \Date object).
4653
4833
  */
4654
4834
  static VALUE
4655
4835
  date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -4664,18 +4844,24 @@ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4664
4844
 
4665
4845
  /*
4666
4846
  * call-seq:
4667
- * Date.rfc2822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4668
- * Date.rfc822(string='Mon, 1 Jan -4712 00:00:00 +0000'[, start=Date::ITALY], limit: 128) -> date
4847
+ * Date.rfc2822(string = 'Mon, 1 Jan -4712 00:00:00 +0000', start = Date::ITALY, limit: 128) -> date
4669
4848
  *
4670
- * Creates a new Date object by parsing from a string according to
4671
- * some typical RFC 2822 formats.
4849
+ * Returns a new \Date object with values parsed from +string+,
4850
+ * which should be a valid
4851
+ * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]:
4672
4852
  *
4673
- * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4674
- * #=> #<Date: 2001-02-03 ...>
4853
+ * d = Date.new(2001, 2, 3)
4854
+ * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
4855
+ * Date.rfc2822(s) # => #<Date: 2001-02-03>
4675
4856
  *
4676
- * Raise an ArgumentError when the string length is longer than _limit_.
4677
- * You can stop this check by passing `limit: nil`, but note that
4678
- * it may take a long time to parse.
4857
+ * See:
4858
+ *
4859
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4860
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4861
+ *
4862
+ * Date.rfc822 is an alias for Date.rfc2822.
4863
+ *
4864
+ * Related: Date._rfc2822 (returns a hash).
4679
4865
  */
4680
4866
  static VALUE
4681
4867
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -4693,23 +4879,27 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4693
4879
 
4694
4880
  {
4695
4881
  int argc2 = 1;
4696
- VALUE argv2[2];
4882
+ VALUE argv2[2], hash;
4697
4883
  argv2[0] = str;
4698
4884
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4699
- VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4885
+ hash = date_s__rfc2822(argc2, argv2, klass);
4700
4886
  return d_new_by_frags(klass, hash, sg);
4701
4887
  }
4702
4888
  }
4703
4889
 
4704
4890
  /*
4705
4891
  * call-seq:
4706
- * Date._httpdate(string, limit: 128) -> hash
4892
+ * Date._httpdate(string, limit: 128) -> hash
4707
4893
  *
4708
- * Returns a hash of parsed elements.
4894
+ * Returns a hash of values parsed from +string+, which should be a valid
4895
+ * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]:
4709
4896
  *
4710
- * Raise an ArgumentError when the string length is longer than _limit_.
4711
- * You can stop this check by passing `limit: nil`, but note that
4712
- * it may take a long time to parse.
4897
+ * d = Date.new(2001, 2, 3)
4898
+ * s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
4899
+ * Date._httpdate(s)
4900
+ * # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"GMT", :offset=>0}
4901
+ *
4902
+ * Related: Date.httpdate (returns a \Date object).
4713
4903
  */
4714
4904
  static VALUE
4715
4905
  date_s__httpdate(int argc, VALUE *argv, VALUE klass)
@@ -4724,17 +4914,22 @@ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4724
4914
 
4725
4915
  /*
4726
4916
  * call-seq:
4727
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4917
+ * Date.httpdate(string = 'Mon, 01 Jan -4712 00:00:00 GMT', start = Date::ITALY, limit: 128) -> date
4728
4918
  *
4729
- * Creates a new Date object by parsing from a string according to
4730
- * some RFC 2616 format.
4919
+ * Returns a new \Date object with values parsed from +string+,
4920
+ * which should be a valid
4921
+ * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]:
4731
4922
  *
4732
- * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4733
- * #=> #<Date: 2001-02-03 ...>
4923
+ * d = Date.new(2001, 2, 3)
4924
+ s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
4925
+ Date.httpdate(s) # => #<Date: 2001-02-03>
4734
4926
  *
4735
- * Raise an ArgumentError when the string length is longer than _limit_.
4736
- * You can stop this check by passing `limit: nil`, but note that
4737
- * it may take a long time to parse.
4927
+ * See:
4928
+ *
4929
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4930
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4931
+ *
4932
+ * Related: Date._httpdate (returns a hash).
4738
4933
  */
4739
4934
  static VALUE
4740
4935
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
@@ -4752,23 +4947,28 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4752
4947
 
4753
4948
  {
4754
4949
  int argc2 = 1;
4755
- VALUE argv2[2];
4950
+ VALUE argv2[2], hash;
4756
4951
  argv2[0] = str;
4757
4952
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4758
- VALUE hash = date_s__httpdate(argc2, argv2, klass);
4953
+ hash = date_s__httpdate(argc2, argv2, klass);
4759
4954
  return d_new_by_frags(klass, hash, sg);
4760
4955
  }
4761
4956
  }
4762
4957
 
4763
4958
  /*
4764
4959
  * call-seq:
4765
- * Date._jisx0301(string, limit: 128) -> hash
4960
+ * Date._jisx0301(string, limit: 128) -> hash
4766
4961
  *
4767
- * Returns a hash of parsed elements.
4962
+ * Returns a hash of values parsed from +string+, which should be a valid
4963
+ * {JIS X 0301 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-JIS+X+0301+Format]:
4768
4964
  *
4769
- * Raise an ArgumentError when the string length is longer than _limit_.
4770
- * You can stop this check by passing `limit: nil`, but note that
4771
- * it may take a long time to parse.
4965
+ * d = Date.new(2001, 2, 3)
4966
+ * s = d.jisx0301 # => "H13.02.03"
4967
+ * Date._jisx0301(s) # => {:year=>2001, :mon=>2, :mday=>3}
4968
+ *
4969
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4970
+ *
4971
+ * Related: Date.jisx0301 (returns a \Date object).
4772
4972
  */
4773
4973
  static VALUE
4774
4974
  date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -4783,20 +4983,25 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4783
4983
 
4784
4984
  /*
4785
4985
  * call-seq:
4786
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4986
+ * Date.jisx0301(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4787
4987
  *
4788
- * Creates a new Date object by parsing from a string according to
4789
- * some typical JIS X 0301 formats.
4988
+ * Returns a new \Date object with values parsed from +string+,
4989
+ * which should be a valid {JIS X 0301 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-JIS+X+0301+Format]:
4790
4990
  *
4791
- * Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
4991
+ * d = Date.new(2001, 2, 3)
4992
+ * s = d.jisx0301 # => "H13.02.03"
4993
+ * Date.jisx0301(s) # => #<Date: 2001-02-03>
4792
4994
  *
4793
4995
  * For no-era year, legacy format, Heisei is assumed.
4794
4996
  *
4795
- * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
4997
+ * Date.jisx0301('13.02.03') # => #<Date: 2001-02-03>
4796
4998
  *
4797
- * Raise an ArgumentError when the string length is longer than _limit_.
4798
- * You can stop this check by passing `limit: nil`, but note that
4799
- * it may take a long time to parse.
4999
+ * See:
5000
+ *
5001
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5002
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
5003
+ *
5004
+ * Related: Date._jisx0301 (returns a hash).
4800
5005
  */
4801
5006
  static VALUE
4802
5007
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -4815,10 +5020,10 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4815
5020
 
4816
5021
  {
4817
5022
  int argc2 = 1;
4818
- VALUE argv2[2];
5023
+ VALUE argv2[2], hash;
4819
5024
  argv2[0] = str;
4820
5025
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4821
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
5026
+ hash = date_s__jisx0301(argc2, argv2, klass);
4822
5027
  return d_new_by_frags(klass, hash, sg);
4823
5028
  }
4824
5029
  }
@@ -4988,6 +5193,7 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
4988
5193
  }
4989
5194
 
4990
5195
  #ifndef NDEBUG
5196
+ /* :nodoc: */
4991
5197
  static VALUE
4992
5198
  d_lite_fill(VALUE self)
4993
5199
  {
@@ -5077,12 +5283,15 @@ d_lite_mjd(VALUE self)
5077
5283
 
5078
5284
  /*
5079
5285
  * call-seq:
5080
- * d.ld -> integer
5286
+ * ld -> integer
5081
5287
  *
5082
- * Returns the Lilian day number. This is a whole number, which is
5083
- * adjusted by the offset as the local time.
5288
+ * Returns the
5289
+ * {Lilian day number}[https://en.wikipedia.org/wiki/Lilian_date],
5290
+ * which is the number of days since the beginning of the Gregorian
5291
+ * calendar, October 15, 1582.
5292
+ *
5293
+ * Date.new(2001, 2, 3).ld # => 152784
5084
5294
  *
5085
- * Date.new(2001,2,3).ld #=> 152784
5086
5295
  */
5087
5296
  static VALUE
5088
5297
  d_lite_ld(VALUE self)
@@ -5093,12 +5302,13 @@ d_lite_ld(VALUE self)
5093
5302
 
5094
5303
  /*
5095
5304
  * call-seq:
5096
- * d.year -> integer
5305
+ * year -> integer
5306
+ *
5307
+ * Returns the year:
5097
5308
  *
5098
- * Returns the year.
5309
+ * Date.new(2001, 2, 3).year # => 2001
5310
+ * (Date.new(1, 1, 1) - 1).year # => 0
5099
5311
  *
5100
- * Date.new(2001,2,3).year #=> 2001
5101
- * (Date.new(1,1,1) - 1).year #=> 0
5102
5312
  */
5103
5313
  static VALUE
5104
5314
  d_lite_year(VALUE self)
@@ -5109,11 +5319,12 @@ d_lite_year(VALUE self)
5109
5319
 
5110
5320
  /*
5111
5321
  * call-seq:
5112
- * d.yday -> fixnum
5322
+ * yday -> integer
5323
+ *
5324
+ * Returns the day of the year, in range (1..366):
5113
5325
  *
5114
- * Returns the day of the year (1-366).
5326
+ * Date.new(2001, 2, 3).yday # => 34
5115
5327
  *
5116
- * Date.new(2001,2,3).yday #=> 34
5117
5328
  */
5118
5329
  static VALUE
5119
5330
  d_lite_yday(VALUE self)
@@ -5124,12 +5335,13 @@ d_lite_yday(VALUE self)
5124
5335
 
5125
5336
  /*
5126
5337
  * call-seq:
5127
- * d.mon -> fixnum
5128
- * d.month -> fixnum
5338
+ * mon -> integer
5129
5339
  *
5130
- * Returns the month (1-12).
5340
+ * Returns the month in range (1..12):
5131
5341
  *
5132
- * Date.new(2001,2,3).mon #=> 2
5342
+ * Date.new(2001, 2, 3).mon # => 2
5343
+ *
5344
+ * Date#month is an alias for Date#mon.
5133
5345
  */
5134
5346
  static VALUE
5135
5347
  d_lite_mon(VALUE self)
@@ -5140,12 +5352,13 @@ d_lite_mon(VALUE self)
5140
5352
 
5141
5353
  /*
5142
5354
  * call-seq:
5143
- * d.mday -> fixnum
5144
- * d.day -> fixnum
5355
+ * mday -> integer
5356
+ *
5357
+ * Returns the day of the month in range (1..31):
5145
5358
  *
5146
- * Returns the day of the month (1-31).
5359
+ * Date.new(2001, 2, 3).mday # => 3
5147
5360
  *
5148
- * Date.new(2001,2,3).mday #=> 3
5361
+ * Date#day is an alias for Date#mday.
5149
5362
  */
5150
5363
  static VALUE
5151
5364
  d_lite_mday(VALUE self)
@@ -5156,11 +5369,12 @@ d_lite_mday(VALUE self)
5156
5369
 
5157
5370
  /*
5158
5371
  * call-seq:
5159
- * d.day_fraction -> rational
5372
+ * day_fraction -> rational
5160
5373
  *
5161
- * Returns the fractional part of the day.
5374
+ * Returns the fractional part of the day in range (Rational(0, 1)...Rational(1, 1)):
5375
+ *
5376
+ * DateTime.new(2001,2,3,12).day_fraction # => (1/2)
5162
5377
  *
5163
- * DateTime.new(2001,2,3,12).day_fraction #=> (1/2)
5164
5378
  */
5165
5379
  static VALUE
5166
5380
  d_lite_day_fraction(VALUE self)
@@ -5173,12 +5387,14 @@ d_lite_day_fraction(VALUE self)
5173
5387
 
5174
5388
  /*
5175
5389
  * call-seq:
5176
- * d.cwyear -> integer
5390
+ * cwyear -> integer
5391
+ *
5392
+ * Returns commercial-date year for +self+
5393
+ * (see Date.commercial):
5177
5394
  *
5178
- * Returns the calendar week based year.
5395
+ * Date.new(2001, 2, 3).cwyear # => 2001
5396
+ * Date.new(2000, 1, 1).cwyear # => 1999
5179
5397
  *
5180
- * Date.new(2001,2,3).cwyear #=> 2001
5181
- * Date.new(2000,1,1).cwyear #=> 1999
5182
5398
  */
5183
5399
  static VALUE
5184
5400
  d_lite_cwyear(VALUE self)
@@ -5189,11 +5405,13 @@ d_lite_cwyear(VALUE self)
5189
5405
 
5190
5406
  /*
5191
5407
  * call-seq:
5192
- * d.cweek -> fixnum
5408
+ * cweek -> integer
5409
+ *
5410
+ * Returns commercial-date week index for +self+
5411
+ * (see Date.commercial):
5193
5412
  *
5194
- * Returns the calendar week number (1-53).
5413
+ * Date.new(2001, 2, 3).cweek # => 5
5195
5414
  *
5196
- * Date.new(2001,2,3).cweek #=> 5
5197
5415
  */
5198
5416
  static VALUE
5199
5417
  d_lite_cweek(VALUE self)
@@ -5204,11 +5422,14 @@ d_lite_cweek(VALUE self)
5204
5422
 
5205
5423
  /*
5206
5424
  * call-seq:
5207
- * d.cwday -> fixnum
5425
+ * cwday -> integer
5208
5426
  *
5209
- * Returns the day of calendar week (1-7, Monday is 1).
5427
+ * Returns the commercial-date weekday index for +self+
5428
+ * (see Date.commercial);
5429
+ * 1 is Monday:
5430
+ *
5431
+ * Date.new(2001, 2, 3).cwday # => 6
5210
5432
  *
5211
- * Date.new(2001,2,3).cwday #=> 6
5212
5433
  */
5213
5434
  static VALUE
5214
5435
  d_lite_cwday(VALUE self)
@@ -5218,6 +5439,7 @@ d_lite_cwday(VALUE self)
5218
5439
  }
5219
5440
 
5220
5441
  #ifndef NDEBUG
5442
+ /* :nodoc: */
5221
5443
  static VALUE
5222
5444
  d_lite_wnum0(VALUE self)
5223
5445
  {
@@ -5225,6 +5447,7 @@ d_lite_wnum0(VALUE self)
5225
5447
  return INT2FIX(m_wnum0(dat));
5226
5448
  }
5227
5449
 
5450
+ /* :nodoc: */
5228
5451
  static VALUE
5229
5452
  d_lite_wnum1(VALUE self)
5230
5453
  {
@@ -5235,11 +5458,12 @@ d_lite_wnum1(VALUE self)
5235
5458
 
5236
5459
  /*
5237
5460
  * call-seq:
5238
- * d.wday -> fixnum
5461
+ * wday -> integer
5462
+ *
5463
+ * Returns the day of week in range (0..6); Sunday is 0:
5239
5464
  *
5240
- * Returns the day of week (0-6, Sunday is zero).
5465
+ * Date.new(2001, 2, 3).wday # => 6
5241
5466
  *
5242
- * Date.new(2001,2,3).wday #=> 6
5243
5467
  */
5244
5468
  static VALUE
5245
5469
  d_lite_wday(VALUE self)
@@ -5250,9 +5474,9 @@ d_lite_wday(VALUE self)
5250
5474
 
5251
5475
  /*
5252
5476
  * call-seq:
5253
- * d.sunday? -> bool
5477
+ * sunday? -> true or false
5254
5478
  *
5255
- * Returns true if the date is Sunday.
5479
+ * Returns +true+ if +self+ is a Sunday, +false+ otherwise.
5256
5480
  */
5257
5481
  static VALUE
5258
5482
  d_lite_sunday_p(VALUE self)
@@ -5263,9 +5487,9 @@ d_lite_sunday_p(VALUE self)
5263
5487
 
5264
5488
  /*
5265
5489
  * call-seq:
5266
- * d.monday? -> bool
5490
+ * monday? -> true or false
5267
5491
  *
5268
- * Returns true if the date is Monday.
5492
+ * Returns +true+ if +self+ is a Monday, +false+ otherwise.
5269
5493
  */
5270
5494
  static VALUE
5271
5495
  d_lite_monday_p(VALUE self)
@@ -5276,9 +5500,9 @@ d_lite_monday_p(VALUE self)
5276
5500
 
5277
5501
  /*
5278
5502
  * call-seq:
5279
- * d.tuesday? -> bool
5503
+ * tuesday? -> true or false
5280
5504
  *
5281
- * Returns true if the date is Tuesday.
5505
+ * Returns +true+ if +self+ is a Tuesday, +false+ otherwise.
5282
5506
  */
5283
5507
  static VALUE
5284
5508
  d_lite_tuesday_p(VALUE self)
@@ -5289,9 +5513,9 @@ d_lite_tuesday_p(VALUE self)
5289
5513
 
5290
5514
  /*
5291
5515
  * call-seq:
5292
- * d.wednesday? -> bool
5516
+ * wednesday? -> true or false
5293
5517
  *
5294
- * Returns true if the date is Wednesday.
5518
+ * Returns +true+ if +self+ is a Wednesday, +false+ otherwise.
5295
5519
  */
5296
5520
  static VALUE
5297
5521
  d_lite_wednesday_p(VALUE self)
@@ -5302,9 +5526,9 @@ d_lite_wednesday_p(VALUE self)
5302
5526
 
5303
5527
  /*
5304
5528
  * call-seq:
5305
- * d.thursday? -> bool
5529
+ * thursday? -> true or false
5306
5530
  *
5307
- * Returns true if the date is Thursday.
5531
+ * Returns +true+ if +self+ is a Thursday, +false+ otherwise.
5308
5532
  */
5309
5533
  static VALUE
5310
5534
  d_lite_thursday_p(VALUE self)
@@ -5315,9 +5539,9 @@ d_lite_thursday_p(VALUE self)
5315
5539
 
5316
5540
  /*
5317
5541
  * call-seq:
5318
- * d.friday? -> bool
5542
+ * friday? -> true or false
5319
5543
  *
5320
- * Returns true if the date is Friday.
5544
+ * Returns +true+ if +self+ is a Friday, +false+ otherwise.
5321
5545
  */
5322
5546
  static VALUE
5323
5547
  d_lite_friday_p(VALUE self)
@@ -5328,9 +5552,9 @@ d_lite_friday_p(VALUE self)
5328
5552
 
5329
5553
  /*
5330
5554
  * call-seq:
5331
- * d.saturday? -> bool
5555
+ * saturday? -> true or false
5332
5556
  *
5333
- * Returns true if the date is Saturday.
5557
+ * Returns +true+ if +self+ is a Saturday, +false+ otherwise.
5334
5558
  */
5335
5559
  static VALUE
5336
5560
  d_lite_saturday_p(VALUE self)
@@ -5340,6 +5564,7 @@ d_lite_saturday_p(VALUE self)
5340
5564
  }
5341
5565
 
5342
5566
  #ifndef NDEBUG
5567
+ /* :nodoc: */
5343
5568
  static VALUE
5344
5569
  d_lite_nth_kday_p(VALUE self, VALUE n, VALUE k)
5345
5570
  {
@@ -5361,11 +5586,12 @@ d_lite_nth_kday_p(VALUE self, VALUE n, VALUE k)
5361
5586
 
5362
5587
  /*
5363
5588
  * call-seq:
5364
- * d.hour -> fixnum
5589
+ * hour -> integer
5590
+ *
5591
+ * Returns the hour in range (0..23):
5365
5592
  *
5366
- * Returns the hour (0-23).
5593
+ * DateTime.new(2001, 2, 3, 4, 5, 6).hour # => 4
5367
5594
  *
5368
- * DateTime.new(2001,2,3,4,5,6).hour #=> 4
5369
5595
  */
5370
5596
  static VALUE
5371
5597
  d_lite_hour(VALUE self)
@@ -5376,12 +5602,13 @@ d_lite_hour(VALUE self)
5376
5602
 
5377
5603
  /*
5378
5604
  * call-seq:
5379
- * d.min -> fixnum
5380
- * d.minute -> fixnum
5605
+ * min -> integer
5381
5606
  *
5382
- * Returns the minute (0-59).
5607
+ * Returns the minute in range (0..59):
5383
5608
  *
5384
- * DateTime.new(2001,2,3,4,5,6).min #=> 5
5609
+ * DateTime.new(2001, 2, 3, 4, 5, 6).min # => 5
5610
+ *
5611
+ * Date#minute is an alias for Date#min.
5385
5612
  */
5386
5613
  static VALUE
5387
5614
  d_lite_min(VALUE self)
@@ -5392,12 +5619,13 @@ d_lite_min(VALUE self)
5392
5619
 
5393
5620
  /*
5394
5621
  * call-seq:
5395
- * d.sec -> fixnum
5396
- * d.second -> fixnum
5622
+ * sec -> integer
5623
+ *
5624
+ * Returns the second in range (0..59):
5397
5625
  *
5398
- * Returns the second (0-59).
5626
+ * DateTime.new(2001, 2, 3, 4, 5, 6).sec # => 6
5399
5627
  *
5400
- * DateTime.new(2001,2,3,4,5,6).sec #=> 6
5628
+ * Date#second is an alias for Date#sec.
5401
5629
  */
5402
5630
  static VALUE
5403
5631
  d_lite_sec(VALUE self)
@@ -5408,12 +5636,14 @@ d_lite_sec(VALUE self)
5408
5636
 
5409
5637
  /*
5410
5638
  * call-seq:
5411
- * d.sec_fraction -> rational
5412
- * d.second_fraction -> rational
5639
+ * sec_fraction -> rational
5640
+ *
5641
+ * Returns the fractional part of the second in range
5642
+ * (Rational(0, 1)...Rational(1, 1)):
5413
5643
  *
5414
- * Returns the fractional part of the second.
5644
+ * DateTime.new(2001, 2, 3, 4, 5, 6.5).sec_fraction # => (1/2)
5415
5645
  *
5416
- * DateTime.new(2001,2,3,4,5,6.5).sec_fraction #=> (1/2)
5646
+ * Date#second_fraction is an alias for Date#sec_fraction.
5417
5647
  */
5418
5648
  static VALUE
5419
5649
  d_lite_sec_fraction(VALUE self)
@@ -5454,12 +5684,14 @@ d_lite_zone(VALUE self)
5454
5684
 
5455
5685
  /*
5456
5686
  * call-seq:
5457
- * d.julian? -> bool
5687
+ * d.julian? -> true or false
5458
5688
  *
5459
- * Returns true if the date is before the day of calendar reform.
5689
+ * Returns +true+ if the date is before the date of calendar reform,
5690
+ * +false+ otherwise:
5691
+ *
5692
+ * (Date.new(1582, 10, 15) - 1).julian? # => true
5693
+ * Date.new(1582, 10, 15).julian? # => false
5460
5694
  *
5461
- * Date.new(1582,10,15).julian? #=> false
5462
- * (Date.new(1582,10,15) - 1).julian? #=> true
5463
5695
  */
5464
5696
  static VALUE
5465
5697
  d_lite_julian_p(VALUE self)
@@ -5470,12 +5702,14 @@ d_lite_julian_p(VALUE self)
5470
5702
 
5471
5703
  /*
5472
5704
  * call-seq:
5473
- * d.gregorian? -> bool
5705
+ * gregorian? -> true or false
5706
+ *
5707
+ * Returns +true+ if the date is on or after
5708
+ * the date of calendar reform, +false+ otherwise:
5474
5709
  *
5475
- * Returns true if the date is on or after the day of calendar reform.
5710
+ * Date.new(1582, 10, 15).gregorian? # => true
5711
+ * (Date.new(1582, 10, 15) - 1).gregorian? # => false
5476
5712
  *
5477
- * Date.new(1582,10,15).gregorian? #=> true
5478
- * (Date.new(1582,10,15) - 1).gregorian? #=> false
5479
5713
  */
5480
5714
  static VALUE
5481
5715
  d_lite_gregorian_p(VALUE self)
@@ -5486,12 +5720,13 @@ d_lite_gregorian_p(VALUE self)
5486
5720
 
5487
5721
  /*
5488
5722
  * call-seq:
5489
- * d.leap? -> bool
5723
+ * leap? -> true or false
5490
5724
  *
5491
- * Returns true if the year is a leap year.
5725
+ * Returns +true+ if the year is a leap year, +false+ otherwise:
5726
+ *
5727
+ * Date.new(2000).leap? # => true
5728
+ * Date.new(2001).leap? # => false
5492
5729
  *
5493
- * Date.new(2000).leap? #=> true
5494
- * Date.new(2001).leap? #=> false
5495
5730
  */
5496
5731
  static VALUE
5497
5732
  d_lite_leap_p(VALUE self)
@@ -5510,12 +5745,25 @@ d_lite_leap_p(VALUE self)
5510
5745
 
5511
5746
  /*
5512
5747
  * call-seq:
5513
- * d.start -> float
5748
+ * start -> float
5749
+ *
5750
+ * Returns the Julian start date for calendar reform;
5751
+ * if not an infinity, the returned value is suitable
5752
+ * for passing to Date#jd:
5753
+ *
5754
+ * d = Date.new(2001, 2, 3, Date::ITALY)
5755
+ * s = d.start # => 2299161.0
5756
+ * Date.jd(s).to_s # => "1582-10-15"
5757
+ *
5758
+ * d = Date.new(2001, 2, 3, Date::ENGLAND)
5759
+ * s = d.start # => 2361222.0
5760
+ * Date.jd(s).to_s # => "1752-09-14"
5514
5761
  *
5515
- * Returns the Julian day number denoting the day of calendar reform.
5762
+ * Date.new(2001, 2, 3, Date::GREGORIAN).start # => -Infinity
5763
+ * Date.new(2001, 2, 3, Date::JULIAN).start # => Infinity
5764
+ *
5765
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5516
5766
  *
5517
- * Date.new(2001,2,3).start #=> 2299161.0
5518
- * Date.new(2001,2,3,Date::GREGORIAN).start #=> -Infinity
5519
5767
  */
5520
5768
  static VALUE
5521
5769
  d_lite_start(VALUE self)
@@ -5580,12 +5828,17 @@ dup_obj_with_new_start(VALUE obj, double sg)
5580
5828
 
5581
5829
  /*
5582
5830
  * call-seq:
5583
- * d.new_start([start=Date::ITALY]) -> date
5831
+ * new_start(start = Date::ITALY]) -> new_date
5832
+ *
5833
+ * Returns a copy of +self+ with the given +start+ value:
5834
+ *
5835
+ * d0 = Date.new(2000, 2, 3)
5836
+ * d0.julian? # => false
5837
+ * d1 = d0.new_start(Date::JULIAN)
5838
+ * d1.julian? # => true
5584
5839
  *
5585
- * Duplicates self and resets its day of calendar reform.
5840
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5586
5841
  *
5587
- * d = Date.new(1582,10,15)
5588
- * d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
5589
5842
  */
5590
5843
  static VALUE
5591
5844
  d_lite_new_start(int argc, VALUE *argv, VALUE self)
@@ -5604,9 +5857,10 @@ d_lite_new_start(int argc, VALUE *argv, VALUE self)
5604
5857
 
5605
5858
  /*
5606
5859
  * call-seq:
5607
- * d.italy -> date
5860
+ * italy -> new_date
5861
+ *
5862
+ * Equivalent to Date#new_start with argument Date::ITALY.
5608
5863
  *
5609
- * This method is equivalent to new_start(Date::ITALY).
5610
5864
  */
5611
5865
  static VALUE
5612
5866
  d_lite_italy(VALUE self)
@@ -5616,9 +5870,9 @@ d_lite_italy(VALUE self)
5616
5870
 
5617
5871
  /*
5618
5872
  * call-seq:
5619
- * d.england -> date
5873
+ * england -> new_date
5620
5874
  *
5621
- * This method is equivalent to new_start(Date::ENGLAND).
5875
+ * Equivalent to Date#new_start with argument Date::ENGLAND.
5622
5876
  */
5623
5877
  static VALUE
5624
5878
  d_lite_england(VALUE self)
@@ -5628,9 +5882,9 @@ d_lite_england(VALUE self)
5628
5882
 
5629
5883
  /*
5630
5884
  * call-seq:
5631
- * d.julian -> date
5885
+ * julian -> new_date
5632
5886
  *
5633
- * This method is equivalent to new_start(Date::JULIAN).
5887
+ * Equivalent to Date#new_start with argument Date::JULIAN.
5634
5888
  */
5635
5889
  static VALUE
5636
5890
  d_lite_julian(VALUE self)
@@ -5640,9 +5894,9 @@ d_lite_julian(VALUE self)
5640
5894
 
5641
5895
  /*
5642
5896
  * call-seq:
5643
- * d.gregorian -> date
5897
+ * gregorian -> new_date
5644
5898
  *
5645
- * This method is equivalent to new_start(Date::GREGORIAN).
5899
+ * Equivalent to Date#new_start with argument Date::GREGORIAN.
5646
5900
  */
5647
5901
  static VALUE
5648
5902
  d_lite_gregorian(VALUE self)
@@ -6123,9 +6377,9 @@ d_lite_minus(VALUE self, VALUE other)
6123
6377
 
6124
6378
  /*
6125
6379
  * call-seq:
6126
- * d.next_day([n=1]) -> date
6380
+ * next_day(n = 1) -> new_date
6127
6381
  *
6128
- * This method is equivalent to d + n.
6382
+ * Equivalent to Date#+ with argument +n+.
6129
6383
  */
6130
6384
  static VALUE
6131
6385
  d_lite_next_day(int argc, VALUE *argv, VALUE self)
@@ -6140,9 +6394,9 @@ d_lite_next_day(int argc, VALUE *argv, VALUE self)
6140
6394
 
6141
6395
  /*
6142
6396
  * call-seq:
6143
- * d.prev_day([n=1]) -> date
6397
+ * prev_day(n = 1) -> new_date
6144
6398
  *
6145
- * This method is equivalent to d - n.
6399
+ * Equivalent to Date#- with argument +n+.
6146
6400
  */
6147
6401
  static VALUE
6148
6402
  d_lite_prev_day(int argc, VALUE *argv, VALUE self)
@@ -6157,10 +6411,15 @@ d_lite_prev_day(int argc, VALUE *argv, VALUE self)
6157
6411
 
6158
6412
  /*
6159
6413
  * call-seq:
6160
- * d.succ -> date
6161
- * d.next -> date
6414
+ * d.next -> new_date
6415
+ *
6416
+ * Returns a new \Date object representing the following day:
6162
6417
  *
6163
- * Returns a date object denoting the following day.
6418
+ * d = Date.new(2001, 2, 3)
6419
+ * d.to_s # => "2001-02-03"
6420
+ * d.next.to_s # => "2001-02-04"
6421
+ *
6422
+ * Date#succ is an alias for Date#next.
6164
6423
  */
6165
6424
  static VALUE
6166
6425
  d_lite_next(VALUE self)
@@ -6170,26 +6429,30 @@ d_lite_next(VALUE self)
6170
6429
 
6171
6430
  /*
6172
6431
  * call-seq:
6173
- * d >> n -> date
6432
+ * d >> n -> new_date
6433
+ *
6434
+ * Returns a new \Date object representing the date
6435
+ * +n+ months later; +n+ should be a numeric:
6174
6436
  *
6175
- * Returns a date object pointing +n+ months after self.
6176
- * The argument +n+ should be a numeric value.
6437
+ * (Date.new(2001, 2, 3) >> 1).to_s # => "2001-03-03"
6438
+ * (Date.new(2001, 2, 3) >> -2).to_s # => "2000-12-03"
6177
6439
  *
6178
- * Date.new(2001,2,3) >> 1 #=> #<Date: 2001-03-03 ...>
6179
- * Date.new(2001,2,3) >> -2 #=> #<Date: 2000-12-03 ...>
6440
+ * When the same day does not exist for the new month,
6441
+ * the last day of that month is used instead:
6180
6442
  *
6181
- * When the same day does not exist for the corresponding month,
6182
- * the last day of the month is used instead:
6443
+ * (Date.new(2001, 1, 31) >> 1).to_s # => "2001-02-28"
6444
+ * (Date.new(2001, 1, 31) >> -4).to_s # => "2000-09-30"
6183
6445
  *
6184
- * Date.new(2001,1,28) >> 1 #=> #<Date: 2001-02-28 ...>
6185
- * Date.new(2001,1,31) >> 1 #=> #<Date: 2001-02-28 ...>
6446
+ * This results in the following, possibly unexpected, behaviors:
6186
6447
  *
6187
- * This also results in the following, possibly unexpected, behavior:
6448
+ * d0 = Date.new(2001, 1, 31)
6449
+ * d1 = d0 >> 1 # => #<Date: 2001-02-28>
6450
+ * d2 = d1 >> 1 # => #<Date: 2001-03-28>
6188
6451
  *
6189
- * Date.new(2001,1,31) >> 2 #=> #<Date: 2001-03-31 ...>
6190
- * Date.new(2001,1,31) >> 1 >> 1 #=> #<Date: 2001-03-28 ...>
6452
+ * d0 = Date.new(2001, 1, 31)
6453
+ * d1 = d0 >> 1 # => #<Date: 2001-02-28>
6454
+ * d2 = d1 >> -1 # => #<Date: 2001-01-28>
6191
6455
  *
6192
- * Date.new(2001,1,31) >> 1 >> -1 #=> #<Date: 2001-01-28 ...>
6193
6456
  */
6194
6457
  static VALUE
6195
6458
  d_lite_rshift(VALUE self, VALUE other)
@@ -6234,24 +6497,28 @@ d_lite_rshift(VALUE self, VALUE other)
6234
6497
  * call-seq:
6235
6498
  * d << n -> date
6236
6499
  *
6237
- * Returns a date object pointing +n+ months before self.
6238
- * The argument +n+ should be a numeric value.
6500
+ * Returns a new \Date object representing the date
6501
+ * +n+ months earlier; +n+ should be a numeric:
6239
6502
  *
6240
- * Date.new(2001,2,3) << 1 #=> #<Date: 2001-01-03 ...>
6241
- * Date.new(2001,2,3) << -2 #=> #<Date: 2001-04-03 ...>
6503
+ * (Date.new(2001, 2, 3) << 1).to_s # => "2001-01-03"
6504
+ * (Date.new(2001, 2, 3) << -2).to_s # => "2001-04-03"
6242
6505
  *
6243
- * When the same day does not exist for the corresponding month,
6244
- * the last day of the month is used instead:
6506
+ * When the same day does not exist for the new month,
6507
+ * the last day of that month is used instead:
6245
6508
  *
6246
- * Date.new(2001,3,28) << 1 #=> #<Date: 2001-02-28 ...>
6247
- * Date.new(2001,3,31) << 1 #=> #<Date: 2001-02-28 ...>
6509
+ * (Date.new(2001, 3, 31) << 1).to_s # => "2001-02-28"
6510
+ * (Date.new(2001, 3, 31) << -6).to_s # => "2001-09-30"
6248
6511
  *
6249
- * This also results in the following, possibly unexpected, behavior:
6512
+ * This results in the following, possibly unexpected, behaviors:
6250
6513
  *
6251
- * Date.new(2001,3,31) << 2 #=> #<Date: 2001-01-31 ...>
6252
- * Date.new(2001,3,31) << 1 << 1 #=> #<Date: 2001-01-28 ...>
6514
+ * d0 = Date.new(2001, 3, 31)
6515
+ * d0 << 2 # => #<Date: 2001-01-31>
6516
+ * d0 << 1 << 1 # => #<Date: 2001-01-28>
6517
+ *
6518
+ * d0 = Date.new(2001, 3, 31)
6519
+ * d1 = d0 << 1 # => #<Date: 2001-02-28>
6520
+ * d2 = d1 << -1 # => #<Date: 2001-03-28>
6253
6521
  *
6254
- * Date.new(2001,3,31) << 1 << -1 #=> #<Date: 2001-03-28 ...>
6255
6522
  */
6256
6523
  static VALUE
6257
6524
  d_lite_lshift(VALUE self, VALUE other)
@@ -6262,11 +6529,9 @@ d_lite_lshift(VALUE self, VALUE other)
6262
6529
 
6263
6530
  /*
6264
6531
  * call-seq:
6265
- * d.next_month([n=1]) -> date
6266
- *
6267
- * This method is equivalent to d >> n.
6532
+ * next_month(n = 1) -> new_date
6268
6533
  *
6269
- * See Date#>> for examples.
6534
+ * Equivalent to #>> with argument +n+.
6270
6535
  */
6271
6536
  static VALUE
6272
6537
  d_lite_next_month(int argc, VALUE *argv, VALUE self)
@@ -6281,11 +6546,9 @@ d_lite_next_month(int argc, VALUE *argv, VALUE self)
6281
6546
 
6282
6547
  /*
6283
6548
  * call-seq:
6284
- * d.prev_month([n=1]) -> date
6549
+ * prev_month(n = 1) -> new_date
6285
6550
  *
6286
- * This method is equivalent to d << n.
6287
- *
6288
- * See Date#<< for examples.
6551
+ * Equivalent to #<< with argument +n+.
6289
6552
  */
6290
6553
  static VALUE
6291
6554
  d_lite_prev_month(int argc, VALUE *argv, VALUE self)
@@ -6300,15 +6563,9 @@ d_lite_prev_month(int argc, VALUE *argv, VALUE self)
6300
6563
 
6301
6564
  /*
6302
6565
  * call-seq:
6303
- * d.next_year([n=1]) -> date
6304
- *
6305
- * This method is equivalent to d >> (n * 12).
6306
- *
6307
- * Date.new(2001,2,3).next_year #=> #<Date: 2002-02-03 ...>
6308
- * Date.new(2008,2,29).next_year #=> #<Date: 2009-02-28 ...>
6309
- * Date.new(2008,2,29).next_year(4) #=> #<Date: 2012-02-29 ...>
6566
+ * next_year(n = 1) -> new_date
6310
6567
  *
6311
- * See also Date#>>.
6568
+ * Equivalent to #>> with argument <tt>n * 12</tt>.
6312
6569
  */
6313
6570
  static VALUE
6314
6571
  d_lite_next_year(int argc, VALUE *argv, VALUE self)
@@ -6323,15 +6580,9 @@ d_lite_next_year(int argc, VALUE *argv, VALUE self)
6323
6580
 
6324
6581
  /*
6325
6582
  * call-seq:
6326
- * d.prev_year([n=1]) -> date
6327
- *
6328
- * This method is equivalent to d << (n * 12).
6329
- *
6330
- * Date.new(2001,2,3).prev_year #=> #<Date: 2000-02-03 ...>
6331
- * Date.new(2008,2,29).prev_year #=> #<Date: 2007-02-28 ...>
6332
- * Date.new(2008,2,29).prev_year(4) #=> #<Date: 2004-02-29 ...>
6583
+ * prev_year(n = 1) -> new_date
6333
6584
  *
6334
- * See also Date#<<.
6585
+ * Equivalent to #<< with argument <tt>n * 12</tt>.
6335
6586
  */
6336
6587
  static VALUE
6337
6588
  d_lite_prev_year(int argc, VALUE *argv, VALUE self)
@@ -6348,14 +6599,33 @@ static VALUE d_lite_cmp(VALUE, VALUE);
6348
6599
 
6349
6600
  /*
6350
6601
  * call-seq:
6351
- * d.step(limit[, step=1]) -> enumerator
6352
- * d.step(limit[, step=1]){|date| ...} -> self
6602
+ * step(limit, step = 1){|date| ... } -> self
6603
+ *
6604
+ * Calls the block with specified dates;
6605
+ * returns +self+.
6606
+ *
6607
+ * - The first +date+ is +self+.
6608
+ * - Each successive +date+ is <tt>date + step</tt>,
6609
+ * where +step+ is the numeric step size in days.
6610
+ * - The last date is the last one that is before or equal to +limit+,
6611
+ * which should be a \Date object.
6612
+ *
6613
+ * Example:
6614
+ *
6615
+ * limit = Date.new(2001, 12, 31)
6616
+ * Date.new(2001).step(limit){|date| p date.to_s if date.mday == 31 }
6353
6617
  *
6354
- * Iterates evaluation of the given block, which takes a date object.
6355
- * The limit should be a date object.
6618
+ * Output:
6356
6619
  *
6357
- * Date.new(2001).step(Date.new(2001,-1,-1)).select{|d| d.sunday?}.size
6358
- * #=> 52
6620
+ * "2001-01-31"
6621
+ * "2001-03-31"
6622
+ * "2001-05-31"
6623
+ * "2001-07-31"
6624
+ * "2001-08-31"
6625
+ * "2001-10-31"
6626
+ * "2001-12-31"
6627
+ *
6628
+ * Returns an Enumerator if no block is given.
6359
6629
  */
6360
6630
  static VALUE
6361
6631
  d_lite_step(int argc, VALUE *argv, VALUE self)
@@ -6398,10 +6668,9 @@ d_lite_step(int argc, VALUE *argv, VALUE self)
6398
6668
 
6399
6669
  /*
6400
6670
  * call-seq:
6401
- * d.upto(max) -> enumerator
6402
- * d.upto(max){|date| ...} -> self
6671
+ * upto(max){|date| ... } -> self
6403
6672
  *
6404
- * This method is equivalent to step(max, 1){|date| ...}.
6673
+ * Equivalent to #step with arguments +max+ and +1+.
6405
6674
  */
6406
6675
  static VALUE
6407
6676
  d_lite_upto(VALUE self, VALUE max)
@@ -6420,10 +6689,9 @@ d_lite_upto(VALUE self, VALUE max)
6420
6689
 
6421
6690
  /*
6422
6691
  * call-seq:
6423
- * d.downto(min) -> enumerator
6424
- * d.downto(min){|date| ...} -> self
6692
+ * downto(min){|date| ... } -> self
6425
6693
  *
6426
- * This method is equivalent to step(min, -1){|date| ...}.
6694
+ * Equivalent to #step with arguments +min+ and <tt>-1</tt>.
6427
6695
  */
6428
6696
  static VALUE
6429
6697
  d_lite_downto(VALUE self, VALUE min)
@@ -6511,19 +6779,43 @@ cmp_dd(VALUE self, VALUE other)
6511
6779
 
6512
6780
  /*
6513
6781
  * call-seq:
6514
- * d <=> other -> -1, 0, +1 or nil
6782
+ * self <=> other -> -1, 0, 1 or nil
6783
+ *
6784
+ * Compares +self+ and +other+, returning:
6785
+ *
6786
+ * - <tt>-1</tt> if +other+ is larger.
6787
+ * - <tt>0</tt> if the two are equal.
6788
+ * - <tt>1</tt> if +other+ is smaller.
6789
+ * - +nil+ if the two are incomparable.
6790
+ *
6791
+ * Argument +other+ may be:
6792
+ *
6793
+ * - Another \Date object:
6794
+ *
6795
+ * d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
6796
+ * prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
6797
+ * next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
6798
+ * d <=> next_date # => -1
6799
+ * d <=> d # => 0
6800
+ * d <=> prev_date # => 1
6801
+ *
6802
+ * - A DateTime object:
6803
+ *
6804
+ * d <=> DateTime.new(2022, 7, 26) # => 1
6805
+ * d <=> DateTime.new(2022, 7, 27) # => 0
6806
+ * d <=> DateTime.new(2022, 7, 28) # => -1
6807
+ *
6808
+ * - A numeric (compares <tt>self.ajd</tt> to +other+):
6515
6809
  *
6516
- * Compares the two dates and returns -1, zero, 1 or nil. The other
6517
- * should be a date object or a numeric value as an astronomical
6518
- * Julian day number.
6810
+ * d <=> 2459788 # => -1
6811
+ * d <=> 2459787 # => 1
6812
+ * d <=> 2459786 # => 1
6813
+ * d <=> d.ajd # => 0
6519
6814
  *
6520
- * Date.new(2001,2,3) <=> Date.new(2001,2,4) #=> -1
6521
- * Date.new(2001,2,3) <=> Date.new(2001,2,3) #=> 0
6522
- * Date.new(2001,2,3) <=> Date.new(2001,2,2) #=> 1
6523
- * Date.new(2001,2,3) <=> Object.new #=> nil
6524
- * Date.new(2001,2,3) <=> Rational(4903887,2) #=> 0
6815
+ * - Any other object:
6816
+ *
6817
+ * d <=> Object.new # => nil
6525
6818
  *
6526
- * See also Comparable.
6527
6819
  */
6528
6820
  static VALUE
6529
6821
  d_lite_cmp(VALUE self, VALUE other)
@@ -6583,20 +6875,39 @@ equal_gen(VALUE self, VALUE other)
6583
6875
 
6584
6876
  /*
6585
6877
  * call-seq:
6586
- * d === other -> bool
6587
- *
6588
- * Returns true if they are the same day.
6589
- *
6590
- * Date.new(2001,2,3) === Date.new(2001,2,3)
6591
- * #=> true
6592
- * Date.new(2001,2,3) === Date.new(2001,2,4)
6593
- * #=> false
6594
- * DateTime.new(2001,2,3) === DateTime.new(2001,2,3,12)
6595
- * #=> true
6596
- * DateTime.new(2001,2,3) === DateTime.new(2001,2,3,0,0,0,'+24:00')
6597
- * #=> true
6598
- * DateTime.new(2001,2,3) === DateTime.new(2001,2,4,0,0,0,'+24:00')
6599
- * #=> false
6878
+ * self === other -> true, false, or nil.
6879
+ *
6880
+ * Returns +true+ if +self+ and +other+ represent the same date,
6881
+ * +false+ if not, +nil+ if the two are not comparable.
6882
+ *
6883
+ * Argument +other+ may be:
6884
+ *
6885
+ * - Another \Date object:
6886
+ *
6887
+ * d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
6888
+ * prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
6889
+ * next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
6890
+ * d === prev_date # => false
6891
+ * d === d # => true
6892
+ * d === next_date # => false
6893
+ *
6894
+ * - A DateTime object:
6895
+ *
6896
+ * d === DateTime.new(2022, 7, 26) # => false
6897
+ * d === DateTime.new(2022, 7, 27) # => true
6898
+ * d === DateTime.new(2022, 7, 28) # => false
6899
+ *
6900
+ * - A numeric (compares <tt>self.jd</tt> to +other+):
6901
+ *
6902
+ * d === 2459788 # => true
6903
+ * d === 2459787 # => false
6904
+ * d === 2459786 # => false
6905
+ * d === d.jd # => true
6906
+ *
6907
+ * - An object not comparable:
6908
+ *
6909
+ * d === Object.new # => nil
6910
+ *
6600
6911
  */
6601
6912
  static VALUE
6602
6913
  d_lite_equal(VALUE self, VALUE other)
@@ -6659,12 +6970,14 @@ static VALUE strftimev(const char *, VALUE,
6659
6970
 
6660
6971
  /*
6661
6972
  * call-seq:
6662
- * d.to_s -> string
6973
+ * to_s -> string
6663
6974
  *
6664
- * Returns a string in an ISO 8601 format. (This method doesn't use the
6665
- * expanded representations.)
6975
+ * Returns a string representation of the date in +self+
6976
+ * in {ISO 8601 extended date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]
6977
+ * (<tt>'%Y-%m-%d'</tt>):
6978
+ *
6979
+ * Date.new(2001, 2, 3).to_s # => "2001-02-03"
6666
6980
  *
6667
- * Date.new(2001,2,3).to_s #=> "2001-02-03"
6668
6981
  */
6669
6982
  static VALUE
6670
6983
  d_lite_to_s(VALUE self)
@@ -6673,6 +6986,7 @@ d_lite_to_s(VALUE self)
6673
6986
  }
6674
6987
 
6675
6988
  #ifndef NDEBUG
6989
+ /* :nodoc: */
6676
6990
  static VALUE
6677
6991
  mk_inspect_raw(union DateData *x, VALUE klass)
6678
6992
  {
@@ -6722,6 +7036,7 @@ mk_inspect_raw(union DateData *x, VALUE klass)
6722
7036
  }
6723
7037
  }
6724
7038
 
7039
+ /* :nodoc: */
6725
7040
  static VALUE
6726
7041
  d_lite_inspect_raw(VALUE self)
6727
7042
  {
@@ -6743,14 +7058,13 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
6743
7058
 
6744
7059
  /*
6745
7060
  * call-seq:
6746
- * d.inspect -> string
7061
+ * inspect -> string
7062
+ *
7063
+ * Returns a string representation of +self+:
6747
7064
  *
6748
- * Returns the value as a string for inspection.
7065
+ * Date.new(2001, 2, 3).inspect
7066
+ * # => "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>"
6749
7067
  *
6750
- * Date.new(2001,2,3).inspect
6751
- * #=> "#<Date: 2001-02-03>"
6752
- * DateTime.new(2001,2,3,4,5,6,'-7').inspect
6753
- * #=> "#<DateTime: 2001-02-03T04:05:06-07:00>"
6754
7068
  */
6755
7069
  static VALUE
6756
7070
  d_lite_inspect(VALUE self)
@@ -6932,180 +7246,16 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
6932
7246
 
6933
7247
  /*
6934
7248
  * call-seq:
6935
- * d.strftime([format='%F']) -> string
6936
- *
6937
- * Formats date according to the directives in the given format
6938
- * string.
6939
- * The directives begin with a percent (%) character.
6940
- * Any text not listed as a directive will be passed through to the
6941
- * output string.
6942
- *
6943
- * A directive consists of a percent (%) character,
6944
- * zero or more flags, an optional minimum field width,
6945
- * an optional modifier, and a conversion specifier
6946
- * as follows.
6947
- *
6948
- * %<flags><width><modifier><conversion>
6949
- *
6950
- * Flags:
6951
- * - don't pad a numerical output.
6952
- * _ use spaces for padding.
6953
- * 0 use zeros for padding.
6954
- * ^ upcase the result string.
6955
- * # change case.
6956
- *
6957
- * The minimum field width specifies the minimum width.
6958
- *
6959
- * The modifiers are "E", "O", ":", "::" and ":::".
6960
- * "E" and "O" are ignored. No effect to result currently.
6961
- *
6962
- * Format directives:
6963
- *
6964
- * Date (Year, Month, Day):
6965
- * %Y - Year with century (can be negative, 4 digits at least)
6966
- * -0001, 0000, 1995, 2009, 14292, etc.
6967
- * %C - year / 100 (round down. 20 in 2009)
6968
- * %y - year % 100 (00..99)
6969
- *
6970
- * %m - Month of the year, zero-padded (01..12)
6971
- * %_m blank-padded ( 1..12)
6972
- * %-m no-padded (1..12)
6973
- * %B - The full month name (``January'')
6974
- * %^B uppercased (``JANUARY'')
6975
- * %b - The abbreviated month name (``Jan'')
6976
- * %^b uppercased (``JAN'')
6977
- * %h - Equivalent to %b
6978
- *
6979
- * %d - Day of the month, zero-padded (01..31)
6980
- * %-d no-padded (1..31)
6981
- * %e - Day of the month, blank-padded ( 1..31)
6982
- *
6983
- * %j - Day of the year (001..366)
6984
- *
6985
- * Time (Hour, Minute, Second, Subsecond):
6986
- * %H - Hour of the day, 24-hour clock, zero-padded (00..23)
6987
- * %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
6988
- * %I - Hour of the day, 12-hour clock, zero-padded (01..12)
6989
- * %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
6990
- * %P - Meridian indicator, lowercase (``am'' or ``pm'')
6991
- * %p - Meridian indicator, uppercase (``AM'' or ``PM'')
6992
- *
6993
- * %M - Minute of the hour (00..59)
6994
- *
6995
- * %S - Second of the minute (00..60)
6996
- *
6997
- * %L - Millisecond of the second (000..999)
6998
- * %N - Fractional seconds digits, default is 9 digits (nanosecond)
6999
- * %3N millisecond (3 digits) %15N femtosecond (15 digits)
7000
- * %6N microsecond (6 digits) %18N attosecond (18 digits)
7001
- * %9N nanosecond (9 digits) %21N zeptosecond (21 digits)
7002
- * %12N picosecond (12 digits) %24N yoctosecond (24 digits)
7003
- *
7004
- * Time zone:
7005
- * %z - Time zone as hour and minute offset from UTC (e.g. +0900)
7006
- * %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
7007
- * %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
7008
- * %:::z - hour, minute and second offset from UTC
7009
- * (e.g. +09, +09:30, +09:30:30)
7010
- * %Z - Equivalent to %:z (e.g. +09:00)
7011
- *
7012
- * Weekday:
7013
- * %A - The full weekday name (``Sunday'')
7014
- * %^A uppercased (``SUNDAY'')
7015
- * %a - The abbreviated name (``Sun'')
7016
- * %^a uppercased (``SUN'')
7017
- * %u - Day of the week (Monday is 1, 1..7)
7018
- * %w - Day of the week (Sunday is 0, 0..6)
7019
- *
7020
- * ISO 8601 week-based year and week number:
7021
- * The week 1 of YYYY starts with a Monday and includes YYYY-01-04.
7022
- * The days in the year before the first week are in the last week of
7023
- * the previous year.
7024
- * %G - The week-based year
7025
- * %g - The last 2 digits of the week-based year (00..99)
7026
- * %V - Week number of the week-based year (01..53)
7027
- *
7028
- * Week number:
7029
- * The week 1 of YYYY starts with a Sunday or Monday (according to %U
7030
- * or %W). The days in the year before the first week are in week 0.
7031
- * %U - Week number of the year. The week starts with Sunday. (00..53)
7032
- * %W - Week number of the year. The week starts with Monday. (00..53)
7033
- *
7034
- * Seconds since the Unix Epoch:
7035
- * %s - Number of seconds since 1970-01-01 00:00:00 UTC.
7036
- * %Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
7037
- *
7038
- * Literal string:
7039
- * %n - Newline character (\n)
7040
- * %t - Tab character (\t)
7041
- * %% - Literal ``%'' character
7042
- *
7043
- * Combination:
7044
- * %c - date and time (%a %b %e %T %Y)
7045
- * %D - Date (%m/%d/%y)
7046
- * %F - The ISO 8601 date format (%Y-%m-%d)
7047
- * %v - VMS date (%e-%^b-%Y)
7048
- * %x - Same as %D
7049
- * %X - Same as %T
7050
- * %r - 12-hour time (%I:%M:%S %p)
7051
- * %R - 24-hour time (%H:%M)
7052
- * %T - 24-hour time (%H:%M:%S)
7053
- * %+ - date(1) (%a %b %e %H:%M:%S %Z %Y)
7054
- *
7055
- * This method is similar to the strftime() function defined in ISO C
7056
- * and POSIX.
7057
- * Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z)
7058
- * are locale dependent in the function.
7059
- * However, this method is locale independent.
7060
- * So, the result may differ even if the same format string is used in other
7061
- * systems such as C.
7062
- * It is good practice to avoid %x and %X because there are corresponding
7063
- * locale independent representations, %D and %T.
7064
- *
7065
- * Examples:
7066
- *
7067
- * d = DateTime.new(2007,11,19,8,37,48,"-06:00")
7068
- * #=> #<DateTime: 2007-11-19T08:37:48-0600 ...>
7069
- * d.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
7070
- * d.strftime("at %I:%M%p") #=> "at 08:37AM"
7071
- *
7072
- * Various ISO 8601 formats:
7073
- * %Y%m%d => 20071119 Calendar date (basic)
7074
- * %F => 2007-11-19 Calendar date (extended)
7075
- * %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
7076
- * %Y => 2007 Calendar date, reduced accuracy, specific year
7077
- * %C => 20 Calendar date, reduced accuracy, specific century
7078
- * %Y%j => 2007323 Ordinal date (basic)
7079
- * %Y-%j => 2007-323 Ordinal date (extended)
7080
- * %GW%V%u => 2007W471 Week date (basic)
7081
- * %G-W%V-%u => 2007-W47-1 Week date (extended)
7082
- * %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
7083
- * %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
7084
- * %H%M%S => 083748 Local time (basic)
7085
- * %T => 08:37:48 Local time (extended)
7086
- * %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
7087
- * %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
7088
- * %H => 08 Local time, reduced accuracy, specific hour
7089
- * %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
7090
- * %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
7091
- * %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
7092
- * %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
7093
- * %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
7094
- * %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
7095
- * %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
7096
- * %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
7097
- * %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
7098
- * %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
7099
- * %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
7100
- * %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
7101
- * %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
7102
- * %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
7103
- * %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
7104
- * %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
7105
- * %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
7106
- * %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
7107
- *
7108
- * See also strftime(3) and ::strptime.
7249
+ * strftime(format = '%F') -> string
7250
+ *
7251
+ * Returns a string representation of the date in +self+,
7252
+ * formatted according the given +format+:
7253
+ *
7254
+ * Date.new(2001, 2, 3).strftime # => "2001-02-03"
7255
+ *
7256
+ * For other formats, see
7257
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
7258
+ *
7109
7259
  */
7110
7260
  static VALUE
7111
7261
  d_lite_strftime(int argc, VALUE *argv, VALUE self)
@@ -7133,13 +7283,17 @@ strftimev(const char *fmt, VALUE self,
7133
7283
 
7134
7284
  /*
7135
7285
  * call-seq:
7136
- * d.asctime -> string
7137
- * d.ctime -> string
7286
+ * asctime -> string
7287
+ *
7288
+ * Equivalent to #strftime with argument <tt>'%a %b %e %T %Y'</tt>
7289
+ * (or its {shorthand form}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Shorthand+Conversion+Specifiers]
7290
+ * <tt>'%c'</tt>):
7138
7291
  *
7139
- * Returns a string in asctime(3) format (but without "\n\0" at the
7140
- * end). This method is equivalent to strftime('%c').
7292
+ * Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
7141
7293
  *
7142
- * See also asctime(3) or ctime(3).
7294
+ * See {asctime}[https://linux.die.net/man/3/asctime].
7295
+ *
7296
+ * Date#ctime is an alias for Date#asctime.
7143
7297
  */
7144
7298
  static VALUE
7145
7299
  d_lite_asctime(VALUE self)
@@ -7149,10 +7303,15 @@ d_lite_asctime(VALUE self)
7149
7303
 
7150
7304
  /*
7151
7305
  * call-seq:
7152
- * d.iso8601 -> string
7153
- * d.xmlschema -> string
7306
+ * iso8601 -> string
7307
+ *
7308
+ * Equivalent to #strftime with argument <tt>'%Y-%m-%d'</tt>
7309
+ * (or its {shorthand form}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Shorthand+Conversion+Specifiers]
7310
+ * <tt>'%F'</tt>);
7311
+ *
7312
+ * Date.new(2001, 2, 3).iso8601 # => "2001-02-03"
7154
7313
  *
7155
- * This method is equivalent to strftime('%F').
7314
+ * Date#xmlschema is an alias for Date#iso8601.
7156
7315
  */
7157
7316
  static VALUE
7158
7317
  d_lite_iso8601(VALUE self)
@@ -7162,9 +7321,13 @@ d_lite_iso8601(VALUE self)
7162
7321
 
7163
7322
  /*
7164
7323
  * call-seq:
7165
- * d.rfc3339 -> string
7324
+ * rfc3339 -> string
7325
+ *
7326
+ * Equivalent to #strftime with argument <tt>'%FT%T%:z'</tt>;
7327
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7328
+ *
7329
+ * Date.new(2001, 2, 3).rfc3339 # => "2001-02-03T00:00:00+00:00"
7166
7330
  *
7167
- * This method is equivalent to strftime('%FT%T%:z').
7168
7331
  */
7169
7332
  static VALUE
7170
7333
  d_lite_rfc3339(VALUE self)
@@ -7174,10 +7337,14 @@ d_lite_rfc3339(VALUE self)
7174
7337
 
7175
7338
  /*
7176
7339
  * call-seq:
7177
- * d.rfc2822 -> string
7178
- * d.rfc822 -> string
7340
+ * rfc2822 -> string
7341
+ *
7342
+ * Equivalent to #strftime with argument <tt>'%a, %-d %b %Y %T %z'</tt>;
7343
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7344
+ *
7345
+ * Date.new(2001, 2, 3).rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
7179
7346
  *
7180
- * This method is equivalent to strftime('%a, %-d %b %Y %T %z').
7347
+ * Date#rfc822 is an alias for Date#rfc2822.
7181
7348
  */
7182
7349
  static VALUE
7183
7350
  d_lite_rfc2822(VALUE self)
@@ -7187,10 +7354,13 @@ d_lite_rfc2822(VALUE self)
7187
7354
 
7188
7355
  /*
7189
7356
  * call-seq:
7190
- * d.httpdate -> string
7357
+ * httpdate -> string
7358
+ *
7359
+ * Equivalent to #strftime with argument <tt>'%a, %d %b %Y %T GMT'</tt>;
7360
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7361
+ *
7362
+ * Date.new(2001, 2, 3).httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
7191
7363
  *
7192
- * This method is equivalent to strftime('%a, %d %b %Y %T GMT').
7193
- * See also RFC 2616.
7194
7364
  */
7195
7365
  static VALUE
7196
7366
  d_lite_httpdate(VALUE self)
@@ -7241,11 +7411,13 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y)
7241
7411
 
7242
7412
  /*
7243
7413
  * call-seq:
7244
- * d.jisx0301 -> string
7414
+ * jisx0301 -> string
7245
7415
  *
7246
- * Returns a string in a JIS X 0301 format.
7416
+ * Returns a string representation of the date in +self+
7417
+ * in JIS X 0301 format.
7418
+ *
7419
+ * Date.new(2001, 2, 3).jisx0301 # => "H13.02.03"
7247
7420
  *
7248
- * Date.new(2001,2,3).jisx0301 #=> "H13.02.03"
7249
7421
  */
7250
7422
  static VALUE
7251
7423
  d_lite_jisx0301(VALUE self)
@@ -7261,6 +7433,7 @@ d_lite_jisx0301(VALUE self)
7261
7433
  }
7262
7434
 
7263
7435
  #ifndef NDEBUG
7436
+ /* :nodoc: */
7264
7437
  static VALUE
7265
7438
  d_lite_marshal_dump_old(VALUE self)
7266
7439
  {
@@ -7548,17 +7721,7 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
7548
7721
  }
7549
7722
 
7550
7723
  /*
7551
- * call-seq:
7552
- * DateTime.civil([year=-4712[, month=1[, mday=1[, hour=0[, minute=0[, second=0[, offset=0[, start=Date::ITALY]]]]]]]]) -> datetime
7553
- * DateTime.new([year=-4712[, month=1[, mday=1[, hour=0[, minute=0[, second=0[, offset=0[, start=Date::ITALY]]]]]]]]) -> datetime
7554
- *
7555
- * Creates a DateTime object denoting the given calendar date.
7556
- *
7557
- * DateTime.new(2001,2,3) #=> #<DateTime: 2001-02-03T00:00:00+00:00 ...>
7558
- * DateTime.new(2001,2,3,4,5,6,'+7')
7559
- * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
7560
- * DateTime.new(2001,-11,-26,-20,-55,-54,'+7')
7561
- * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
7724
+ * Same as DateTime.new.
7562
7725
  */
7563
7726
  static VALUE
7564
7727
  datetime_s_civil(int argc, VALUE *argv, VALUE klass)
@@ -7748,6 +7911,7 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
7748
7911
  }
7749
7912
 
7750
7913
  #ifndef NDEBUG
7914
+ /* :nodoc: */
7751
7915
  static VALUE
7752
7916
  datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
7753
7917
  {
@@ -7817,6 +7981,7 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
7817
7981
  return ret;
7818
7982
  }
7819
7983
 
7984
+ /* :nodoc: */
7820
7985
  static VALUE
7821
7986
  datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
7822
7987
  {
@@ -8162,9 +8327,9 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8162
8327
  * Parses the given representation of date and time, and creates a
8163
8328
  * DateTime object.
8164
8329
  *
8165
- * This method *does not* function as a validator. If the input
8330
+ * This method *does* *not* function as a validator. If the input
8166
8331
  * string does not match valid formats strictly, you may get a cryptic
8167
- * result. Should consider to use `DateTime.strptime` instead of this
8332
+ * result. Should consider to use DateTime.strptime instead of this
8168
8333
  * method as possible.
8169
8334
  *
8170
8335
  * If the optional second argument is true and the detected year is in
@@ -8178,8 +8343,8 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8178
8343
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8179
8344
  *
8180
8345
  * Raise an ArgumentError when the string length is longer than _limit_.
8181
- * You can stop this check by passing `limit: nil`, but note that
8182
- * it may take a long time to parse.
8346
+ * You can stop this check by passing <code>limit: nil</code>, but note
8347
+ * that it may take a long time to parse.
8183
8348
  */
8184
8349
  static VALUE
8185
8350
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
@@ -8200,12 +8365,12 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8200
8365
 
8201
8366
  {
8202
8367
  int argc2 = 2;
8203
- VALUE argv2[3];
8368
+ VALUE argv2[3], hash;
8204
8369
  argv2[0] = str;
8205
8370
  argv2[1] = comp;
8206
8371
  argv2[2] = opt;
8207
8372
  if (!NIL_P(opt)) argc2++;
8208
- VALUE hash = date_s__parse(argc2, argv2, klass);
8373
+ hash = date_s__parse(argc2, argv2, klass);
8209
8374
  return dt_new_by_frags(klass, hash, sg);
8210
8375
  }
8211
8376
  }
@@ -8225,8 +8390,8 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8225
8390
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8226
8391
  *
8227
8392
  * Raise an ArgumentError when the string length is longer than _limit_.
8228
- * You can stop this check by passing `limit: nil`, but note that
8229
- * it may take a long time to parse.
8393
+ * You can stop this check by passing <code>limit: nil</code>, but note
8394
+ * that it may take a long time to parse.
8230
8395
  */
8231
8396
  static VALUE
8232
8397
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
@@ -8245,11 +8410,11 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8245
8410
 
8246
8411
  {
8247
8412
  int argc2 = 1;
8248
- VALUE argv2[2];
8413
+ VALUE argv2[2], hash;
8249
8414
  argv2[0] = str;
8250
8415
  argv2[1] = opt;
8251
8416
  if (!NIL_P(opt)) argc2--;
8252
- VALUE hash = date_s__iso8601(argc2, argv2, klass);
8417
+ hash = date_s__iso8601(argc2, argv2, klass);
8253
8418
  return dt_new_by_frags(klass, hash, sg);
8254
8419
  }
8255
8420
  }
@@ -8265,8 +8430,8 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8265
8430
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8266
8431
  *
8267
8432
  * Raise an ArgumentError when the string length is longer than _limit_.
8268
- * You can stop this check by passing `limit: nil`, but note that
8269
- * it may take a long time to parse.
8433
+ * You can stop this check by passing <code>limit: nil</code>, but note
8434
+ * that it may take a long time to parse.
8270
8435
  */
8271
8436
  static VALUE
8272
8437
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -8285,11 +8450,11 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8285
8450
 
8286
8451
  {
8287
8452
  int argc2 = 1;
8288
- VALUE argv2[2];
8453
+ VALUE argv2[2], hash;
8289
8454
  argv2[0] = str;
8290
8455
  argv2[1] = opt;
8291
8456
  if (!NIL_P(opt)) argc2++;
8292
- VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8457
+ hash = date_s__rfc3339(argc2, argv2, klass);
8293
8458
  return dt_new_by_frags(klass, hash, sg);
8294
8459
  }
8295
8460
  }
@@ -8305,8 +8470,8 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8305
8470
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8306
8471
  *
8307
8472
  * Raise an ArgumentError when the string length is longer than _limit_.
8308
- * You can stop this check by passing `limit: nil`, but note that
8309
- * it may take a long time to parse.
8473
+ * You can stop this check by passing <code>limit: nil</code>, but note
8474
+ * that it may take a long time to parse.
8310
8475
  */
8311
8476
  static VALUE
8312
8477
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -8325,11 +8490,11 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8325
8490
 
8326
8491
  {
8327
8492
  int argc2 = 1;
8328
- VALUE argv2[2];
8493
+ VALUE argv2[2], hash;
8329
8494
  argv2[0] = str;
8330
8495
  argv2[1] = opt;
8331
8496
  if (!NIL_P(opt)) argc2++;
8332
- VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8497
+ hash = date_s__xmlschema(argc2, argv2, klass);
8333
8498
  return dt_new_by_frags(klass, hash, sg);
8334
8499
  }
8335
8500
  }
@@ -8346,8 +8511,8 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8346
8511
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8347
8512
  *
8348
8513
  * Raise an ArgumentError when the string length is longer than _limit_.
8349
- * You can stop this check by passing `limit: nil`, but note that
8350
- * it may take a long time to parse.
8514
+ * You can stop this check by passing <code>limit: nil</code>, but note
8515
+ * that it may take a long time to parse.
8351
8516
  */
8352
8517
  static VALUE
8353
8518
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -8366,11 +8531,11 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8366
8531
 
8367
8532
  {
8368
8533
  int argc2 = 1;
8369
- VALUE argv2[2];
8534
+ VALUE argv2[2], hash;
8370
8535
  argv2[0] = str;
8371
8536
  argv2[1] = opt;
8372
8537
  if (!NIL_P(opt)) argc2++;
8373
- VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8538
+ hash = date_s__rfc2822(argc2, argv2, klass);
8374
8539
  return dt_new_by_frags(klass, hash, sg);
8375
8540
  }
8376
8541
  }
@@ -8386,8 +8551,8 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8386
8551
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8387
8552
  *
8388
8553
  * Raise an ArgumentError when the string length is longer than _limit_.
8389
- * You can stop this check by passing `limit: nil`, but note that
8390
- * it may take a long time to parse.
8554
+ * You can stop this check by passing <code>limit: nil</code>, but note
8555
+ * that it may take a long time to parse.
8391
8556
  */
8392
8557
  static VALUE
8393
8558
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
@@ -8406,11 +8571,11 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8406
8571
 
8407
8572
  {
8408
8573
  int argc2 = 1;
8409
- VALUE argv2[2];
8574
+ VALUE argv2[2], hash;
8410
8575
  argv2[0] = str;
8411
8576
  argv2[1] = opt;
8412
8577
  if (!NIL_P(opt)) argc2++;
8413
- VALUE hash = date_s__httpdate(argc2, argv2, klass);
8578
+ hash = date_s__httpdate(argc2, argv2, klass);
8414
8579
  return dt_new_by_frags(klass, hash, sg);
8415
8580
  }
8416
8581
  }
@@ -8431,8 +8596,8 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8431
8596
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8432
8597
  *
8433
8598
  * Raise an ArgumentError when the string length is longer than _limit_.
8434
- * You can stop this check by passing `limit: nil`, but note that
8435
- * it may take a long time to parse.
8599
+ * You can stop this check by passing <code>limit: nil</code>, but note
8600
+ * that it may take a long time to parse.
8436
8601
  */
8437
8602
  static VALUE
8438
8603
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -8451,11 +8616,11 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8451
8616
 
8452
8617
  {
8453
8618
  int argc2 = 1;
8454
- VALUE argv2[2];
8619
+ VALUE argv2[2], hash;
8455
8620
  argv2[0] = str;
8456
8621
  argv2[1] = opt;
8457
8622
  if (!NIL_P(opt)) argc2++;
8458
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8623
+ hash = date_s__jisx0301(argc2, argv2, klass);
8459
8624
  return dt_new_by_frags(klass, hash, sg);
8460
8625
  }
8461
8626
  }
@@ -8478,181 +8643,16 @@ dt_lite_to_s(VALUE self)
8478
8643
 
8479
8644
  /*
8480
8645
  * call-seq:
8481
- * dt.strftime([format='%FT%T%:z']) -> string
8482
- *
8483
- * Formats date according to the directives in the given format
8484
- * string.
8485
- * The directives begin with a percent (%) character.
8486
- * Any text not listed as a directive will be passed through to the
8487
- * output string.
8488
- *
8489
- * A directive consists of a percent (%) character,
8490
- * zero or more flags, an optional minimum field width,
8491
- * an optional modifier, and a conversion specifier
8492
- * as follows.
8493
- *
8494
- * %<flags><width><modifier><conversion>
8495
- *
8496
- * Flags:
8497
- * - don't pad a numerical output.
8498
- * _ use spaces for padding.
8499
- * 0 use zeros for padding.
8500
- * ^ upcase the result string.
8501
- * # change case.
8502
- * : use colons for %z.
8503
- *
8504
- * The minimum field width specifies the minimum width.
8505
- *
8506
- * The modifiers are "E" and "O".
8507
- * They are ignored.
8508
- *
8509
- * Format directives:
8510
- *
8511
- * Date (Year, Month, Day):
8512
- * %Y - Year with century (can be negative, 4 digits at least)
8513
- * -0001, 0000, 1995, 2009, 14292, etc.
8514
- * %C - year / 100 (round down. 20 in 2009)
8515
- * %y - year % 100 (00..99)
8516
- *
8517
- * %m - Month of the year, zero-padded (01..12)
8518
- * %_m blank-padded ( 1..12)
8519
- * %-m no-padded (1..12)
8520
- * %B - The full month name (``January'')
8521
- * %^B uppercased (``JANUARY'')
8522
- * %b - The abbreviated month name (``Jan'')
8523
- * %^b uppercased (``JAN'')
8524
- * %h - Equivalent to %b
8525
- *
8526
- * %d - Day of the month, zero-padded (01..31)
8527
- * %-d no-padded (1..31)
8528
- * %e - Day of the month, blank-padded ( 1..31)
8529
- *
8530
- * %j - Day of the year (001..366)
8531
- *
8532
- * Time (Hour, Minute, Second, Subsecond):
8533
- * %H - Hour of the day, 24-hour clock, zero-padded (00..23)
8534
- * %k - Hour of the day, 24-hour clock, blank-padded ( 0..23)
8535
- * %I - Hour of the day, 12-hour clock, zero-padded (01..12)
8536
- * %l - Hour of the day, 12-hour clock, blank-padded ( 1..12)
8537
- * %P - Meridian indicator, lowercase (``am'' or ``pm'')
8538
- * %p - Meridian indicator, uppercase (``AM'' or ``PM'')
8539
- *
8540
- * %M - Minute of the hour (00..59)
8541
- *
8542
- * %S - Second of the minute (00..60)
8543
- *
8544
- * %L - Millisecond of the second (000..999)
8545
- * %N - Fractional seconds digits, default is 9 digits (nanosecond)
8546
- * %3N millisecond (3 digits) %15N femtosecond (15 digits)
8547
- * %6N microsecond (6 digits) %18N attosecond (18 digits)
8548
- * %9N nanosecond (9 digits) %21N zeptosecond (21 digits)
8549
- * %12N picosecond (12 digits) %24N yoctosecond (24 digits)
8550
- *
8551
- * Time zone:
8552
- * %z - Time zone as hour and minute offset from UTC (e.g. +0900)
8553
- * %:z - hour and minute offset from UTC with a colon (e.g. +09:00)
8554
- * %::z - hour, minute and second offset from UTC (e.g. +09:00:00)
8555
- * %:::z - hour, minute and second offset from UTC
8556
- * (e.g. +09, +09:30, +09:30:30)
8557
- * %Z - Equivalent to %:z (e.g. +09:00)
8558
- *
8559
- * Weekday:
8560
- * %A - The full weekday name (``Sunday'')
8561
- * %^A uppercased (``SUNDAY'')
8562
- * %a - The abbreviated name (``Sun'')
8563
- * %^a uppercased (``SUN'')
8564
- * %u - Day of the week (Monday is 1, 1..7)
8565
- * %w - Day of the week (Sunday is 0, 0..6)
8566
- *
8567
- * ISO 8601 week-based year and week number:
8568
- * The week 1 of YYYY starts with a Monday and includes YYYY-01-04.
8569
- * The days in the year before the first week are in the last week of
8570
- * the previous year.
8571
- * %G - The week-based year
8572
- * %g - The last 2 digits of the week-based year (00..99)
8573
- * %V - Week number of the week-based year (01..53)
8574
- *
8575
- * Week number:
8576
- * The week 1 of YYYY starts with a Sunday or Monday (according to %U
8577
- * or %W). The days in the year before the first week are in week 0.
8578
- * %U - Week number of the year. The week starts with Sunday. (00..53)
8579
- * %W - Week number of the year. The week starts with Monday. (00..53)
8580
- *
8581
- * Seconds since the Unix Epoch:
8582
- * %s - Number of seconds since 1970-01-01 00:00:00 UTC.
8583
- * %Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
8584
- *
8585
- * Literal string:
8586
- * %n - Newline character (\n)
8587
- * %t - Tab character (\t)
8588
- * %% - Literal ``%'' character
8589
- *
8590
- * Combination:
8591
- * %c - date and time (%a %b %e %T %Y)
8592
- * %D - Date (%m/%d/%y)
8593
- * %F - The ISO 8601 date format (%Y-%m-%d)
8594
- * %v - VMS date (%e-%^b-%Y)
8595
- * %x - Same as %D
8596
- * %X - Same as %T
8597
- * %r - 12-hour time (%I:%M:%S %p)
8598
- * %R - 24-hour time (%H:%M)
8599
- * %T - 24-hour time (%H:%M:%S)
8600
- * %+ - date(1) (%a %b %e %H:%M:%S %Z %Y)
8601
- *
8602
- * This method is similar to the strftime() function defined in ISO C
8603
- * and POSIX.
8604
- * Several directives (%a, %A, %b, %B, %c, %p, %r, %x, %X, %E*, %O* and %Z)
8605
- * are locale dependent in the function.
8606
- * However, this method is locale independent.
8607
- * So, the result may differ even if the same format string is used in other
8608
- * systems such as C.
8609
- * It is good practice to avoid %x and %X because there are corresponding
8610
- * locale independent representations, %D and %T.
8611
- *
8612
- * Examples:
8613
- *
8614
- * d = DateTime.new(2007,11,19,8,37,48,"-06:00")
8615
- * #=> #<DateTime: 2007-11-19T08:37:48-0600 ...>
8616
- * d.strftime("Printed on %m/%d/%Y") #=> "Printed on 11/19/2007"
8617
- * d.strftime("at %I:%M%p") #=> "at 08:37AM"
8618
- *
8619
- * Various ISO 8601 formats:
8620
- * %Y%m%d => 20071119 Calendar date (basic)
8621
- * %F => 2007-11-19 Calendar date (extended)
8622
- * %Y-%m => 2007-11 Calendar date, reduced accuracy, specific month
8623
- * %Y => 2007 Calendar date, reduced accuracy, specific year
8624
- * %C => 20 Calendar date, reduced accuracy, specific century
8625
- * %Y%j => 2007323 Ordinal date (basic)
8626
- * %Y-%j => 2007-323 Ordinal date (extended)
8627
- * %GW%V%u => 2007W471 Week date (basic)
8628
- * %G-W%V-%u => 2007-W47-1 Week date (extended)
8629
- * %GW%V => 2007W47 Week date, reduced accuracy, specific week (basic)
8630
- * %G-W%V => 2007-W47 Week date, reduced accuracy, specific week (extended)
8631
- * %H%M%S => 083748 Local time (basic)
8632
- * %T => 08:37:48 Local time (extended)
8633
- * %H%M => 0837 Local time, reduced accuracy, specific minute (basic)
8634
- * %H:%M => 08:37 Local time, reduced accuracy, specific minute (extended)
8635
- * %H => 08 Local time, reduced accuracy, specific hour
8636
- * %H%M%S,%L => 083748,000 Local time with decimal fraction, comma as decimal sign (basic)
8637
- * %T,%L => 08:37:48,000 Local time with decimal fraction, comma as decimal sign (extended)
8638
- * %H%M%S.%L => 083748.000 Local time with decimal fraction, full stop as decimal sign (basic)
8639
- * %T.%L => 08:37:48.000 Local time with decimal fraction, full stop as decimal sign (extended)
8640
- * %H%M%S%z => 083748-0600 Local time and the difference from UTC (basic)
8641
- * %T%:z => 08:37:48-06:00 Local time and the difference from UTC (extended)
8642
- * %Y%m%dT%H%M%S%z => 20071119T083748-0600 Date and time of day for calendar date (basic)
8643
- * %FT%T%:z => 2007-11-19T08:37:48-06:00 Date and time of day for calendar date (extended)
8644
- * %Y%jT%H%M%S%z => 2007323T083748-0600 Date and time of day for ordinal date (basic)
8645
- * %Y-%jT%T%:z => 2007-323T08:37:48-06:00 Date and time of day for ordinal date (extended)
8646
- * %GW%V%uT%H%M%S%z => 2007W471T083748-0600 Date and time of day for week date (basic)
8647
- * %G-W%V-%uT%T%:z => 2007-W47-1T08:37:48-06:00 Date and time of day for week date (extended)
8648
- * %Y%m%dT%H%M => 20071119T0837 Calendar date and local time (basic)
8649
- * %FT%R => 2007-11-19T08:37 Calendar date and local time (extended)
8650
- * %Y%jT%H%MZ => 2007323T0837Z Ordinal date and UTC of day (basic)
8651
- * %Y-%jT%RZ => 2007-323T08:37Z Ordinal date and UTC of day (extended)
8652
- * %GW%V%uT%H%M%z => 2007W471T0837-0600 Week date and local time and difference from UTC (basic)
8653
- * %G-W%V-%uT%R%:z => 2007-W47-1T08:37-06:00 Week date and local time and difference from UTC (extended)
8654
- *
8655
- * See also strftime(3) and ::strptime.
8646
+ * strftime(format = '%FT%T%:z') -> string
8647
+ *
8648
+ * Returns a string representation of +self+,
8649
+ * formatted according the given +format:
8650
+ *
8651
+ * DateTime.now.strftime # => "2022-07-01T11:03:19-05:00"
8652
+ *
8653
+ * For other formats, see
8654
+ * {Formats for Dates and Times}[doc/strftime_formatting.rdoc].
8655
+ *
8656
8656
  */
8657
8657
  static VALUE
8658
8658
  dt_lite_strftime(int argc, VALUE *argv, VALUE self)
@@ -8818,7 +8818,7 @@ time_to_datetime(VALUE self)
8818
8818
  ret = d_complex_new_internal(cDateTime,
8819
8819
  nth, 0,
8820
8820
  0, sf,
8821
- of, DEFAULT_SG,
8821
+ of, GREGORIAN,
8822
8822
  ry, m, d,
8823
8823
  h, min, s,
8824
8824
  HAVE_CIVIL | HAVE_TIME);
@@ -8831,10 +8831,15 @@ time_to_datetime(VALUE self)
8831
8831
 
8832
8832
  /*
8833
8833
  * call-seq:
8834
- * d.to_time -> time
8834
+ * to_time -> time
8835
+ *
8836
+ * Returns a new Time object with the same value as +self+;
8837
+ * if +self+ is a Julian date, derives its Gregorian date
8838
+ * for conversion to the \Time object:
8839
+ *
8840
+ * Date.new(2001, 2, 3).to_time # => 2001-02-03 00:00:00 -0600
8841
+ * Date.new(2001, 2, 3, Date::JULIAN).to_time # => 2001-02-16 00:00:00 -0600
8835
8842
  *
8836
- * Returns a Time object which denotes self. If self is a julian date,
8837
- * convert it to a gregorian date before converting it to Time.
8838
8843
  */
8839
8844
  static VALUE
8840
8845
  date_to_time(VALUE self)
@@ -8855,9 +8860,9 @@ date_to_time(VALUE self)
8855
8860
 
8856
8861
  /*
8857
8862
  * call-seq:
8858
- * d.to_date -> self
8863
+ * to_date -> self
8859
8864
  *
8860
- * Returns self.
8865
+ * Returns +self+.
8861
8866
  */
8862
8867
  static VALUE
8863
8868
  date_to_date(VALUE self)
@@ -8869,7 +8874,10 @@ date_to_date(VALUE self)
8869
8874
  * call-seq:
8870
8875
  * d.to_datetime -> datetime
8871
8876
  *
8872
- * Returns a DateTime object which denotes self.
8877
+ * Returns a DateTime whose value is the same as +self+:
8878
+ *
8879
+ * Date.new(2001, 2, 3).to_datetime # => #<DateTime: 2001-02-03T00:00:00+00:00>
8880
+ *
8873
8881
  */
8874
8882
  static VALUE
8875
8883
  date_to_datetime(VALUE self)
@@ -8914,12 +8922,17 @@ date_to_datetime(VALUE self)
8914
8922
  static VALUE
8915
8923
  datetime_to_time(VALUE self)
8916
8924
  {
8917
- volatile VALUE dup = dup_obj(self);
8925
+ get_d1(self);
8926
+
8927
+ if (m_julian_p(dat)) {
8928
+ self = d_lite_gregorian(self);
8929
+ get_d1a(self);
8930
+ dat = adat;
8931
+ }
8932
+
8918
8933
  {
8919
8934
  VALUE t;
8920
8935
 
8921
- get_d1(dup);
8922
-
8923
8936
  t = rb_funcall(rb_cTime,
8924
8937
  rb_intern("new"),
8925
8938
  7,
@@ -8987,6 +9000,7 @@ datetime_to_datetime(VALUE self)
8987
9000
  #define MIN_JD -327
8988
9001
  #define MAX_JD 366963925
8989
9002
 
9003
+ /* :nodoc: */
8990
9004
  static int
8991
9005
  test_civil(int from, int to, double sg)
8992
9006
  {
@@ -9007,6 +9021,7 @@ test_civil(int from, int to, double sg)
9007
9021
  return 1;
9008
9022
  }
9009
9023
 
9024
+ /* :nodoc: */
9010
9025
  static VALUE
9011
9026
  date_s_test_civil(VALUE klass)
9012
9027
  {
@@ -9027,6 +9042,7 @@ date_s_test_civil(VALUE klass)
9027
9042
  return Qtrue;
9028
9043
  }
9029
9044
 
9045
+ /* :nodoc: */
9030
9046
  static int
9031
9047
  test_ordinal(int from, int to, double sg)
9032
9048
  {
@@ -9047,6 +9063,7 @@ test_ordinal(int from, int to, double sg)
9047
9063
  return 1;
9048
9064
  }
9049
9065
 
9066
+ /* :nodoc: */
9050
9067
  static VALUE
9051
9068
  date_s_test_ordinal(VALUE klass)
9052
9069
  {
@@ -9067,6 +9084,7 @@ date_s_test_ordinal(VALUE klass)
9067
9084
  return Qtrue;
9068
9085
  }
9069
9086
 
9087
+ /* :nodoc: */
9070
9088
  static int
9071
9089
  test_commercial(int from, int to, double sg)
9072
9090
  {
@@ -9087,6 +9105,7 @@ test_commercial(int from, int to, double sg)
9087
9105
  return 1;
9088
9106
  }
9089
9107
 
9108
+ /* :nodoc: */
9090
9109
  static VALUE
9091
9110
  date_s_test_commercial(VALUE klass)
9092
9111
  {
@@ -9107,6 +9126,7 @@ date_s_test_commercial(VALUE klass)
9107
9126
  return Qtrue;
9108
9127
  }
9109
9128
 
9129
+ /* :nodoc: */
9110
9130
  static int
9111
9131
  test_weeknum(int from, int to, int f, double sg)
9112
9132
  {
@@ -9127,6 +9147,7 @@ test_weeknum(int from, int to, int f, double sg)
9127
9147
  return 1;
9128
9148
  }
9129
9149
 
9150
+ /* :nodoc: */
9130
9151
  static VALUE
9131
9152
  date_s_test_weeknum(VALUE klass)
9132
9153
  {
@@ -9151,6 +9172,7 @@ date_s_test_weeknum(VALUE klass)
9151
9172
  return Qtrue;
9152
9173
  }
9153
9174
 
9175
+ /* :nodoc: */
9154
9176
  static int
9155
9177
  test_nth_kday(int from, int to, double sg)
9156
9178
  {
@@ -9171,6 +9193,7 @@ test_nth_kday(int from, int to, double sg)
9171
9193
  return 1;
9172
9194
  }
9173
9195
 
9196
+ /* :nodoc: */
9174
9197
  static VALUE
9175
9198
  date_s_test_nth_kday(VALUE klass)
9176
9199
  {
@@ -9191,6 +9214,7 @@ date_s_test_nth_kday(VALUE klass)
9191
9214
  return Qtrue;
9192
9215
  }
9193
9216
 
9217
+ /* :nodoc: */
9194
9218
  static int
9195
9219
  test_unit_v2v(VALUE i,
9196
9220
  VALUE (* conv1)(VALUE),
@@ -9202,6 +9226,7 @@ test_unit_v2v(VALUE i,
9202
9226
  return f_eqeq_p(o, i);
9203
9227
  }
9204
9228
 
9229
+ /* :nodoc: */
9205
9230
  static int
9206
9231
  test_unit_v2v_iter2(VALUE (* conv1)(VALUE),
9207
9232
  VALUE (* conv2)(VALUE))
@@ -9233,6 +9258,7 @@ test_unit_v2v_iter2(VALUE (* conv1)(VALUE),
9233
9258
  return 1;
9234
9259
  }
9235
9260
 
9261
+ /* :nodoc: */
9236
9262
  static int
9237
9263
  test_unit_v2v_iter(VALUE (* conv1)(VALUE),
9238
9264
  VALUE (* conv2)(VALUE))
@@ -9244,6 +9270,7 @@ test_unit_v2v_iter(VALUE (* conv1)(VALUE),
9244
9270
  return 1;
9245
9271
  }
9246
9272
 
9273
+ /* :nodoc: */
9247
9274
  static VALUE
9248
9275
  date_s_test_unit_conv(VALUE klass)
9249
9276
  {
@@ -9258,6 +9285,7 @@ date_s_test_unit_conv(VALUE klass)
9258
9285
  return Qtrue;
9259
9286
  }
9260
9287
 
9288
+ /* :nodoc: */
9261
9289
  static VALUE
9262
9290
  date_s_test_all(VALUE klass)
9263
9291
  {
@@ -9324,6 +9352,7 @@ mk_ary_of_str(long len, const char *a[])
9324
9352
  return o;
9325
9353
  }
9326
9354
 
9355
+ /* :nodoc: */
9327
9356
  static VALUE
9328
9357
  d_lite_zero(VALUE x)
9329
9358
  {
@@ -9361,152 +9390,81 @@ Init_date_core(void)
9361
9390
  negative_inf = -INFINITY;
9362
9391
 
9363
9392
  /*
9364
- * date and datetime class - Tadayoshi Funaba 1998-2011
9365
- *
9366
- * 'date' provides two classes: Date and DateTime.
9367
- *
9368
- * == Terms and Definitions
9369
- *
9370
- * Some terms and definitions are based on ISO 8601 and JIS X 0301.
9371
- *
9372
- * === Calendar Date
9373
- *
9374
- * The calendar date is a particular day of a calendar year,
9375
- * identified by its ordinal number within a calendar month within
9376
- * that year.
9377
- *
9378
- * In those classes, this is so-called "civil".
9379
- *
9380
- * === Ordinal Date
9393
+ * \Class \Date provides methods for storing and manipulating
9394
+ * calendar dates.
9381
9395
  *
9382
- * The ordinal date is a particular day of a calendar year identified
9383
- * by its ordinal number within the year.
9396
+ * Consider using
9397
+ * {class Time}[https://docs.ruby-lang.org/en/master/Time.html]
9398
+ * instead of class \Date if:
9384
9399
  *
9385
- * In those classes, this is so-called "ordinal".
9400
+ * - You need both dates and times; \Date handles only dates.
9401
+ * - You need only Gregorian dates (and not Julian dates);
9402
+ * see {Julian and Gregorian Calendars}[rdoc-ref:calendars.rdoc].
9386
9403
  *
9387
- * === Week Date
9404
+ * A \Date object, once created, is immutable, and cannot be modified.
9388
9405
  *
9389
- * The week date is a date identified by calendar week and day numbers.
9406
+ * == Creating a \Date
9390
9407
  *
9391
- * The calendar week is a seven day period within a calendar year,
9392
- * starting on a Monday and identified by its ordinal number within
9393
- * the year; the first calendar week of the year is the one that
9394
- * includes the first Thursday of that year. In the Gregorian
9395
- * calendar, this is equivalent to the week which includes January 4.
9408
+ * You can create a date for the current date, using Date.today:
9396
9409
  *
9397
- * In those classes, this is so-called "commercial".
9410
+ * Date.today # => #<Date: 1999-12-31>
9398
9411
  *
9399
- * === Julian Day Number
9412
+ * You can create a specific date from various combinations of arguments:
9400
9413
  *
9401
- * The Julian day number is in elapsed days since noon (Greenwich Mean
9402
- * Time) on January 1, 4713 BCE (in the Julian calendar).
9414
+ * - Date.new takes integer year, month, and day-of-month:
9403
9415
  *
9404
- * In this document, the astronomical Julian day number is the same as
9405
- * the original Julian day number. And the chronological Julian day
9406
- * number is a variation of the Julian day number. Its days begin at
9407
- * midnight on local time.
9416
+ * Date.new(1999, 12, 31) # => #<Date: 1999-12-31>
9408
9417
  *
9409
- * In this document, when the term "Julian day number" simply appears,
9410
- * it just refers to "chronological Julian day number", not the
9411
- * original.
9418
+ * - Date.ordinal takes integer year and day-of-year:
9412
9419
  *
9413
- * In those classes, those are so-called "ajd" and "jd".
9420
+ * Date.ordinal(1999, 365) # => #<Date: 1999-12-31>
9414
9421
  *
9415
- * === Modified Julian Day Number
9422
+ * - Date.jd takes integer Julian day:
9416
9423
  *
9417
- * The modified Julian day number is in elapsed days since midnight
9418
- * (Coordinated Universal Time) on November 17, 1858 CE (in the
9419
- * Gregorian calendar).
9424
+ * Date.jd(2451544) # => #<Date: 1999-12-31>
9420
9425
  *
9421
- * In this document, the astronomical modified Julian day number is
9422
- * the same as the original modified Julian day number. And the
9423
- * chronological modified Julian day number is a variation of the
9424
- * modified Julian day number. Its days begin at midnight on local
9425
- * time.
9426
+ * - Date.commercial takes integer commercial data (year, week, day-of-week):
9426
9427
  *
9427
- * In this document, when the term "modified Julian day number" simply
9428
- * appears, it just refers to "chronological modified Julian day
9429
- * number", not the original.
9428
+ * Date.commercial(1999, 52, 5) # => #<Date: 1999-12-31>
9430
9429
  *
9431
- * In those classes, those are so-called "amjd" and "mjd".
9430
+ * - Date.parse takes a string, which it parses heuristically:
9432
9431
  *
9433
- * == Date
9432
+ * Date.parse('1999-12-31') # => #<Date: 1999-12-31>
9433
+ * Date.parse('31-12-1999') # => #<Date: 1999-12-31>
9434
+ * Date.parse('1999-365') # => #<Date: 1999-12-31>
9435
+ * Date.parse('1999-W52-5') # => #<Date: 1999-12-31>
9434
9436
  *
9435
- * A subclass of Object that includes the Comparable module and
9436
- * easily handles date.
9437
+ * - Date.strptime takes a date string and a format string,
9438
+ * then parses the date string according to the format string:
9437
9439
  *
9438
- * A Date object is created with Date::new, Date::jd, Date::ordinal,
9439
- * Date::commercial, Date::parse, Date::strptime, Date::today,
9440
- * Time#to_date, etc.
9440
+ * Date.strptime('1999-12-31', '%Y-%m-%d') # => #<Date: 1999-12-31>
9441
+ * Date.strptime('31-12-1999', '%d-%m-%Y') # => #<Date: 1999-12-31>
9442
+ * Date.strptime('1999-365', '%Y-%j') # => #<Date: 1999-12-31>
9443
+ * Date.strptime('1999-W52-5', '%G-W%V-%u') # => #<Date: 1999-12-31>
9444
+ * Date.strptime('1999 52 5', '%Y %U %w') # => #<Date: 1999-12-31>
9445
+ * Date.strptime('1999 52 5', '%Y %W %u') # => #<Date: 1999-12-31>
9446
+ * Date.strptime('fri31dec99', '%a%d%b%y') # => #<Date: 1999-12-31>
9441
9447
  *
9442
- * require 'date'
9443
- *
9444
- * Date.new(2001,2,3)
9445
- * #=> #<Date: 2001-02-03 ...>
9446
- * Date.jd(2451944)
9447
- * #=> #<Date: 2001-02-03 ...>
9448
- * Date.ordinal(2001,34)
9449
- * #=> #<Date: 2001-02-03 ...>
9450
- * Date.commercial(2001,5,6)
9451
- * #=> #<Date: 2001-02-03 ...>
9452
- * Date.parse('2001-02-03')
9453
- * #=> #<Date: 2001-02-03 ...>
9454
- * Date.strptime('03-02-2001', '%d-%m-%Y')
9455
- * #=> #<Date: 2001-02-03 ...>
9456
- * Time.new(2001,2,3).to_date
9457
- * #=> #<Date: 2001-02-03 ...>
9458
- *
9459
- * All date objects are immutable; hence cannot modify themselves.
9448
+ * See also the specialized methods in
9449
+ * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings]
9460
9450
  *
9461
- * The concept of a date object can be represented as a tuple
9462
- * of the day count, the offset and the day of calendar reform.
9451
+ * == Argument +limit+
9463
9452
  *
9464
- * The day count denotes the absolute position of a temporal
9465
- * dimension. The offset is relative adjustment, which determines
9466
- * decoded local time with the day count. The day of calendar
9467
- * reform denotes the start day of the new style. The old style
9468
- * of the West is the Julian calendar which was adopted by
9469
- * Caesar. The new style is the Gregorian calendar, which is the
9470
- * current civil calendar of many countries.
9453
+ * Certain singleton methods in \Date that parse string arguments
9454
+ * also take optional keyword argument +limit+,
9455
+ * which can limit the length of the string argument.
9471
9456
  *
9472
- * The day count is virtually the astronomical Julian day number.
9473
- * The offset in this class is usually zero, and cannot be
9474
- * specified directly.
9475
- *
9476
- * A Date object can be created with an optional argument,
9477
- * the day of calendar reform as a Julian day number, which
9478
- * should be 2298874 to 2426355 or negative/positive infinity.
9479
- * The default value is +Date::ITALY+ (2299161=1582-10-15).
9480
- * See also sample/cal.rb.
9457
+ * When +limit+ is:
9481
9458
  *
9482
- * $ ruby sample/cal.rb -c it 10 1582
9483
- * October 1582
9484
- * S M Tu W Th F S
9485
- * 1 2 3 4 15 16
9486
- * 17 18 19 20 21 22 23
9487
- * 24 25 26 27 28 29 30
9488
- * 31
9489
- *
9490
- * $ ruby sample/cal.rb -c gb 9 1752
9491
- * September 1752
9492
- * S M Tu W Th F S
9493
- * 1 2 14 15 16
9494
- * 17 18 19 20 21 22 23
9495
- * 24 25 26 27 28 29 30
9496
- *
9497
- * A Date object has various methods. See each reference.
9498
- *
9499
- * d = Date.parse('3rd Feb 2001')
9500
- * #=> #<Date: 2001-02-03 ...>
9501
- * d.year #=> 2001
9502
- * d.mon #=> 2
9503
- * d.mday #=> 3
9504
- * d.wday #=> 6
9505
- * d += 1 #=> #<Date: 2001-02-04 ...>
9506
- * d.strftime('%a %d %b %Y') #=> "Sun 04 Feb 2001"
9459
+ * - Non-negative:
9460
+ * raises ArgumentError if the string length is greater than _limit_.
9461
+ * - Other numeric or +nil+: ignores +limit+.
9462
+ * - Other non-numeric: raises TypeError.
9507
9463
  *
9508
9464
  */
9509
9465
  cDate = rb_define_class("Date", rb_cObject);
9466
+
9467
+ /* Exception for invalid date/time */
9510
9468
  eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
9511
9469
 
9512
9470
  rb_include_module(cDate, rb_mComparable);