date 3.2.2 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/date/date_core.c CHANGED
@@ -27,6 +27,10 @@ static VALUE eDateError;
27
27
  static VALUE half_days_in_day, day_in_nanoseconds;
28
28
  static double positive_inf, negative_inf;
29
29
 
30
+ // used by deconstruct_keys
31
+ static VALUE sym_year, sym_month, sym_day, sym_yday, sym_wday;
32
+ static VALUE sym_hour, sym_min, sym_sec, sym_sec_fraction, sym_zone;
33
+
30
34
  #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
31
35
 
32
36
  #define f_abs(x) rb_funcall(x, rb_intern("abs"), 0)
@@ -60,7 +64,8 @@ static VALUE datetime_initialize(int argc, VALUE *argv, VALUE self);
60
64
 
61
65
  #define RETURN_FALSE_UNLESS_NUMERIC(obj) if(!RTEST(rb_obj_is_kind_of((obj), rb_cNumeric))) return Qfalse
62
66
  inline static void
63
- check_numeric(VALUE obj, const char* field) {
67
+ check_numeric(VALUE obj, const char* field)
68
+ {
64
69
  if(!RTEST(rb_obj_is_kind_of(obj, rb_cNumeric))) {
65
70
  rb_raise(rb_eTypeError, "invalid %s (not numeric)", field);
66
71
  }
@@ -465,6 +470,7 @@ c_find_ldoy(int y, double sg, int *rjd, int *ns)
465
470
  }
466
471
 
467
472
  #ifndef NDEBUG
473
+ /* :nodoc: */
468
474
  static int
469
475
  c_find_fdom(int y, int m, double sg, int *rjd, int *ns)
470
476
  {
@@ -621,6 +627,7 @@ c_jd_to_weeknum(int jd, int f, double sg, int *ry, int *rw, int *rd)
621
627
  }
622
628
 
623
629
  #ifndef NDEBUG
630
+ /* :nodoc: */
624
631
  static void
625
632
  c_nth_kday_to_jd(int y, int m, int n, int k, double sg, int *rjd, int *ns)
626
633
  {
@@ -646,6 +653,7 @@ c_jd_to_wday(int jd)
646
653
  }
647
654
 
648
655
  #ifndef NDEBUG
656
+ /* :nodoc: */
649
657
  static void
650
658
  c_jd_to_nth_kday(int jd, double sg, int *ry, int *rm, int *rn, int *rk)
651
659
  {
@@ -758,6 +766,8 @@ c_valid_civil_p(int y, int m, int d, double sg,
758
766
 
759
767
  if (m < 0)
760
768
  m += 13;
769
+ if (m < 1 || m > 12)
770
+ return 0;
761
771
  if (d < 0) {
762
772
  if (!c_find_ldom(y, m, sg, rjd, ns))
763
773
  return 0;
@@ -822,6 +832,7 @@ c_valid_weeknum_p(int y, int w, int d, int f, double sg,
822
832
  }
823
833
 
824
834
  #ifndef NDEBUG
835
+ /* :nodoc: */
825
836
  static int
826
837
  c_valid_nth_kday_p(int y, int m, int n, int k, double sg,
827
838
  int *rm, int *rn, int *rk, int *rjd, int *ns)
@@ -963,6 +974,7 @@ ns_to_day(VALUE n)
963
974
  }
964
975
 
965
976
  #ifndef NDEBUG
977
+ /* :nodoc: */
966
978
  static VALUE
967
979
  ms_to_sec(VALUE m)
968
980
  {
@@ -981,6 +993,7 @@ ns_to_sec(VALUE n)
981
993
  }
982
994
 
983
995
  #ifndef NDEBUG
996
+ /* :nodoc: */
984
997
  inline static VALUE
985
998
  ins_to_day(int n)
986
999
  {
@@ -1016,6 +1029,7 @@ day_to_sec(VALUE d)
1016
1029
  }
1017
1030
 
1018
1031
  #ifndef NDEBUG
1032
+ /* :nodoc: */
1019
1033
  static VALUE
1020
1034
  day_to_ns(VALUE d)
1021
1035
  {
@@ -1040,6 +1054,7 @@ sec_to_ns(VALUE s)
1040
1054
  }
1041
1055
 
1042
1056
  #ifndef NDEBUG
1057
+ /* :nodoc: */
1043
1058
  static VALUE
1044
1059
  isec_to_ns(int s)
1045
1060
  {
@@ -1066,6 +1081,7 @@ div_df(VALUE d, VALUE *f)
1066
1081
  }
1067
1082
 
1068
1083
  #ifndef NDEBUG
1084
+ /* :nodoc: */
1069
1085
  static VALUE
1070
1086
  div_sf(VALUE s, VALUE *f)
1071
1087
  {
@@ -1500,6 +1516,7 @@ m_df(union DateData *x)
1500
1516
  }
1501
1517
 
1502
1518
  #ifndef NDEBUG
1519
+ /* :nodoc: */
1503
1520
  static VALUE
1504
1521
  m_df_in_day(union DateData *x)
1505
1522
  {
@@ -1997,6 +2014,7 @@ expect_numeric(VALUE x)
1997
2014
  }
1998
2015
 
1999
2016
  #ifndef NDEBUG
2017
+ /* :nodoc: */
2000
2018
  static void
2001
2019
  civil_to_jd(VALUE y, int m, int d, double sg,
2002
2020
  VALUE *nth, int *ry,
@@ -2309,6 +2327,7 @@ valid_weeknum_p(VALUE y, int w, int d, int f, double sg,
2309
2327
  }
2310
2328
 
2311
2329
  #ifndef NDEBUG
2330
+ /* :nodoc: */
2312
2331
  static int
2313
2332
  valid_nth_kday_p(VALUE y, int m, int n, int k, double sg,
2314
2333
  VALUE *nth, int *ry,
@@ -2446,6 +2465,7 @@ valid_jd_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2446
2465
  }
2447
2466
 
2448
2467
  #ifndef NDEBUG
2468
+ /* :nodoc: */
2449
2469
  static VALUE
2450
2470
  date_s__valid_jd_p(int argc, VALUE *argv, VALUE klass)
2451
2471
  {
@@ -2466,13 +2486,16 @@ date_s__valid_jd_p(int argc, VALUE *argv, VALUE klass)
2466
2486
 
2467
2487
  /*
2468
2488
  * call-seq:
2469
- * Date.valid_jd?(jd[, start=Date::ITALY]) -> bool
2489
+ * Date.valid_jd?(jd, start = Date::ITALY) -> true
2470
2490
  *
2471
- * Just returns true. It's nonsense, but is for symmetry.
2491
+ * Implemented for compatibility;
2492
+ * returns +true+ unless +jd+ is invalid (i.e., not a Numeric).
2472
2493
  *
2473
- * Date.valid_jd?(2451944) #=> true
2494
+ * Date.valid_jd?(2451944) # => true
2474
2495
  *
2475
- * See also ::jd.
2496
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2497
+ *
2498
+ * Related: Date.jd.
2476
2499
  */
2477
2500
  static VALUE
2478
2501
  date_s_valid_jd_p(int argc, VALUE *argv, VALUE klass)
@@ -2532,6 +2555,7 @@ valid_civil_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2532
2555
  }
2533
2556
 
2534
2557
  #ifndef NDEBUG
2558
+ /* :nodoc: */
2535
2559
  static VALUE
2536
2560
  date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
2537
2561
  {
@@ -2554,18 +2578,20 @@ date_s__valid_civil_p(int argc, VALUE *argv, VALUE klass)
2554
2578
 
2555
2579
  /*
2556
2580
  * call-seq:
2557
- * Date.valid_civil?(year, month, mday[, start=Date::ITALY]) -> bool
2558
- * Date.valid_date?(year, month, mday[, start=Date::ITALY]) -> bool
2581
+ * Date.valid_civil?(year, month, mday, start = Date::ITALY) -> true or false
2582
+ *
2583
+ * Returns +true+ if the arguments define a valid ordinal date,
2584
+ * +false+ otherwise:
2559
2585
  *
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.
2586
+ * Date.valid_date?(2001, 2, 3) # => true
2587
+ * Date.valid_date?(2001, 2, 29) # => false
2588
+ * Date.valid_date?(2001, 2, -1) # => true
2563
2589
  *
2564
- * Date.valid_date?(2001,2,3) #=> true
2565
- * Date.valid_date?(2001,2,29) #=> false
2566
- * Date.valid_date?(2001,2,-1) #=> true
2590
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2567
2591
  *
2568
- * See also ::jd and ::civil.
2592
+ * Date.valid_date? is an alias for Date.valid_civil?.
2593
+ *
2594
+ * Related: Date.jd, Date.new.
2569
2595
  */
2570
2596
  static VALUE
2571
2597
  date_s_valid_civil_p(int argc, VALUE *argv, VALUE klass)
@@ -2621,6 +2647,7 @@ valid_ordinal_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2621
2647
  }
2622
2648
 
2623
2649
  #ifndef NDEBUG
2650
+ /* :nodoc: */
2624
2651
  static VALUE
2625
2652
  date_s__valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
2626
2653
  {
@@ -2642,14 +2669,17 @@ date_s__valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
2642
2669
 
2643
2670
  /*
2644
2671
  * call-seq:
2645
- * Date.valid_ordinal?(year, yday[, start=Date::ITALY]) -> bool
2672
+ * Date.valid_ordinal?(year, yday, start = Date::ITALY) -> true or false
2646
2673
  *
2647
- * Returns true if the given ordinal date is valid, and false if not.
2674
+ * Returns +true+ if the arguments define a valid ordinal date,
2675
+ * +false+ otherwise:
2648
2676
  *
2649
- * Date.valid_ordinal?(2001,34) #=> true
2650
- * Date.valid_ordinal?(2001,366) #=> false
2677
+ * Date.valid_ordinal?(2001, 34) # => true
2678
+ * Date.valid_ordinal?(2001, 366) # => false
2651
2679
  *
2652
- * See also ::jd and ::ordinal.
2680
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2681
+ *
2682
+ * Related: Date.jd, Date.ordinal.
2653
2683
  */
2654
2684
  static VALUE
2655
2685
  date_s_valid_ordinal_p(int argc, VALUE *argv, VALUE klass)
@@ -2704,6 +2734,7 @@ valid_commercial_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2704
2734
  }
2705
2735
 
2706
2736
  #ifndef NDEBUG
2737
+ /* :nodoc: */
2707
2738
  static VALUE
2708
2739
  date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2709
2740
  {
@@ -2726,14 +2757,19 @@ date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2726
2757
 
2727
2758
  /*
2728
2759
  * call-seq:
2729
- * Date.valid_commercial?(cwyear, cweek, cwday[, start=Date::ITALY]) -> bool
2760
+ * Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
2761
+ *
2762
+ * Returns +true+ if the arguments define a valid commercial date,
2763
+ * +false+ otherwise:
2730
2764
  *
2731
- * Returns true if the given week date is valid, and false if not.
2765
+ * Date.valid_commercial?(2001, 5, 6) # => true
2766
+ * Date.valid_commercial?(2001, 5, 8) # => false
2732
2767
  *
2733
- * Date.valid_commercial?(2001,5,6) #=> true
2734
- * Date.valid_commercial?(2001,5,8) #=> false
2768
+ * See Date.commercial.
2735
2769
  *
2736
- * See also ::jd and ::commercial.
2770
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
2771
+ *
2772
+ * Related: Date.jd, Date.commercial.
2737
2773
  */
2738
2774
  static VALUE
2739
2775
  date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
@@ -2760,6 +2796,7 @@ date_s_valid_commercial_p(int argc, VALUE *argv, VALUE klass)
2760
2796
  }
2761
2797
 
2762
2798
  #ifndef NDEBUG
2799
+ /* :nodoc: */
2763
2800
  static VALUE
2764
2801
  valid_weeknum_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2765
2802
  {
@@ -2791,6 +2828,7 @@ valid_weeknum_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2791
2828
  }
2792
2829
  }
2793
2830
 
2831
+ /* :nodoc: */
2794
2832
  static VALUE
2795
2833
  date_s__valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2796
2834
  {
@@ -2811,6 +2849,7 @@ date_s__valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2811
2849
  return valid_weeknum_sub(5, argv2, klass, 1);
2812
2850
  }
2813
2851
 
2852
+ /* :nodoc: */
2814
2853
  static VALUE
2815
2854
  date_s_valid_weeknum_p(int argc, VALUE *argv, VALUE klass)
2816
2855
  {
@@ -2862,6 +2901,7 @@ valid_nth_kday_sub(int argc, VALUE *argv, VALUE klass, int need_jd)
2862
2901
  }
2863
2902
  }
2864
2903
 
2904
+ /* :nodoc: */
2865
2905
  static VALUE
2866
2906
  date_s__valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2867
2907
  {
@@ -2882,6 +2922,7 @@ date_s__valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2882
2922
  return valid_nth_kday_sub(5, argv2, klass, 1);
2883
2923
  }
2884
2924
 
2925
+ /* :nodoc: */
2885
2926
  static VALUE
2886
2927
  date_s_valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2887
2928
  {
@@ -2904,6 +2945,7 @@ date_s_valid_nth_kday_p(int argc, VALUE *argv, VALUE klass)
2904
2945
  return Qtrue;
2905
2946
  }
2906
2947
 
2948
+ /* :nodoc: */
2907
2949
  static VALUE
2908
2950
  date_s_zone_to_diff(VALUE klass, VALUE str)
2909
2951
  {
@@ -2913,13 +2955,15 @@ date_s_zone_to_diff(VALUE klass, VALUE str)
2913
2955
 
2914
2956
  /*
2915
2957
  * call-seq:
2916
- * Date.julian_leap?(year) -> bool
2958
+ * Date.julian_leap?(year) -> true or false
2959
+ *
2960
+ * Returns +true+ if the given year is a leap year
2961
+ * in the {proleptic Julian calendar}[https://en.wikipedia.org/wiki/Proleptic_Julian_calendar], +false+ otherwise:
2917
2962
  *
2918
- * Returns true if the given year is a leap year of the proleptic
2919
- * Julian calendar.
2963
+ * Date.julian_leap?(1900) # => true
2964
+ * Date.julian_leap?(1901) # => false
2920
2965
  *
2921
- * Date.julian_leap?(1900) #=> true
2922
- * Date.julian_leap?(1901) #=> false
2966
+ * Related: Date.gregorian_leap?.
2923
2967
  */
2924
2968
  static VALUE
2925
2969
  date_s_julian_leap_p(VALUE klass, VALUE y)
@@ -2934,14 +2978,17 @@ date_s_julian_leap_p(VALUE klass, VALUE y)
2934
2978
 
2935
2979
  /*
2936
2980
  * call-seq:
2937
- * Date.gregorian_leap?(year) -> bool
2938
- * Date.leap?(year) -> bool
2981
+ * Date.gregorian_leap?(year) -> true or false
2939
2982
  *
2940
- * Returns true if the given year is a leap year of the proleptic
2941
- * Gregorian calendar.
2983
+ * Returns +true+ if the given year is a leap year
2984
+ * in the {proleptic Gregorian calendar}[https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar], +false+ otherwise:
2942
2985
  *
2943
- * Date.gregorian_leap?(1900) #=> false
2944
- * Date.gregorian_leap?(2000) #=> true
2986
+ * Date.gregorian_leap?(2000) # => true
2987
+ * Date.gregorian_leap?(2001) # => false
2988
+ *
2989
+ * Date.leap? is an alias for Date.gregorian_leap?.
2990
+ *
2991
+ * Related: Date.julian_leap?.
2945
2992
  */
2946
2993
  static VALUE
2947
2994
  date_s_gregorian_leap_p(VALUE klass, VALUE y)
@@ -3094,6 +3141,7 @@ old_to_new(VALUE ajd, VALUE of, VALUE sg,
3094
3141
  }
3095
3142
 
3096
3143
  #ifndef NDEBUG
3144
+ /* :nodoc: */
3097
3145
  static VALUE
3098
3146
  date_s_new_bang(int argc, VALUE *argv, VALUE klass)
3099
3147
  {
@@ -3281,16 +3329,29 @@ static VALUE d_lite_plus(VALUE, VALUE);
3281
3329
 
3282
3330
  /*
3283
3331
  * call-seq:
3284
- * Date.jd([jd=0[, start=Date::ITALY]]) -> date
3332
+ * Date.jd(jd = 0, start = Date::ITALY) -> date
3333
+ *
3334
+ * Returns a new \Date object formed from the arguments:
3335
+ *
3336
+ * Date.jd(2451944).to_s # => "2001-02-03"
3337
+ * Date.jd(2451945).to_s # => "2001-02-04"
3338
+ * Date.jd(0).to_s # => "-4712-01-01"
3285
3339
  *
3286
- * Creates a date object denoting the given chronological Julian day
3287
- * number.
3340
+ * The returned date is:
3288
3341
  *
3289
- * Date.jd(2451944) #=> #<Date: 2001-02-03 ...>
3290
- * Date.jd(2451945) #=> #<Date: 2001-02-04 ...>
3291
- * Date.jd(0) #=> #<Date: -4712-01-01 ...>
3342
+ * - Gregorian, if the argument is greater than or equal to +start+:
3292
3343
  *
3293
- * See also ::new.
3344
+ * Date::ITALY # => 2299161
3345
+ * Date.jd(Date::ITALY).gregorian? # => true
3346
+ * Date.jd(Date::ITALY + 1).gregorian? # => true
3347
+ *
3348
+ * - Julian, otherwise
3349
+ *
3350
+ * Date.jd(Date::ITALY - 1).julian? # => true
3351
+ *
3352
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3353
+ *
3354
+ * Related: Date.new.
3294
3355
  */
3295
3356
  static VALUE
3296
3357
  date_s_jd(int argc, VALUE *argv, VALUE klass)
@@ -3329,19 +3390,33 @@ date_s_jd(int argc, VALUE *argv, VALUE klass)
3329
3390
 
3330
3391
  /*
3331
3392
  * call-seq:
3332
- * Date.ordinal([year=-4712[, yday=1[, start=Date::ITALY]]]) -> date
3393
+ * Date.ordinal(year = -4712, yday = 1, start = Date::ITALY) -> date
3394
+ *
3395
+ * Returns a new \Date object formed fom the arguments.
3333
3396
  *
3334
- * Creates a date object denoting the given ordinal date.
3397
+ * With no arguments, returns the date for January 1, -4712:
3335
3398
  *
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.
3399
+ * Date.ordinal.to_s # => "-4712-01-01"
3339
3400
  *
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 ...>
3401
+ * With argument +year+, returns the date for January 1 of that year:
3343
3402
  *
3344
- * See also ::jd and ::new.
3403
+ * Date.ordinal(2001).to_s # => "2001-01-01"
3404
+ * Date.ordinal(-2001).to_s # => "-2001-01-01"
3405
+ *
3406
+ * With positive argument +yday+ == +n+,
3407
+ * returns the date for the +nth+ day of the given year:
3408
+ *
3409
+ * Date.ordinal(2001, 14).to_s # => "2001-01-14"
3410
+ *
3411
+ * With negative argument +yday+, counts backward from the end of the year:
3412
+ *
3413
+ * Date.ordinal(2001, -14).to_s # => "2001-12-18"
3414
+ *
3415
+ * Raises an exception if +yday+ is zero or out of range.
3416
+ *
3417
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3418
+ *
3419
+ * Related: Date.jd, Date.new.
3345
3420
  */
3346
3421
  static VALUE
3347
3422
  date_s_ordinal(int argc, VALUE *argv, VALUE klass)
@@ -3389,29 +3464,7 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass)
3389
3464
  }
3390
3465
 
3391
3466
  /*
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.
3467
+ * Same as Date.new.
3415
3468
  */
3416
3469
  static VALUE
3417
3470
  date_s_civil(int argc, VALUE *argv, VALUE klass)
@@ -3419,6 +3472,31 @@ date_s_civil(int argc, VALUE *argv, VALUE klass)
3419
3472
  return date_initialize(argc, argv, d_lite_s_alloc_simple(klass));
3420
3473
  }
3421
3474
 
3475
+ /*
3476
+ * call-seq:
3477
+ * Date.new(year = -4712, month = 1, mday = 1, start = Date::ITALY) -> date
3478
+ *
3479
+ * Returns a new \Date object constructed from the given arguments:
3480
+ *
3481
+ * Date.new(2022).to_s # => "2022-01-01"
3482
+ * Date.new(2022, 2).to_s # => "2022-02-01"
3483
+ * Date.new(2022, 2, 4).to_s # => "2022-02-04"
3484
+ *
3485
+ * Argument +month+ should be in range (1..12) or range (-12..-1);
3486
+ * when the argument is negative, counts backward from the end of the year:
3487
+ *
3488
+ * Date.new(2022, -11, 4).to_s # => "2022-02-04"
3489
+ *
3490
+ * Argument +mday+ should be in range (1..n) or range (-n..-1)
3491
+ * where +n+ is the number of days in the month;
3492
+ * when the argument is negative, counts backward from the end of the month.
3493
+ *
3494
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3495
+ *
3496
+ * Date.civil is an alias for Date.new.
3497
+ *
3498
+ * Related: Date.jd.
3499
+ */
3422
3500
  static VALUE
3423
3501
  date_initialize(int argc, VALUE *argv, VALUE self)
3424
3502
  {
@@ -3483,19 +3561,47 @@ date_initialize(int argc, VALUE *argv, VALUE self)
3483
3561
 
3484
3562
  /*
3485
3563
  * call-seq:
3486
- * Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) -> date
3564
+ * Date.commercial(cwyear = -4712, cweek = 1, cwday = 1, start = Date::ITALY) -> date
3565
+ *
3566
+ * Returns a new \Date object constructed from the arguments.
3567
+ *
3568
+ * Argument +cwyear+ gives the year, and should be an integer.
3569
+ *
3570
+ * Argument +cweek+ gives the index of the week within the year,
3571
+ * and should be in range (1..53) or (-53..-1);
3572
+ * in some years, 53 or -53 will be out-of-range;
3573
+ * if negative, counts backward from the end of the year:
3574
+ *
3575
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3576
+ * Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
3577
+ *
3578
+ * Argument +cwday+ gives the indes of the weekday within the week,
3579
+ * and should be in range (1..7) or (-7..-1);
3580
+ * 1 or -7 is Monday;
3581
+ * if negative, counts backward from the end of the week:
3582
+ *
3583
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3584
+ * Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
3585
+ *
3586
+ * When +cweek+ is 1:
3587
+ *
3588
+ * - If January 1 is a Friday, Saturday, or Sunday,
3589
+ * the first week begins in the week after:
3590
+ *
3591
+ * Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun"
3592
+ * Date.commercial(2023, 1, 1).to_s # => "2023-01-02"
3593
+ Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
3487
3594
  *
3488
- * Creates a date object denoting the given week date.
3595
+ * - Otherwise, the first week is the week of January 1,
3596
+ * which may mean some of the days fall on the year before:
3489
3597
  *
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.
3598
+ * Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed"
3599
+ * Date.commercial(2020, 1, 1).to_s # => "2019-12-30"
3600
+ Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
3493
3601
  *
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 ...>
3602
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3497
3603
  *
3498
- * See also ::jd and ::new.
3604
+ * Related: Date.jd, Date.new, Date.ordinal.
3499
3605
  */
3500
3606
  static VALUE
3501
3607
  date_s_commercial(int argc, VALUE *argv, VALUE klass)
@@ -3547,6 +3653,7 @@ date_s_commercial(int argc, VALUE *argv, VALUE klass)
3547
3653
  }
3548
3654
 
3549
3655
  #ifndef NDEBUG
3656
+ /* :nodoc: */
3550
3657
  static VALUE
3551
3658
  date_s_weeknum(int argc, VALUE *argv, VALUE klass)
3552
3659
  {
@@ -3596,6 +3703,7 @@ date_s_weeknum(int argc, VALUE *argv, VALUE klass)
3596
3703
  return ret;
3597
3704
  }
3598
3705
 
3706
+ /* :nodoc: */
3599
3707
  static VALUE
3600
3708
  date_s_nth_kday(int argc, VALUE *argv, VALUE klass)
3601
3709
  {
@@ -3670,11 +3778,14 @@ static void set_sg(union DateData *, double);
3670
3778
 
3671
3779
  /*
3672
3780
  * call-seq:
3673
- * Date.today([start=Date::ITALY]) -> date
3781
+ * Date.today(start = Date::ITALY) -> date
3782
+ *
3783
+ * Returns a new \Date object constructed from the present date:
3674
3784
  *
3675
- * Creates a date object denoting the present day.
3785
+ * Date.today.to_s # => "2022-07-06"
3786
+ *
3787
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
3676
3788
  *
3677
- * Date.today #=> #<Date: 2011-06-11 ...>
3678
3789
  */
3679
3790
  static VALUE
3680
3791
  date_s_today(int argc, VALUE *argv, VALUE klass)
@@ -4265,16 +4376,20 @@ date_s__strptime_internal(int argc, VALUE *argv, VALUE klass,
4265
4376
 
4266
4377
  /*
4267
4378
  * call-seq:
4268
- * Date._strptime(string[, format='%F']) -> hash
4379
+ * Date._strptime(string, format = '%F') -> hash
4269
4380
  *
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.
4381
+ * Returns a hash of values parsed from +string+
4382
+ * according to the given +format+:
4273
4383
  *
4274
- * Date._strptime('2001-02-03', '%Y-%m-%d')
4275
- * #=> {:year=>2001, :mon=>2, :mday=>3}
4384
+ * Date._strptime('2001-02-03', '%Y-%m-%d') # => {:year=>2001, :mon=>2, :mday=>3}
4276
4385
  *
4277
- * See also strptime(3) and #strftime.
4386
+ * For other formats, see
4387
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
4388
+ * (Unlike Date.strftime, does not support flags and width.)
4389
+ *
4390
+ * See also {strptime(3)}[https://man7.org/linux/man-pages/man3/strptime.3.html].
4391
+ *
4392
+ * Related: Date.strptime (returns a \Date object).
4278
4393
  */
4279
4394
  static VALUE
4280
4395
  date_s__strptime(int argc, VALUE *argv, VALUE klass)
@@ -4284,21 +4399,28 @@ date_s__strptime(int argc, VALUE *argv, VALUE klass)
4284
4399
 
4285
4400
  /*
4286
4401
  * call-seq:
4287
- * Date.strptime([string='-4712-01-01'[, format='%F'[, start=Date::ITALY]]]) -> date
4402
+ * Date.strptime(string = '-4712-01-01', format = '%F', start = Date::ITALY) -> date
4288
4403
  *
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.
4404
+ * Returns a new \Date object with values parsed from +string+,
4405
+ * according to the given +format+:
4292
4406
  *
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 ...>
4407
+ * Date.strptime('2001-02-03', '%Y-%m-%d') # => #<Date: 2001-02-03>
4408
+ * Date.strptime('03-02-2001', '%d-%m-%Y') # => #<Date: 2001-02-03>
4409
+ * Date.strptime('2001-034', '%Y-%j') # => #<Date: 2001-02-03>
4410
+ * Date.strptime('2001-W05-6', '%G-W%V-%u') # => #<Date: 2001-02-03>
4411
+ * Date.strptime('2001 04 6', '%Y %U %w') # => #<Date: 2001-02-03>
4412
+ * Date.strptime('2001 05 6', '%Y %W %u') # => #<Date: 2001-02-03>
4413
+ * Date.strptime('sat3feb01', '%a%d%b%y') # => #<Date: 2001-02-03>
4300
4414
  *
4301
- * See also strptime(3) and #strftime.
4415
+ * For other formats, see
4416
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
4417
+ * (Unlike Date.strftime, does not support flags and width.)
4418
+ *
4419
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4420
+ *
4421
+ * See also {strptime(3)}[https://man7.org/linux/man-pages/man3/strptime.3.html].
4422
+ *
4423
+ * Related: Date._strptime (returns a hash).
4302
4424
  */
4303
4425
  static VALUE
4304
4426
  date_s_strptime(int argc, VALUE *argv, VALUE klass)
@@ -4339,15 +4461,24 @@ get_limit(VALUE opt)
4339
4461
  return 128;
4340
4462
  }
4341
4463
 
4464
+ #ifndef HAVE_RB_CATEGORY_WARN
4465
+ #define rb_category_warn(category, fmt) rb_warn(fmt)
4466
+ #endif
4467
+
4342
4468
  static void
4343
4469
  check_limit(VALUE str, VALUE opt)
4344
4470
  {
4471
+ size_t slen, limit;
4345
4472
  if (NIL_P(str)) return;
4346
- if (SYMBOL_P(str)) str = rb_sym2str(str);
4473
+ if (SYMBOL_P(str)) {
4474
+ rb_category_warn(RB_WARN_CATEGORY_DEPRECATED,
4475
+ "The ability to parse Symbol is an unintentional bug and is deprecated");
4476
+ str = rb_sym2str(str);
4477
+ }
4347
4478
 
4348
4479
  StringValue(str);
4349
- size_t slen = RSTRING_LEN(str);
4350
- size_t limit = get_limit(opt);
4480
+ slen = RSTRING_LEN(str);
4481
+ limit = get_limit(opt);
4351
4482
  if (slen > limit) {
4352
4483
  rb_raise(rb_eArgError,
4353
4484
  "string length (%"PRI_SIZE_PREFIX"u) exceeds the limit %"PRI_SIZE_PREFIX"u", slen, limit);
@@ -4376,25 +4507,32 @@ date_s__parse_internal(int argc, VALUE *argv, VALUE klass)
4376
4507
 
4377
4508
  /*
4378
4509
  * call-seq:
4379
- * Date._parse(string[, comp=true], limit: 128) -> hash
4510
+ * Date._parse(string, comp = true, limit: 128) -> hash
4380
4511
  *
4381
- * Parses the given representation of date and time, and returns a
4382
- * hash of parsed elements.
4512
+ * <b>Note</b>:
4513
+ * This method recognizes many forms in +string+,
4514
+ * but it is not a validator.
4515
+ * For formats, see
4516
+ * {"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
4517
  *
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.
4518
+ * If +string+ does not specify a valid date,
4519
+ * the result is unpredictable;
4520
+ * consider using Date._strptime instead.
4388
4521
  *
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.
4522
+ * Returns a hash of values parsed from +string+:
4392
4523
  *
4393
- * Date._parse('2001-02-03') #=> {:year=>2001, :mon=>2, :mday=>3}
4524
+ * Date._parse('2001-02-03') # => {:year=>2001, :mon=>2, :mday=>3}
4394
4525
  *
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.
4526
+ * If +comp+ is +true+ and the given year is in the range <tt>(0..99)</tt>,
4527
+ * the current century is supplied;
4528
+ * otherwise, the year is taken as given:
4529
+ *
4530
+ * Date._parse('01-02-03', true) # => {:year=>2001, :mon=>2, :mday=>3}
4531
+ * Date._parse('01-02-03', false) # => {:year=>1, :mon=>2, :mday=>3}
4532
+ *
4533
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4534
+ *
4535
+ * Related: Date.parse(returns a \Date object).
4398
4536
  */
4399
4537
  static VALUE
4400
4538
  date_s__parse(int argc, VALUE *argv, VALUE klass)
@@ -4404,27 +4542,36 @@ date_s__parse(int argc, VALUE *argv, VALUE klass)
4404
4542
 
4405
4543
  /*
4406
4544
  * call-seq:
4407
- * Date.parse(string='-4712-01-01'[, comp=true[, start=Date::ITALY]], limit: 128) -> date
4545
+ * Date.parse(string = '-4712-01-01', comp = true, start = Date::ITALY, limit: 128) -> date
4408
4546
  *
4409
- * Parses the given representation of date and time, and creates a
4410
- * date object.
4547
+ * <b>Note</b>:
4548
+ * This method recognizes many forms in +string+,
4549
+ * but it is not a validator.
4550
+ * For formats, see
4551
+ * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings]
4552
+ * If +string+ does not specify a valid date,
4553
+ * the result is unpredictable;
4554
+ * consider using Date._strptime instead.
4411
4555
  *
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.
4556
+ * Returns a new \Date object with values parsed from +string+:
4416
4557
  *
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.
4558
+ * Date.parse('2001-02-03') # => #<Date: 2001-02-03>
4559
+ * Date.parse('20010203') # => #<Date: 2001-02-03>
4560
+ * Date.parse('3rd Feb 2001') # => #<Date: 2001-02-03>
4420
4561
  *
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 ...>
4562
+ * If +comp+ is +true+ and the given year is in the range <tt>(0..99)</tt>,
4563
+ * the current century is supplied;
4564
+ * otherwise, the year is taken as given:
4424
4565
  *
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.
4566
+ * Date.parse('01-02-03', true) # => #<Date: 2001-02-03>
4567
+ * Date.parse('01-02-03', false) # => #<Date: 0001-02-03>
4568
+ *
4569
+ * See:
4570
+ *
4571
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4572
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4573
+ *
4574
+ * Related: Date._parse (returns a hash).
4428
4575
  */
4429
4576
  static VALUE
4430
4577
  date_s_parse(int argc, VALUE *argv, VALUE klass)
@@ -4445,11 +4592,11 @@ date_s_parse(int argc, VALUE *argv, VALUE klass)
4445
4592
 
4446
4593
  {
4447
4594
  int argc2 = 2;
4448
- VALUE argv2[3];
4595
+ VALUE argv2[3], hash;
4449
4596
  argv2[0] = str;
4450
4597
  argv2[1] = comp;
4451
4598
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4452
- VALUE hash = date_s__parse(argc2, argv2, klass);
4599
+ hash = date_s__parse(argc2, argv2, klass);
4453
4600
  return d_new_by_frags(klass, hash, sg);
4454
4601
  }
4455
4602
  }
@@ -4463,13 +4610,18 @@ VALUE date__jisx0301(VALUE);
4463
4610
 
4464
4611
  /*
4465
4612
  * call-seq:
4466
- * Date._iso8601(string, limit: 128) -> hash
4613
+ * Date._iso8601(string, limit: 128) -> hash
4467
4614
  *
4468
- * Returns a hash of parsed elements.
4615
+ * Returns a hash of values parsed from +string+, which should contain
4616
+ * an {ISO 8601 formatted date}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]:
4469
4617
  *
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.
4618
+ * d = Date.new(2001, 2, 3)
4619
+ * s = d.iso8601 # => "2001-02-03"
4620
+ * Date._iso8601(s) # => {:mday=>3, :year=>2001, :mon=>2}
4621
+ *
4622
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4623
+ *
4624
+ * Related: Date.iso8601 (returns a \Date object).
4473
4625
  */
4474
4626
  static VALUE
4475
4627
  date_s__iso8601(int argc, VALUE *argv, VALUE klass)
@@ -4484,18 +4636,22 @@ date_s__iso8601(int argc, VALUE *argv, VALUE klass)
4484
4636
 
4485
4637
  /*
4486
4638
  * call-seq:
4487
- * Date.iso8601(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4639
+ * Date.iso8601(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4488
4640
  *
4489
- * Creates a new Date object by parsing from a string according to
4490
- * some typical ISO 8601 formats.
4641
+ * Returns a new \Date object with values parsed from +string+,
4642
+ * which should contain
4643
+ * an {ISO 8601 formatted date}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]:
4491
4644
  *
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 ...>
4645
+ * d = Date.new(2001, 2, 3)
4646
+ * s = d.iso8601 # => "2001-02-03"
4647
+ * Date.iso8601(s) # => #<Date: 2001-02-03>
4495
4648
  *
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.
4649
+ * See:
4650
+ *
4651
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4652
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4653
+ *
4654
+ * Related: Date._iso8601 (returns a hash).
4499
4655
  */
4500
4656
  static VALUE
4501
4657
  date_s_iso8601(int argc, VALUE *argv, VALUE klass)
@@ -4514,23 +4670,29 @@ date_s_iso8601(int argc, VALUE *argv, VALUE klass)
4514
4670
 
4515
4671
  {
4516
4672
  int argc2 = 1;
4517
- VALUE argv2[2];
4673
+ VALUE argv2[2], hash;
4518
4674
  argv2[0] = str;
4519
4675
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4520
- VALUE hash = date_s__iso8601(argc2, argv2, klass);
4676
+ hash = date_s__iso8601(argc2, argv2, klass);
4521
4677
  return d_new_by_frags(klass, hash, sg);
4522
4678
  }
4523
4679
  }
4524
4680
 
4525
4681
  /*
4526
4682
  * call-seq:
4527
- * Date._rfc3339(string, limit: 128) -> hash
4683
+ * Date._rfc3339(string, limit: 128) -> hash
4528
4684
  *
4529
- * Returns a hash of parsed elements.
4685
+ * Returns a hash of values parsed from +string+, which should be a valid
4686
+ * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]:
4530
4687
  *
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.
4688
+ * d = Date.new(2001, 2, 3)
4689
+ * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
4690
+ * Date._rfc3339(s)
4691
+ * # => {:year=>2001, :mon=>2, :mday=>3, :hour=>0, :min=>0, :sec=>0, :zone=>"+00:00", :offset=>0}
4692
+ *
4693
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4694
+ *
4695
+ * Related: Date.rfc3339 (returns a \Date object).
4534
4696
  */
4535
4697
  static VALUE
4536
4698
  date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -4545,16 +4707,22 @@ date_s__rfc3339(int argc, VALUE *argv, VALUE klass)
4545
4707
 
4546
4708
  /*
4547
4709
  * call-seq:
4548
- * Date.rfc3339(string='-4712-01-01T00:00:00+00:00'[, start=Date::ITALY], limit: 128) -> date
4710
+ * Date.rfc3339(string = '-4712-01-01T00:00:00+00:00', start = Date::ITALY, limit: 128) -> date
4549
4711
  *
4550
- * Creates a new Date object by parsing from a string according to
4551
- * some typical RFC 3339 formats.
4712
+ * Returns a new \Date object with values parsed from +string+,
4713
+ * which should be a valid
4714
+ * {RFC 3339 format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+3339+Format]:
4552
4715
  *
4553
- * Date.rfc3339('2001-02-03T04:05:06+07:00') #=> #<Date: 2001-02-03 ...>
4716
+ * d = Date.new(2001, 2, 3)
4717
+ * s = d.rfc3339 # => "2001-02-03T00:00:00+00:00"
4718
+ * Date.rfc3339(s) # => #<Date: 2001-02-03>
4554
4719
  *
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.
4720
+ * See:
4721
+ *
4722
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4723
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4724
+ *
4725
+ * Related: Date._rfc3339 (returns a hash).
4558
4726
  */
4559
4727
  static VALUE
4560
4728
  date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -4573,23 +4741,28 @@ date_s_rfc3339(int argc, VALUE *argv, VALUE klass)
4573
4741
 
4574
4742
  {
4575
4743
  int argc2 = 1;
4576
- VALUE argv2[2];
4744
+ VALUE argv2[2], hash;
4577
4745
  argv2[0] = str;
4578
4746
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4579
- VALUE hash = date_s__rfc3339(argc2, argv2, klass);
4747
+ hash = date_s__rfc3339(argc2, argv2, klass);
4580
4748
  return d_new_by_frags(klass, hash, sg);
4581
4749
  }
4582
4750
  }
4583
4751
 
4584
4752
  /*
4585
4753
  * call-seq:
4586
- * Date._xmlschema(string, limit: 128) -> hash
4754
+ * Date._xmlschema(string, limit: 128) -> hash
4587
4755
  *
4588
- * Returns a hash of parsed elements.
4756
+ * Returns a hash of values parsed from +string+, which should be a valid
4757
+ * XML date format:
4589
4758
  *
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.
4759
+ * d = Date.new(2001, 2, 3)
4760
+ * s = d.xmlschema # => "2001-02-03"
4761
+ * Date._xmlschema(s) # => {:year=>2001, :mon=>2, :mday=>3}
4762
+ *
4763
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4764
+ *
4765
+ * Related: Date.xmlschema (returns a \Date object).
4593
4766
  */
4594
4767
  static VALUE
4595
4768
  date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -4604,16 +4777,21 @@ date_s__xmlschema(int argc, VALUE *argv, VALUE klass)
4604
4777
 
4605
4778
  /*
4606
4779
  * call-seq:
4607
- * Date.xmlschema(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4780
+ * Date.xmlschema(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4608
4781
  *
4609
- * Creates a new Date object by parsing from a string according to
4610
- * some typical XML Schema formats.
4782
+ * Returns a new \Date object with values parsed from +string+,
4783
+ * which should be a valid XML date format:
4611
4784
  *
4612
- * Date.xmlschema('2001-02-03') #=> #<Date: 2001-02-03 ...>
4785
+ * d = Date.new(2001, 2, 3)
4786
+ * s = d.xmlschema # => "2001-02-03"
4787
+ * Date.xmlschema(s) # => #<Date: 2001-02-03>
4613
4788
  *
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.
4789
+ * See:
4790
+ *
4791
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4792
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4793
+ *
4794
+ * Related: Date._xmlschema (returns a hash).
4617
4795
  */
4618
4796
  static VALUE
4619
4797
  date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -4632,24 +4810,31 @@ date_s_xmlschema(int argc, VALUE *argv, VALUE klass)
4632
4810
 
4633
4811
  {
4634
4812
  int argc2 = 1;
4635
- VALUE argv2[2];
4813
+ VALUE argv2[2], hash;
4636
4814
  argv2[0] = str;
4637
4815
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4638
- VALUE hash = date_s__xmlschema(argc2, argv2, klass);
4816
+ hash = date_s__xmlschema(argc2, argv2, klass);
4639
4817
  return d_new_by_frags(klass, hash, sg);
4640
4818
  }
4641
4819
  }
4642
4820
 
4643
4821
  /*
4644
4822
  * call-seq:
4645
- * Date._rfc2822(string, limit: 128) -> hash
4646
- * Date._rfc822(string, limit: 128) -> hash
4823
+ * Date._rfc2822(string, limit: 128) -> hash
4647
4824
  *
4648
- * Returns a hash of parsed elements.
4825
+ * Returns a hash of values parsed from +string+, which should be a valid
4826
+ * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]:
4649
4827
  *
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.
4828
+ * d = Date.new(2001, 2, 3)
4829
+ * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
4830
+ * Date._rfc2822(s)
4831
+ * # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"+0000", :offset=>0}
4832
+ *
4833
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4834
+ *
4835
+ * Date._rfc822 is an alias for Date._rfc2822.
4836
+ *
4837
+ * Related: Date.rfc2822 (returns a \Date object).
4653
4838
  */
4654
4839
  static VALUE
4655
4840
  date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -4664,18 +4849,24 @@ date_s__rfc2822(int argc, VALUE *argv, VALUE klass)
4664
4849
 
4665
4850
  /*
4666
4851
  * 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
4852
+ * Date.rfc2822(string = 'Mon, 1 Jan -4712 00:00:00 +0000', start = Date::ITALY, limit: 128) -> date
4669
4853
  *
4670
- * Creates a new Date object by parsing from a string according to
4671
- * some typical RFC 2822 formats.
4854
+ * Returns a new \Date object with values parsed from +string+,
4855
+ * which should be a valid
4856
+ * {RFC 2822 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-RFC+2822+Format]:
4672
4857
  *
4673
- * Date.rfc2822('Sat, 3 Feb 2001 00:00:00 +0000')
4674
- * #=> #<Date: 2001-02-03 ...>
4858
+ * d = Date.new(2001, 2, 3)
4859
+ * s = d.rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
4860
+ * Date.rfc2822(s) # => #<Date: 2001-02-03>
4675
4861
  *
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.
4862
+ * See:
4863
+ *
4864
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4865
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4866
+ *
4867
+ * Date.rfc822 is an alias for Date.rfc2822.
4868
+ *
4869
+ * Related: Date._rfc2822 (returns a hash).
4679
4870
  */
4680
4871
  static VALUE
4681
4872
  date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -4693,23 +4884,27 @@ date_s_rfc2822(int argc, VALUE *argv, VALUE klass)
4693
4884
 
4694
4885
  {
4695
4886
  int argc2 = 1;
4696
- VALUE argv2[2];
4887
+ VALUE argv2[2], hash;
4697
4888
  argv2[0] = str;
4698
4889
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4699
- VALUE hash = date_s__rfc2822(argc2, argv2, klass);
4890
+ hash = date_s__rfc2822(argc2, argv2, klass);
4700
4891
  return d_new_by_frags(klass, hash, sg);
4701
4892
  }
4702
4893
  }
4703
4894
 
4704
4895
  /*
4705
4896
  * call-seq:
4706
- * Date._httpdate(string, limit: 128) -> hash
4897
+ * Date._httpdate(string, limit: 128) -> hash
4707
4898
  *
4708
- * Returns a hash of parsed elements.
4899
+ * Returns a hash of values parsed from +string+, which should be a valid
4900
+ * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]:
4709
4901
  *
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.
4902
+ * d = Date.new(2001, 2, 3)
4903
+ * s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
4904
+ * Date._httpdate(s)
4905
+ * # => {:wday=>6, :mday=>3, :mon=>2, :year=>2001, :hour=>0, :min=>0, :sec=>0, :zone=>"GMT", :offset=>0}
4906
+ *
4907
+ * Related: Date.httpdate (returns a \Date object).
4713
4908
  */
4714
4909
  static VALUE
4715
4910
  date_s__httpdate(int argc, VALUE *argv, VALUE klass)
@@ -4724,17 +4919,22 @@ date_s__httpdate(int argc, VALUE *argv, VALUE klass)
4724
4919
 
4725
4920
  /*
4726
4921
  * call-seq:
4727
- * Date.httpdate(string='Mon, 01 Jan -4712 00:00:00 GMT'[, start=Date::ITALY], limit: 128) -> date
4922
+ * Date.httpdate(string = 'Mon, 01 Jan -4712 00:00:00 GMT', start = Date::ITALY, limit: 128) -> date
4728
4923
  *
4729
- * Creates a new Date object by parsing from a string according to
4730
- * some RFC 2616 format.
4924
+ * Returns a new \Date object with values parsed from +string+,
4925
+ * which should be a valid
4926
+ * {HTTP date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-HTTP+Format]:
4731
4927
  *
4732
- * Date.httpdate('Sat, 03 Feb 2001 00:00:00 GMT')
4733
- * #=> #<Date: 2001-02-03 ...>
4928
+ * d = Date.new(2001, 2, 3)
4929
+ s = d.httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
4930
+ Date.httpdate(s) # => #<Date: 2001-02-03>
4734
4931
  *
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.
4932
+ * See:
4933
+ *
4934
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
4935
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
4936
+ *
4937
+ * Related: Date._httpdate (returns a hash).
4738
4938
  */
4739
4939
  static VALUE
4740
4940
  date_s_httpdate(int argc, VALUE *argv, VALUE klass)
@@ -4752,23 +4952,28 @@ date_s_httpdate(int argc, VALUE *argv, VALUE klass)
4752
4952
 
4753
4953
  {
4754
4954
  int argc2 = 1;
4755
- VALUE argv2[2];
4955
+ VALUE argv2[2], hash;
4756
4956
  argv2[0] = str;
4757
4957
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4758
- VALUE hash = date_s__httpdate(argc2, argv2, klass);
4958
+ hash = date_s__httpdate(argc2, argv2, klass);
4759
4959
  return d_new_by_frags(klass, hash, sg);
4760
4960
  }
4761
4961
  }
4762
4962
 
4763
4963
  /*
4764
4964
  * call-seq:
4765
- * Date._jisx0301(string, limit: 128) -> hash
4965
+ * Date._jisx0301(string, limit: 128) -> hash
4766
4966
  *
4767
- * Returns a hash of parsed elements.
4967
+ * Returns a hash of values parsed from +string+, which should be a valid
4968
+ * {JIS X 0301 date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-JIS+X+0301+Format]:
4768
4969
  *
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.
4970
+ * d = Date.new(2001, 2, 3)
4971
+ * s = d.jisx0301 # => "H13.02.03"
4972
+ * Date._jisx0301(s) # => {:year=>2001, :mon=>2, :mday=>3}
4973
+ *
4974
+ * See argument {limit}[rdoc-ref:Date@Argument+limit].
4975
+ *
4976
+ * Related: Date.jisx0301 (returns a \Date object).
4772
4977
  */
4773
4978
  static VALUE
4774
4979
  date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -4783,20 +4988,25 @@ date_s__jisx0301(int argc, VALUE *argv, VALUE klass)
4783
4988
 
4784
4989
  /*
4785
4990
  * call-seq:
4786
- * Date.jisx0301(string='-4712-01-01'[, start=Date::ITALY], limit: 128) -> date
4991
+ * Date.jisx0301(string = '-4712-01-01', start = Date::ITALY, limit: 128) -> date
4787
4992
  *
4788
- * Creates a new Date object by parsing from a string according to
4789
- * some typical JIS X 0301 formats.
4993
+ * Returns a new \Date object with values parsed from +string+,
4994
+ * 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
4995
  *
4791
- * Date.jisx0301('H13.02.03') #=> #<Date: 2001-02-03 ...>
4996
+ * d = Date.new(2001, 2, 3)
4997
+ * s = d.jisx0301 # => "H13.02.03"
4998
+ * Date.jisx0301(s) # => #<Date: 2001-02-03>
4792
4999
  *
4793
5000
  * For no-era year, legacy format, Heisei is assumed.
4794
5001
  *
4795
- * Date.jisx0301('13.02.03') #=> #<Date: 2001-02-03 ...>
5002
+ * Date.jisx0301('13.02.03') # => #<Date: 2001-02-03>
4796
5003
  *
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.
5004
+ * See:
5005
+ *
5006
+ * - Argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5007
+ * - Argument {limit}[rdoc-ref:Date@Argument+limit].
5008
+ *
5009
+ * Related: Date._jisx0301 (returns a hash).
4800
5010
  */
4801
5011
  static VALUE
4802
5012
  date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -4815,10 +5025,10 @@ date_s_jisx0301(int argc, VALUE *argv, VALUE klass)
4815
5025
 
4816
5026
  {
4817
5027
  int argc2 = 1;
4818
- VALUE argv2[2];
5028
+ VALUE argv2[2], hash;
4819
5029
  argv2[0] = str;
4820
5030
  if (!NIL_P(opt)) argv2[argc2++] = opt;
4821
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
5031
+ hash = date_s__jisx0301(argc2, argv2, klass);
4822
5032
  return d_new_by_frags(klass, hash, sg);
4823
5033
  }
4824
5034
  }
@@ -4988,6 +5198,7 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
4988
5198
  }
4989
5199
 
4990
5200
  #ifndef NDEBUG
5201
+ /* :nodoc: */
4991
5202
  static VALUE
4992
5203
  d_lite_fill(VALUE self)
4993
5204
  {
@@ -5077,12 +5288,15 @@ d_lite_mjd(VALUE self)
5077
5288
 
5078
5289
  /*
5079
5290
  * call-seq:
5080
- * d.ld -> integer
5291
+ * ld -> integer
5081
5292
  *
5082
- * Returns the Lilian day number. This is a whole number, which is
5083
- * adjusted by the offset as the local time.
5293
+ * Returns the
5294
+ * {Lilian day number}[https://en.wikipedia.org/wiki/Lilian_date],
5295
+ * which is the number of days since the beginning of the Gregorian
5296
+ * calendar, October 15, 1582.
5297
+ *
5298
+ * Date.new(2001, 2, 3).ld # => 152784
5084
5299
  *
5085
- * Date.new(2001,2,3).ld #=> 152784
5086
5300
  */
5087
5301
  static VALUE
5088
5302
  d_lite_ld(VALUE self)
@@ -5093,12 +5307,13 @@ d_lite_ld(VALUE self)
5093
5307
 
5094
5308
  /*
5095
5309
  * call-seq:
5096
- * d.year -> integer
5310
+ * year -> integer
5311
+ *
5312
+ * Returns the year:
5097
5313
  *
5098
- * Returns the year.
5314
+ * Date.new(2001, 2, 3).year # => 2001
5315
+ * (Date.new(1, 1, 1) - 1).year # => 0
5099
5316
  *
5100
- * Date.new(2001,2,3).year #=> 2001
5101
- * (Date.new(1,1,1) - 1).year #=> 0
5102
5317
  */
5103
5318
  static VALUE
5104
5319
  d_lite_year(VALUE self)
@@ -5109,11 +5324,12 @@ d_lite_year(VALUE self)
5109
5324
 
5110
5325
  /*
5111
5326
  * call-seq:
5112
- * d.yday -> fixnum
5327
+ * yday -> integer
5113
5328
  *
5114
- * Returns the day of the year (1-366).
5329
+ * Returns the day of the year, in range (1..366):
5330
+ *
5331
+ * Date.new(2001, 2, 3).yday # => 34
5115
5332
  *
5116
- * Date.new(2001,2,3).yday #=> 34
5117
5333
  */
5118
5334
  static VALUE
5119
5335
  d_lite_yday(VALUE self)
@@ -5124,12 +5340,13 @@ d_lite_yday(VALUE self)
5124
5340
 
5125
5341
  /*
5126
5342
  * call-seq:
5127
- * d.mon -> fixnum
5128
- * d.month -> fixnum
5343
+ * mon -> integer
5344
+ *
5345
+ * Returns the month in range (1..12):
5129
5346
  *
5130
- * Returns the month (1-12).
5347
+ * Date.new(2001, 2, 3).mon # => 2
5131
5348
  *
5132
- * Date.new(2001,2,3).mon #=> 2
5349
+ * Date#month is an alias for Date#mon.
5133
5350
  */
5134
5351
  static VALUE
5135
5352
  d_lite_mon(VALUE self)
@@ -5140,12 +5357,13 @@ d_lite_mon(VALUE self)
5140
5357
 
5141
5358
  /*
5142
5359
  * call-seq:
5143
- * d.mday -> fixnum
5144
- * d.day -> fixnum
5360
+ * mday -> integer
5361
+ *
5362
+ * Returns the day of the month in range (1..31):
5145
5363
  *
5146
- * Returns the day of the month (1-31).
5364
+ * Date.new(2001, 2, 3).mday # => 3
5147
5365
  *
5148
- * Date.new(2001,2,3).mday #=> 3
5366
+ * Date#day is an alias for Date#mday.
5149
5367
  */
5150
5368
  static VALUE
5151
5369
  d_lite_mday(VALUE self)
@@ -5156,11 +5374,12 @@ d_lite_mday(VALUE self)
5156
5374
 
5157
5375
  /*
5158
5376
  * call-seq:
5159
- * d.day_fraction -> rational
5377
+ * day_fraction -> rational
5160
5378
  *
5161
- * Returns the fractional part of the day.
5379
+ * Returns the fractional part of the day in range (Rational(0, 1)...Rational(1, 1)):
5380
+ *
5381
+ * DateTime.new(2001,2,3,12).day_fraction # => (1/2)
5162
5382
  *
5163
- * DateTime.new(2001,2,3,12).day_fraction #=> (1/2)
5164
5383
  */
5165
5384
  static VALUE
5166
5385
  d_lite_day_fraction(VALUE self)
@@ -5173,12 +5392,14 @@ d_lite_day_fraction(VALUE self)
5173
5392
 
5174
5393
  /*
5175
5394
  * call-seq:
5176
- * d.cwyear -> integer
5395
+ * cwyear -> integer
5396
+ *
5397
+ * Returns commercial-date year for +self+
5398
+ * (see Date.commercial):
5177
5399
  *
5178
- * Returns the calendar week based year.
5400
+ * Date.new(2001, 2, 3).cwyear # => 2001
5401
+ * Date.new(2000, 1, 1).cwyear # => 1999
5179
5402
  *
5180
- * Date.new(2001,2,3).cwyear #=> 2001
5181
- * Date.new(2000,1,1).cwyear #=> 1999
5182
5403
  */
5183
5404
  static VALUE
5184
5405
  d_lite_cwyear(VALUE self)
@@ -5189,11 +5410,13 @@ d_lite_cwyear(VALUE self)
5189
5410
 
5190
5411
  /*
5191
5412
  * call-seq:
5192
- * d.cweek -> fixnum
5413
+ * cweek -> integer
5193
5414
  *
5194
- * Returns the calendar week number (1-53).
5415
+ * Returns commercial-date week index for +self+
5416
+ * (see Date.commercial):
5417
+ *
5418
+ * Date.new(2001, 2, 3).cweek # => 5
5195
5419
  *
5196
- * Date.new(2001,2,3).cweek #=> 5
5197
5420
  */
5198
5421
  static VALUE
5199
5422
  d_lite_cweek(VALUE self)
@@ -5204,11 +5427,14 @@ d_lite_cweek(VALUE self)
5204
5427
 
5205
5428
  /*
5206
5429
  * call-seq:
5207
- * d.cwday -> fixnum
5430
+ * cwday -> integer
5431
+ *
5432
+ * Returns the commercial-date weekday index for +self+
5433
+ * (see Date.commercial);
5434
+ * 1 is Monday:
5208
5435
  *
5209
- * Returns the day of calendar week (1-7, Monday is 1).
5436
+ * Date.new(2001, 2, 3).cwday # => 6
5210
5437
  *
5211
- * Date.new(2001,2,3).cwday #=> 6
5212
5438
  */
5213
5439
  static VALUE
5214
5440
  d_lite_cwday(VALUE self)
@@ -5218,6 +5444,7 @@ d_lite_cwday(VALUE self)
5218
5444
  }
5219
5445
 
5220
5446
  #ifndef NDEBUG
5447
+ /* :nodoc: */
5221
5448
  static VALUE
5222
5449
  d_lite_wnum0(VALUE self)
5223
5450
  {
@@ -5225,6 +5452,7 @@ d_lite_wnum0(VALUE self)
5225
5452
  return INT2FIX(m_wnum0(dat));
5226
5453
  }
5227
5454
 
5455
+ /* :nodoc: */
5228
5456
  static VALUE
5229
5457
  d_lite_wnum1(VALUE self)
5230
5458
  {
@@ -5235,11 +5463,12 @@ d_lite_wnum1(VALUE self)
5235
5463
 
5236
5464
  /*
5237
5465
  * call-seq:
5238
- * d.wday -> fixnum
5466
+ * wday -> integer
5467
+ *
5468
+ * Returns the day of week in range (0..6); Sunday is 0:
5239
5469
  *
5240
- * Returns the day of week (0-6, Sunday is zero).
5470
+ * Date.new(2001, 2, 3).wday # => 6
5241
5471
  *
5242
- * Date.new(2001,2,3).wday #=> 6
5243
5472
  */
5244
5473
  static VALUE
5245
5474
  d_lite_wday(VALUE self)
@@ -5250,9 +5479,9 @@ d_lite_wday(VALUE self)
5250
5479
 
5251
5480
  /*
5252
5481
  * call-seq:
5253
- * d.sunday? -> bool
5482
+ * sunday? -> true or false
5254
5483
  *
5255
- * Returns true if the date is Sunday.
5484
+ * Returns +true+ if +self+ is a Sunday, +false+ otherwise.
5256
5485
  */
5257
5486
  static VALUE
5258
5487
  d_lite_sunday_p(VALUE self)
@@ -5263,9 +5492,9 @@ d_lite_sunday_p(VALUE self)
5263
5492
 
5264
5493
  /*
5265
5494
  * call-seq:
5266
- * d.monday? -> bool
5495
+ * monday? -> true or false
5267
5496
  *
5268
- * Returns true if the date is Monday.
5497
+ * Returns +true+ if +self+ is a Monday, +false+ otherwise.
5269
5498
  */
5270
5499
  static VALUE
5271
5500
  d_lite_monday_p(VALUE self)
@@ -5276,9 +5505,9 @@ d_lite_monday_p(VALUE self)
5276
5505
 
5277
5506
  /*
5278
5507
  * call-seq:
5279
- * d.tuesday? -> bool
5508
+ * tuesday? -> true or false
5280
5509
  *
5281
- * Returns true if the date is Tuesday.
5510
+ * Returns +true+ if +self+ is a Tuesday, +false+ otherwise.
5282
5511
  */
5283
5512
  static VALUE
5284
5513
  d_lite_tuesday_p(VALUE self)
@@ -5289,9 +5518,9 @@ d_lite_tuesday_p(VALUE self)
5289
5518
 
5290
5519
  /*
5291
5520
  * call-seq:
5292
- * d.wednesday? -> bool
5521
+ * wednesday? -> true or false
5293
5522
  *
5294
- * Returns true if the date is Wednesday.
5523
+ * Returns +true+ if +self+ is a Wednesday, +false+ otherwise.
5295
5524
  */
5296
5525
  static VALUE
5297
5526
  d_lite_wednesday_p(VALUE self)
@@ -5302,9 +5531,9 @@ d_lite_wednesday_p(VALUE self)
5302
5531
 
5303
5532
  /*
5304
5533
  * call-seq:
5305
- * d.thursday? -> bool
5534
+ * thursday? -> true or false
5306
5535
  *
5307
- * Returns true if the date is Thursday.
5536
+ * Returns +true+ if +self+ is a Thursday, +false+ otherwise.
5308
5537
  */
5309
5538
  static VALUE
5310
5539
  d_lite_thursday_p(VALUE self)
@@ -5315,9 +5544,9 @@ d_lite_thursday_p(VALUE self)
5315
5544
 
5316
5545
  /*
5317
5546
  * call-seq:
5318
- * d.friday? -> bool
5547
+ * friday? -> true or false
5319
5548
  *
5320
- * Returns true if the date is Friday.
5549
+ * Returns +true+ if +self+ is a Friday, +false+ otherwise.
5321
5550
  */
5322
5551
  static VALUE
5323
5552
  d_lite_friday_p(VALUE self)
@@ -5328,9 +5557,9 @@ d_lite_friday_p(VALUE self)
5328
5557
 
5329
5558
  /*
5330
5559
  * call-seq:
5331
- * d.saturday? -> bool
5560
+ * saturday? -> true or false
5332
5561
  *
5333
- * Returns true if the date is Saturday.
5562
+ * Returns +true+ if +self+ is a Saturday, +false+ otherwise.
5334
5563
  */
5335
5564
  static VALUE
5336
5565
  d_lite_saturday_p(VALUE self)
@@ -5340,6 +5569,7 @@ d_lite_saturday_p(VALUE self)
5340
5569
  }
5341
5570
 
5342
5571
  #ifndef NDEBUG
5572
+ /* :nodoc: */
5343
5573
  static VALUE
5344
5574
  d_lite_nth_kday_p(VALUE self, VALUE n, VALUE k)
5345
5575
  {
@@ -5361,11 +5591,12 @@ d_lite_nth_kday_p(VALUE self, VALUE n, VALUE k)
5361
5591
 
5362
5592
  /*
5363
5593
  * call-seq:
5364
- * d.hour -> fixnum
5594
+ * hour -> integer
5595
+ *
5596
+ * Returns the hour in range (0..23):
5365
5597
  *
5366
- * Returns the hour (0-23).
5598
+ * DateTime.new(2001, 2, 3, 4, 5, 6).hour # => 4
5367
5599
  *
5368
- * DateTime.new(2001,2,3,4,5,6).hour #=> 4
5369
5600
  */
5370
5601
  static VALUE
5371
5602
  d_lite_hour(VALUE self)
@@ -5376,12 +5607,13 @@ d_lite_hour(VALUE self)
5376
5607
 
5377
5608
  /*
5378
5609
  * call-seq:
5379
- * d.min -> fixnum
5380
- * d.minute -> fixnum
5610
+ * min -> integer
5611
+ *
5612
+ * Returns the minute in range (0..59):
5381
5613
  *
5382
- * Returns the minute (0-59).
5614
+ * DateTime.new(2001, 2, 3, 4, 5, 6).min # => 5
5383
5615
  *
5384
- * DateTime.new(2001,2,3,4,5,6).min #=> 5
5616
+ * Date#minute is an alias for Date#min.
5385
5617
  */
5386
5618
  static VALUE
5387
5619
  d_lite_min(VALUE self)
@@ -5392,12 +5624,13 @@ d_lite_min(VALUE self)
5392
5624
 
5393
5625
  /*
5394
5626
  * call-seq:
5395
- * d.sec -> fixnum
5396
- * d.second -> fixnum
5627
+ * sec -> integer
5397
5628
  *
5398
- * Returns the second (0-59).
5629
+ * Returns the second in range (0..59):
5399
5630
  *
5400
- * DateTime.new(2001,2,3,4,5,6).sec #=> 6
5631
+ * DateTime.new(2001, 2, 3, 4, 5, 6).sec # => 6
5632
+ *
5633
+ * Date#second is an alias for Date#sec.
5401
5634
  */
5402
5635
  static VALUE
5403
5636
  d_lite_sec(VALUE self)
@@ -5408,12 +5641,14 @@ d_lite_sec(VALUE self)
5408
5641
 
5409
5642
  /*
5410
5643
  * call-seq:
5411
- * d.sec_fraction -> rational
5412
- * d.second_fraction -> rational
5644
+ * sec_fraction -> rational
5645
+ *
5646
+ * Returns the fractional part of the second in range
5647
+ * (Rational(0, 1)...Rational(1, 1)):
5413
5648
  *
5414
- * Returns the fractional part of the second.
5649
+ * DateTime.new(2001, 2, 3, 4, 5, 6.5).sec_fraction # => (1/2)
5415
5650
  *
5416
- * DateTime.new(2001,2,3,4,5,6.5).sec_fraction #=> (1/2)
5651
+ * Date#second_fraction is an alias for Date#sec_fraction.
5417
5652
  */
5418
5653
  static VALUE
5419
5654
  d_lite_sec_fraction(VALUE self)
@@ -5454,12 +5689,14 @@ d_lite_zone(VALUE self)
5454
5689
 
5455
5690
  /*
5456
5691
  * call-seq:
5457
- * d.julian? -> bool
5692
+ * d.julian? -> true or false
5458
5693
  *
5459
- * Returns true if the date is before the day of calendar reform.
5694
+ * Returns +true+ if the date is before the date of calendar reform,
5695
+ * +false+ otherwise:
5696
+ *
5697
+ * (Date.new(1582, 10, 15) - 1).julian? # => true
5698
+ * Date.new(1582, 10, 15).julian? # => false
5460
5699
  *
5461
- * Date.new(1582,10,15).julian? #=> false
5462
- * (Date.new(1582,10,15) - 1).julian? #=> true
5463
5700
  */
5464
5701
  static VALUE
5465
5702
  d_lite_julian_p(VALUE self)
@@ -5470,12 +5707,14 @@ d_lite_julian_p(VALUE self)
5470
5707
 
5471
5708
  /*
5472
5709
  * call-seq:
5473
- * d.gregorian? -> bool
5710
+ * gregorian? -> true or false
5711
+ *
5712
+ * Returns +true+ if the date is on or after
5713
+ * the date of calendar reform, +false+ otherwise:
5474
5714
  *
5475
- * Returns true if the date is on or after the day of calendar reform.
5715
+ * Date.new(1582, 10, 15).gregorian? # => true
5716
+ * (Date.new(1582, 10, 15) - 1).gregorian? # => false
5476
5717
  *
5477
- * Date.new(1582,10,15).gregorian? #=> true
5478
- * (Date.new(1582,10,15) - 1).gregorian? #=> false
5479
5718
  */
5480
5719
  static VALUE
5481
5720
  d_lite_gregorian_p(VALUE self)
@@ -5486,12 +5725,13 @@ d_lite_gregorian_p(VALUE self)
5486
5725
 
5487
5726
  /*
5488
5727
  * call-seq:
5489
- * d.leap? -> bool
5728
+ * leap? -> true or false
5729
+ *
5730
+ * Returns +true+ if the year is a leap year, +false+ otherwise:
5490
5731
  *
5491
- * Returns true if the year is a leap year.
5732
+ * Date.new(2000).leap? # => true
5733
+ * Date.new(2001).leap? # => false
5492
5734
  *
5493
- * Date.new(2000).leap? #=> true
5494
- * Date.new(2001).leap? #=> false
5495
5735
  */
5496
5736
  static VALUE
5497
5737
  d_lite_leap_p(VALUE self)
@@ -5510,12 +5750,25 @@ d_lite_leap_p(VALUE self)
5510
5750
 
5511
5751
  /*
5512
5752
  * call-seq:
5513
- * d.start -> float
5753
+ * start -> float
5754
+ *
5755
+ * Returns the Julian start date for calendar reform;
5756
+ * if not an infinity, the returned value is suitable
5757
+ * for passing to Date#jd:
5758
+ *
5759
+ * d = Date.new(2001, 2, 3, Date::ITALY)
5760
+ * s = d.start # => 2299161.0
5761
+ * Date.jd(s).to_s # => "1582-10-15"
5762
+ *
5763
+ * d = Date.new(2001, 2, 3, Date::ENGLAND)
5764
+ * s = d.start # => 2361222.0
5765
+ * Date.jd(s).to_s # => "1752-09-14"
5514
5766
  *
5515
- * Returns the Julian day number denoting the day of calendar reform.
5767
+ * Date.new(2001, 2, 3, Date::GREGORIAN).start # => -Infinity
5768
+ * Date.new(2001, 2, 3, Date::JULIAN).start # => Infinity
5769
+ *
5770
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5516
5771
  *
5517
- * Date.new(2001,2,3).start #=> 2299161.0
5518
- * Date.new(2001,2,3,Date::GREGORIAN).start #=> -Infinity
5519
5772
  */
5520
5773
  static VALUE
5521
5774
  d_lite_start(VALUE self)
@@ -5580,12 +5833,17 @@ dup_obj_with_new_start(VALUE obj, double sg)
5580
5833
 
5581
5834
  /*
5582
5835
  * call-seq:
5583
- * d.new_start([start=Date::ITALY]) -> date
5836
+ * new_start(start = Date::ITALY]) -> new_date
5837
+ *
5838
+ * Returns a copy of +self+ with the given +start+ value:
5839
+ *
5840
+ * d0 = Date.new(2000, 2, 3)
5841
+ * d0.julian? # => false
5842
+ * d1 = d0.new_start(Date::JULIAN)
5843
+ * d1.julian? # => true
5584
5844
  *
5585
- * Duplicates self and resets its day of calendar reform.
5845
+ * See argument {start}[rdoc-ref:calendars.rdoc@Argument+start].
5586
5846
  *
5587
- * d = Date.new(1582,10,15)
5588
- * d.new_start(Date::JULIAN) #=> #<Date: 1582-10-05 ...>
5589
5847
  */
5590
5848
  static VALUE
5591
5849
  d_lite_new_start(int argc, VALUE *argv, VALUE self)
@@ -5604,9 +5862,10 @@ d_lite_new_start(int argc, VALUE *argv, VALUE self)
5604
5862
 
5605
5863
  /*
5606
5864
  * call-seq:
5607
- * d.italy -> date
5865
+ * italy -> new_date
5866
+ *
5867
+ * Equivalent to Date#new_start with argument Date::ITALY.
5608
5868
  *
5609
- * This method is equivalent to new_start(Date::ITALY).
5610
5869
  */
5611
5870
  static VALUE
5612
5871
  d_lite_italy(VALUE self)
@@ -5616,9 +5875,9 @@ d_lite_italy(VALUE self)
5616
5875
 
5617
5876
  /*
5618
5877
  * call-seq:
5619
- * d.england -> date
5878
+ * england -> new_date
5620
5879
  *
5621
- * This method is equivalent to new_start(Date::ENGLAND).
5880
+ * Equivalent to Date#new_start with argument Date::ENGLAND.
5622
5881
  */
5623
5882
  static VALUE
5624
5883
  d_lite_england(VALUE self)
@@ -5628,9 +5887,9 @@ d_lite_england(VALUE self)
5628
5887
 
5629
5888
  /*
5630
5889
  * call-seq:
5631
- * d.julian -> date
5890
+ * julian -> new_date
5632
5891
  *
5633
- * This method is equivalent to new_start(Date::JULIAN).
5892
+ * Equivalent to Date#new_start with argument Date::JULIAN.
5634
5893
  */
5635
5894
  static VALUE
5636
5895
  d_lite_julian(VALUE self)
@@ -5640,9 +5899,9 @@ d_lite_julian(VALUE self)
5640
5899
 
5641
5900
  /*
5642
5901
  * call-seq:
5643
- * d.gregorian -> date
5902
+ * gregorian -> new_date
5644
5903
  *
5645
- * This method is equivalent to new_start(Date::GREGORIAN).
5904
+ * Equivalent to Date#new_start with argument Date::GREGORIAN.
5646
5905
  */
5647
5906
  static VALUE
5648
5907
  d_lite_gregorian(VALUE self)
@@ -6123,9 +6382,9 @@ d_lite_minus(VALUE self, VALUE other)
6123
6382
 
6124
6383
  /*
6125
6384
  * call-seq:
6126
- * d.next_day([n=1]) -> date
6385
+ * next_day(n = 1) -> new_date
6127
6386
  *
6128
- * This method is equivalent to d + n.
6387
+ * Equivalent to Date#+ with argument +n+.
6129
6388
  */
6130
6389
  static VALUE
6131
6390
  d_lite_next_day(int argc, VALUE *argv, VALUE self)
@@ -6140,9 +6399,9 @@ d_lite_next_day(int argc, VALUE *argv, VALUE self)
6140
6399
 
6141
6400
  /*
6142
6401
  * call-seq:
6143
- * d.prev_day([n=1]) -> date
6402
+ * prev_day(n = 1) -> new_date
6144
6403
  *
6145
- * This method is equivalent to d - n.
6404
+ * Equivalent to Date#- with argument +n+.
6146
6405
  */
6147
6406
  static VALUE
6148
6407
  d_lite_prev_day(int argc, VALUE *argv, VALUE self)
@@ -6157,10 +6416,15 @@ d_lite_prev_day(int argc, VALUE *argv, VALUE self)
6157
6416
 
6158
6417
  /*
6159
6418
  * call-seq:
6160
- * d.succ -> date
6161
- * d.next -> date
6419
+ * d.next -> new_date
6420
+ *
6421
+ * Returns a new \Date object representing the following day:
6162
6422
  *
6163
- * Returns a date object denoting the following day.
6423
+ * d = Date.new(2001, 2, 3)
6424
+ * d.to_s # => "2001-02-03"
6425
+ * d.next.to_s # => "2001-02-04"
6426
+ *
6427
+ * Date#succ is an alias for Date#next.
6164
6428
  */
6165
6429
  static VALUE
6166
6430
  d_lite_next(VALUE self)
@@ -6170,26 +6434,30 @@ d_lite_next(VALUE self)
6170
6434
 
6171
6435
  /*
6172
6436
  * call-seq:
6173
- * d >> n -> date
6437
+ * d >> n -> new_date
6438
+ *
6439
+ * Returns a new \Date object representing the date
6440
+ * +n+ months later; +n+ should be a numeric:
6174
6441
  *
6175
- * Returns a date object pointing +n+ months after self.
6176
- * The argument +n+ should be a numeric value.
6442
+ * (Date.new(2001, 2, 3) >> 1).to_s # => "2001-03-03"
6443
+ * (Date.new(2001, 2, 3) >> -2).to_s # => "2000-12-03"
6177
6444
  *
6178
- * Date.new(2001,2,3) >> 1 #=> #<Date: 2001-03-03 ...>
6179
- * Date.new(2001,2,3) >> -2 #=> #<Date: 2000-12-03 ...>
6445
+ * When the same day does not exist for the new month,
6446
+ * the last day of that month is used instead:
6180
6447
  *
6181
- * When the same day does not exist for the corresponding month,
6182
- * the last day of the month is used instead:
6448
+ * (Date.new(2001, 1, 31) >> 1).to_s # => "2001-02-28"
6449
+ * (Date.new(2001, 1, 31) >> -4).to_s # => "2000-09-30"
6183
6450
  *
6184
- * Date.new(2001,1,28) >> 1 #=> #<Date: 2001-02-28 ...>
6185
- * Date.new(2001,1,31) >> 1 #=> #<Date: 2001-02-28 ...>
6451
+ * This results in the following, possibly unexpected, behaviors:
6186
6452
  *
6187
- * This also results in the following, possibly unexpected, behavior:
6453
+ * d0 = Date.new(2001, 1, 31)
6454
+ * d1 = d0 >> 1 # => #<Date: 2001-02-28>
6455
+ * d2 = d1 >> 1 # => #<Date: 2001-03-28>
6188
6456
  *
6189
- * Date.new(2001,1,31) >> 2 #=> #<Date: 2001-03-31 ...>
6190
- * Date.new(2001,1,31) >> 1 >> 1 #=> #<Date: 2001-03-28 ...>
6457
+ * d0 = Date.new(2001, 1, 31)
6458
+ * d1 = d0 >> 1 # => #<Date: 2001-02-28>
6459
+ * d2 = d1 >> -1 # => #<Date: 2001-01-28>
6191
6460
  *
6192
- * Date.new(2001,1,31) >> 1 >> -1 #=> #<Date: 2001-01-28 ...>
6193
6461
  */
6194
6462
  static VALUE
6195
6463
  d_lite_rshift(VALUE self, VALUE other)
@@ -6234,24 +6502,28 @@ d_lite_rshift(VALUE self, VALUE other)
6234
6502
  * call-seq:
6235
6503
  * d << n -> date
6236
6504
  *
6237
- * Returns a date object pointing +n+ months before self.
6238
- * The argument +n+ should be a numeric value.
6505
+ * Returns a new \Date object representing the date
6506
+ * +n+ months earlier; +n+ should be a numeric:
6507
+ *
6508
+ * (Date.new(2001, 2, 3) << 1).to_s # => "2001-01-03"
6509
+ * (Date.new(2001, 2, 3) << -2).to_s # => "2001-04-03"
6239
6510
  *
6240
- * Date.new(2001,2,3) << 1 #=> #<Date: 2001-01-03 ...>
6241
- * Date.new(2001,2,3) << -2 #=> #<Date: 2001-04-03 ...>
6511
+ * When the same day does not exist for the new month,
6512
+ * the last day of that month is used instead:
6242
6513
  *
6243
- * When the same day does not exist for the corresponding month,
6244
- * the last day of the month is used instead:
6514
+ * (Date.new(2001, 3, 31) << 1).to_s # => "2001-02-28"
6515
+ * (Date.new(2001, 3, 31) << -6).to_s # => "2001-09-30"
6245
6516
  *
6246
- * Date.new(2001,3,28) << 1 #=> #<Date: 2001-02-28 ...>
6247
- * Date.new(2001,3,31) << 1 #=> #<Date: 2001-02-28 ...>
6517
+ * This results in the following, possibly unexpected, behaviors:
6248
6518
  *
6249
- * This also results in the following, possibly unexpected, behavior:
6519
+ * d0 = Date.new(2001, 3, 31)
6520
+ * d0 << 2 # => #<Date: 2001-01-31>
6521
+ * d0 << 1 << 1 # => #<Date: 2001-01-28>
6250
6522
  *
6251
- * Date.new(2001,3,31) << 2 #=> #<Date: 2001-01-31 ...>
6252
- * Date.new(2001,3,31) << 1 << 1 #=> #<Date: 2001-01-28 ...>
6523
+ * d0 = Date.new(2001, 3, 31)
6524
+ * d1 = d0 << 1 # => #<Date: 2001-02-28>
6525
+ * d2 = d1 << -1 # => #<Date: 2001-03-28>
6253
6526
  *
6254
- * Date.new(2001,3,31) << 1 << -1 #=> #<Date: 2001-03-28 ...>
6255
6527
  */
6256
6528
  static VALUE
6257
6529
  d_lite_lshift(VALUE self, VALUE other)
@@ -6262,11 +6534,9 @@ d_lite_lshift(VALUE self, VALUE other)
6262
6534
 
6263
6535
  /*
6264
6536
  * call-seq:
6265
- * d.next_month([n=1]) -> date
6537
+ * next_month(n = 1) -> new_date
6266
6538
  *
6267
- * This method is equivalent to d >> n.
6268
- *
6269
- * See Date#>> for examples.
6539
+ * Equivalent to #>> with argument +n+.
6270
6540
  */
6271
6541
  static VALUE
6272
6542
  d_lite_next_month(int argc, VALUE *argv, VALUE self)
@@ -6281,11 +6551,9 @@ d_lite_next_month(int argc, VALUE *argv, VALUE self)
6281
6551
 
6282
6552
  /*
6283
6553
  * call-seq:
6284
- * d.prev_month([n=1]) -> date
6285
- *
6286
- * This method is equivalent to d << n.
6554
+ * prev_month(n = 1) -> new_date
6287
6555
  *
6288
- * See Date#<< for examples.
6556
+ * Equivalent to #<< with argument +n+.
6289
6557
  */
6290
6558
  static VALUE
6291
6559
  d_lite_prev_month(int argc, VALUE *argv, VALUE self)
@@ -6300,15 +6568,9 @@ d_lite_prev_month(int argc, VALUE *argv, VALUE self)
6300
6568
 
6301
6569
  /*
6302
6570
  * call-seq:
6303
- * d.next_year([n=1]) -> date
6304
- *
6305
- * This method is equivalent to d >> (n * 12).
6571
+ * next_year(n = 1) -> new_date
6306
6572
  *
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 ...>
6310
- *
6311
- * See also Date#>>.
6573
+ * Equivalent to #>> with argument <tt>n * 12</tt>.
6312
6574
  */
6313
6575
  static VALUE
6314
6576
  d_lite_next_year(int argc, VALUE *argv, VALUE self)
@@ -6323,15 +6585,9 @@ d_lite_next_year(int argc, VALUE *argv, VALUE self)
6323
6585
 
6324
6586
  /*
6325
6587
  * 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 ...>
6588
+ * prev_year(n = 1) -> new_date
6333
6589
  *
6334
- * See also Date#<<.
6590
+ * Equivalent to #<< with argument <tt>n * 12</tt>.
6335
6591
  */
6336
6592
  static VALUE
6337
6593
  d_lite_prev_year(int argc, VALUE *argv, VALUE self)
@@ -6348,14 +6604,33 @@ static VALUE d_lite_cmp(VALUE, VALUE);
6348
6604
 
6349
6605
  /*
6350
6606
  * call-seq:
6351
- * d.step(limit[, step=1]) -> enumerator
6352
- * d.step(limit[, step=1]){|date| ...} -> self
6607
+ * step(limit, step = 1){|date| ... } -> self
6608
+ *
6609
+ * Calls the block with specified dates;
6610
+ * returns +self+.
6611
+ *
6612
+ * - The first +date+ is +self+.
6613
+ * - Each successive +date+ is <tt>date + step</tt>,
6614
+ * where +step+ is the numeric step size in days.
6615
+ * - The last date is the last one that is before or equal to +limit+,
6616
+ * which should be a \Date object.
6353
6617
  *
6354
- * Iterates evaluation of the given block, which takes a date object.
6355
- * The limit should be a date object.
6618
+ * Example:
6356
6619
  *
6357
- * Date.new(2001).step(Date.new(2001,-1,-1)).select{|d| d.sunday?}.size
6358
- * #=> 52
6620
+ * limit = Date.new(2001, 12, 31)
6621
+ * Date.new(2001).step(limit){|date| p date.to_s if date.mday == 31 }
6622
+ *
6623
+ * Output:
6624
+ *
6625
+ * "2001-01-31"
6626
+ * "2001-03-31"
6627
+ * "2001-05-31"
6628
+ * "2001-07-31"
6629
+ * "2001-08-31"
6630
+ * "2001-10-31"
6631
+ * "2001-12-31"
6632
+ *
6633
+ * Returns an Enumerator if no block is given.
6359
6634
  */
6360
6635
  static VALUE
6361
6636
  d_lite_step(int argc, VALUE *argv, VALUE self)
@@ -6398,10 +6673,9 @@ d_lite_step(int argc, VALUE *argv, VALUE self)
6398
6673
 
6399
6674
  /*
6400
6675
  * call-seq:
6401
- * d.upto(max) -> enumerator
6402
- * d.upto(max){|date| ...} -> self
6676
+ * upto(max){|date| ... } -> self
6403
6677
  *
6404
- * This method is equivalent to step(max, 1){|date| ...}.
6678
+ * Equivalent to #step with arguments +max+ and +1+.
6405
6679
  */
6406
6680
  static VALUE
6407
6681
  d_lite_upto(VALUE self, VALUE max)
@@ -6420,10 +6694,9 @@ d_lite_upto(VALUE self, VALUE max)
6420
6694
 
6421
6695
  /*
6422
6696
  * call-seq:
6423
- * d.downto(min) -> enumerator
6424
- * d.downto(min){|date| ...} -> self
6697
+ * downto(min){|date| ... } -> self
6425
6698
  *
6426
- * This method is equivalent to step(min, -1){|date| ...}.
6699
+ * Equivalent to #step with arguments +min+ and <tt>-1</tt>.
6427
6700
  */
6428
6701
  static VALUE
6429
6702
  d_lite_downto(VALUE self, VALUE min)
@@ -6511,19 +6784,43 @@ cmp_dd(VALUE self, VALUE other)
6511
6784
 
6512
6785
  /*
6513
6786
  * call-seq:
6514
- * d <=> other -> -1, 0, +1 or nil
6787
+ * self <=> other -> -1, 0, 1 or nil
6788
+ *
6789
+ * Compares +self+ and +other+, returning:
6790
+ *
6791
+ * - <tt>-1</tt> if +other+ is larger.
6792
+ * - <tt>0</tt> if the two are equal.
6793
+ * - <tt>1</tt> if +other+ is smaller.
6794
+ * - +nil+ if the two are incomparable.
6795
+ *
6796
+ * Argument +other+ may be:
6797
+ *
6798
+ * - Another \Date object:
6799
+ *
6800
+ * d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
6801
+ * prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
6802
+ * next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
6803
+ * d <=> next_date # => -1
6804
+ * d <=> d # => 0
6805
+ * d <=> prev_date # => 1
6806
+ *
6807
+ * - A DateTime object:
6808
+ *
6809
+ * d <=> DateTime.new(2022, 7, 26) # => 1
6810
+ * d <=> DateTime.new(2022, 7, 27) # => 0
6811
+ * d <=> DateTime.new(2022, 7, 28) # => -1
6812
+ *
6813
+ * - A numeric (compares <tt>self.ajd</tt> to +other+):
6515
6814
  *
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.
6815
+ * d <=> 2459788 # => -1
6816
+ * d <=> 2459787 # => 1
6817
+ * d <=> 2459786 # => 1
6818
+ * d <=> d.ajd # => 0
6519
6819
  *
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
6820
+ * - Any other object:
6821
+ *
6822
+ * d <=> Object.new # => nil
6525
6823
  *
6526
- * See also Comparable.
6527
6824
  */
6528
6825
  static VALUE
6529
6826
  d_lite_cmp(VALUE self, VALUE other)
@@ -6583,20 +6880,39 @@ equal_gen(VALUE self, VALUE other)
6583
6880
 
6584
6881
  /*
6585
6882
  * 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
6883
+ * self === other -> true, false, or nil.
6884
+ *
6885
+ * Returns +true+ if +self+ and +other+ represent the same date,
6886
+ * +false+ if not, +nil+ if the two are not comparable.
6887
+ *
6888
+ * Argument +other+ may be:
6889
+ *
6890
+ * - Another \Date object:
6891
+ *
6892
+ * d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
6893
+ * prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
6894
+ * next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
6895
+ * d === prev_date # => false
6896
+ * d === d # => true
6897
+ * d === next_date # => false
6898
+ *
6899
+ * - A DateTime object:
6900
+ *
6901
+ * d === DateTime.new(2022, 7, 26) # => false
6902
+ * d === DateTime.new(2022, 7, 27) # => true
6903
+ * d === DateTime.new(2022, 7, 28) # => false
6904
+ *
6905
+ * - A numeric (compares <tt>self.jd</tt> to +other+):
6906
+ *
6907
+ * d === 2459788 # => true
6908
+ * d === 2459787 # => false
6909
+ * d === 2459786 # => false
6910
+ * d === d.jd # => true
6911
+ *
6912
+ * - An object not comparable:
6913
+ *
6914
+ * d === Object.new # => nil
6915
+ *
6600
6916
  */
6601
6917
  static VALUE
6602
6918
  d_lite_equal(VALUE self, VALUE other)
@@ -6659,12 +6975,14 @@ static VALUE strftimev(const char *, VALUE,
6659
6975
 
6660
6976
  /*
6661
6977
  * call-seq:
6662
- * d.to_s -> string
6978
+ * to_s -> string
6663
6979
  *
6664
- * Returns a string in an ISO 8601 format. (This method doesn't use the
6665
- * expanded representations.)
6980
+ * Returns a string representation of the date in +self+
6981
+ * in {ISO 8601 extended date format}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-ISO+8601+Format+Specifications]
6982
+ * (<tt>'%Y-%m-%d'</tt>):
6983
+ *
6984
+ * Date.new(2001, 2, 3).to_s # => "2001-02-03"
6666
6985
  *
6667
- * Date.new(2001,2,3).to_s #=> "2001-02-03"
6668
6986
  */
6669
6987
  static VALUE
6670
6988
  d_lite_to_s(VALUE self)
@@ -6673,6 +6991,7 @@ d_lite_to_s(VALUE self)
6673
6991
  }
6674
6992
 
6675
6993
  #ifndef NDEBUG
6994
+ /* :nodoc: */
6676
6995
  static VALUE
6677
6996
  mk_inspect_raw(union DateData *x, VALUE klass)
6678
6997
  {
@@ -6722,6 +7041,7 @@ mk_inspect_raw(union DateData *x, VALUE klass)
6722
7041
  }
6723
7042
  }
6724
7043
 
7044
+ /* :nodoc: */
6725
7045
  static VALUE
6726
7046
  d_lite_inspect_raw(VALUE self)
6727
7047
  {
@@ -6743,14 +7063,13 @@ mk_inspect(union DateData *x, VALUE klass, VALUE to_s)
6743
7063
 
6744
7064
  /*
6745
7065
  * call-seq:
6746
- * d.inspect -> string
7066
+ * inspect -> string
7067
+ *
7068
+ * Returns a string representation of +self+:
6747
7069
  *
6748
- * Returns the value as a string for inspection.
7070
+ * Date.new(2001, 2, 3).inspect
7071
+ * # => "#<Date: 2001-02-03 ((2451944j,0s,0n),+0s,2299161j)>"
6749
7072
  *
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
7073
  */
6755
7074
  static VALUE
6756
7075
  d_lite_inspect(VALUE self)
@@ -6932,180 +7251,16 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
6932
7251
 
6933
7252
  /*
6934
7253
  * 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.
7254
+ * strftime(format = '%F') -> string
7255
+ *
7256
+ * Returns a string representation of the date in +self+,
7257
+ * formatted according the given +format+:
7258
+ *
7259
+ * Date.new(2001, 2, 3).strftime # => "2001-02-03"
7260
+ *
7261
+ * For other formats, see
7262
+ * {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html].
7263
+ *
7109
7264
  */
7110
7265
  static VALUE
7111
7266
  d_lite_strftime(int argc, VALUE *argv, VALUE self)
@@ -7133,13 +7288,17 @@ strftimev(const char *fmt, VALUE self,
7133
7288
 
7134
7289
  /*
7135
7290
  * call-seq:
7136
- * d.asctime -> string
7137
- * d.ctime -> string
7291
+ * asctime -> string
7292
+ *
7293
+ * Equivalent to #strftime with argument <tt>'%a %b %e %T %Y'</tt>
7294
+ * (or its {shorthand form}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Shorthand+Conversion+Specifiers]
7295
+ * <tt>'%c'</tt>):
7296
+ *
7297
+ * Date.new(2001, 2, 3).asctime # => "Sat Feb 3 00:00:00 2001"
7138
7298
  *
7139
- * Returns a string in asctime(3) format (but without "\n\0" at the
7140
- * end). This method is equivalent to strftime('%c').
7299
+ * See {asctime}[https://linux.die.net/man/3/asctime].
7141
7300
  *
7142
- * See also asctime(3) or ctime(3).
7301
+ * Date#ctime is an alias for Date#asctime.
7143
7302
  */
7144
7303
  static VALUE
7145
7304
  d_lite_asctime(VALUE self)
@@ -7149,10 +7308,15 @@ d_lite_asctime(VALUE self)
7149
7308
 
7150
7309
  /*
7151
7310
  * call-seq:
7152
- * d.iso8601 -> string
7153
- * d.xmlschema -> string
7311
+ * iso8601 -> string
7312
+ *
7313
+ * Equivalent to #strftime with argument <tt>'%Y-%m-%d'</tt>
7314
+ * (or its {shorthand form}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Shorthand+Conversion+Specifiers]
7315
+ * <tt>'%F'</tt>);
7316
+ *
7317
+ * Date.new(2001, 2, 3).iso8601 # => "2001-02-03"
7154
7318
  *
7155
- * This method is equivalent to strftime('%F').
7319
+ * Date#xmlschema is an alias for Date#iso8601.
7156
7320
  */
7157
7321
  static VALUE
7158
7322
  d_lite_iso8601(VALUE self)
@@ -7162,9 +7326,13 @@ d_lite_iso8601(VALUE self)
7162
7326
 
7163
7327
  /*
7164
7328
  * call-seq:
7165
- * d.rfc3339 -> string
7329
+ * rfc3339 -> string
7330
+ *
7331
+ * Equivalent to #strftime with argument <tt>'%FT%T%:z'</tt>;
7332
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7333
+ *
7334
+ * Date.new(2001, 2, 3).rfc3339 # => "2001-02-03T00:00:00+00:00"
7166
7335
  *
7167
- * This method is equivalent to strftime('%FT%T%:z').
7168
7336
  */
7169
7337
  static VALUE
7170
7338
  d_lite_rfc3339(VALUE self)
@@ -7174,10 +7342,14 @@ d_lite_rfc3339(VALUE self)
7174
7342
 
7175
7343
  /*
7176
7344
  * call-seq:
7177
- * d.rfc2822 -> string
7178
- * d.rfc822 -> string
7345
+ * rfc2822 -> string
7346
+ *
7347
+ * Equivalent to #strftime with argument <tt>'%a, %-d %b %Y %T %z'</tt>;
7348
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7349
+ *
7350
+ * Date.new(2001, 2, 3).rfc2822 # => "Sat, 3 Feb 2001 00:00:00 +0000"
7179
7351
  *
7180
- * This method is equivalent to strftime('%a, %-d %b %Y %T %z').
7352
+ * Date#rfc822 is an alias for Date#rfc2822.
7181
7353
  */
7182
7354
  static VALUE
7183
7355
  d_lite_rfc2822(VALUE self)
@@ -7187,10 +7359,13 @@ d_lite_rfc2822(VALUE self)
7187
7359
 
7188
7360
  /*
7189
7361
  * call-seq:
7190
- * d.httpdate -> string
7362
+ * httpdate -> string
7363
+ *
7364
+ * Equivalent to #strftime with argument <tt>'%a, %d %b %Y %T GMT'</tt>;
7365
+ * see {Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html]:
7366
+ *
7367
+ * Date.new(2001, 2, 3).httpdate # => "Sat, 03 Feb 2001 00:00:00 GMT"
7191
7368
  *
7192
- * This method is equivalent to strftime('%a, %d %b %Y %T GMT').
7193
- * See also RFC 2616.
7194
7369
  */
7195
7370
  static VALUE
7196
7371
  d_lite_httpdate(VALUE self)
@@ -7241,11 +7416,13 @@ jisx0301_date_format(char *fmt, size_t size, VALUE jd, VALUE y)
7241
7416
 
7242
7417
  /*
7243
7418
  * call-seq:
7244
- * d.jisx0301 -> string
7419
+ * jisx0301 -> string
7245
7420
  *
7246
- * Returns a string in a JIS X 0301 format.
7421
+ * Returns a string representation of the date in +self+
7422
+ * in JIS X 0301 format.
7423
+ *
7424
+ * Date.new(2001, 2, 3).jisx0301 # => "H13.02.03"
7247
7425
  *
7248
- * Date.new(2001,2,3).jisx0301 #=> "H13.02.03"
7249
7426
  */
7250
7427
  static VALUE
7251
7428
  d_lite_jisx0301(VALUE self)
@@ -7260,7 +7437,98 @@ d_lite_jisx0301(VALUE self)
7260
7437
  return strftimev(fmt, self, set_tmx);
7261
7438
  }
7262
7439
 
7440
+ static VALUE
7441
+ deconstruct_keys(VALUE self, VALUE keys, int is_datetime)
7442
+ {
7443
+ VALUE h = rb_hash_new();
7444
+ long i;
7445
+
7446
+ get_d1(self);
7447
+
7448
+ if (NIL_P(keys)) {
7449
+ rb_hash_aset(h, sym_year, m_real_year(dat));
7450
+ rb_hash_aset(h, sym_month, INT2FIX(m_mon(dat)));
7451
+ rb_hash_aset(h, sym_day, INT2FIX(m_mday(dat)));
7452
+ rb_hash_aset(h, sym_yday, INT2FIX(m_yday(dat)));
7453
+ rb_hash_aset(h, sym_wday, INT2FIX(m_wday(dat)));
7454
+ if (is_datetime) {
7455
+ rb_hash_aset(h, sym_hour, INT2FIX(m_hour(dat)));
7456
+ rb_hash_aset(h, sym_min, INT2FIX(m_min(dat)));
7457
+ rb_hash_aset(h, sym_sec, INT2FIX(m_sec(dat)));
7458
+ rb_hash_aset(h, sym_sec_fraction, m_sf_in_sec(dat));
7459
+ rb_hash_aset(h, sym_zone, m_zone(dat));
7460
+ }
7461
+
7462
+ return h;
7463
+ }
7464
+ if (!RB_TYPE_P(keys, T_ARRAY)) {
7465
+ rb_raise(rb_eTypeError,
7466
+ "wrong argument type %"PRIsVALUE" (expected Array or nil)",
7467
+ rb_obj_class(keys));
7468
+
7469
+ }
7470
+
7471
+ for (i=0; i<RARRAY_LEN(keys); i++) {
7472
+ VALUE key = RARRAY_AREF(keys, i);
7473
+
7474
+ if (sym_year == key) rb_hash_aset(h, key, m_real_year(dat));
7475
+ if (sym_month == key) rb_hash_aset(h, key, INT2FIX(m_mon(dat)));
7476
+ if (sym_day == key) rb_hash_aset(h, key, INT2FIX(m_mday(dat)));
7477
+ if (sym_yday == key) rb_hash_aset(h, key, INT2FIX(m_yday(dat)));
7478
+ if (sym_wday == key) rb_hash_aset(h, key, INT2FIX(m_wday(dat)));
7479
+ if (is_datetime) {
7480
+ if (sym_hour == key) rb_hash_aset(h, key, INT2FIX(m_hour(dat)));
7481
+ if (sym_min == key) rb_hash_aset(h, key, INT2FIX(m_min(dat)));
7482
+ if (sym_sec == key) rb_hash_aset(h, key, INT2FIX(m_sec(dat)));
7483
+ if (sym_sec_fraction == key) rb_hash_aset(h, key, m_sf_in_sec(dat));
7484
+ if (sym_zone == key) rb_hash_aset(h, key, m_zone(dat));
7485
+ }
7486
+ }
7487
+ return h;
7488
+ }
7489
+
7490
+ /*
7491
+ * call-seq:
7492
+ * deconstruct_keys(array_of_names_or_nil) -> hash
7493
+ *
7494
+ * Returns a hash of the name/value pairs, to use in pattern matching.
7495
+ * Possible keys are: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>,
7496
+ * <tt>:wday</tt>, <tt>:yday</tt>.
7497
+ *
7498
+ * Possible usages:
7499
+ *
7500
+ * d = Date.new(2022, 10, 5)
7501
+ *
7502
+ * if d in wday: 3, day: ..7 # uses deconstruct_keys underneath
7503
+ * puts "first Wednesday of the month"
7504
+ * end
7505
+ * #=> prints "first Wednesday of the month"
7506
+ *
7507
+ * case d
7508
+ * in year: ...2022
7509
+ * puts "too old"
7510
+ * in month: ..9
7511
+ * puts "quarter 1-3"
7512
+ * in wday: 1..5, month:
7513
+ * puts "working day in month #{month}"
7514
+ * end
7515
+ * #=> prints "working day in month 10"
7516
+ *
7517
+ * Note that deconstruction by pattern can also be combined with class check:
7518
+ *
7519
+ * if d in Date(wday: 3, day: ..7)
7520
+ * puts "first Wednesday of the month"
7521
+ * end
7522
+ *
7523
+ */
7524
+ static VALUE
7525
+ d_lite_deconstruct_keys(VALUE self, VALUE keys)
7526
+ {
7527
+ return deconstruct_keys(self, keys, /* is_datetime=false */ 0);
7528
+ }
7529
+
7263
7530
  #ifndef NDEBUG
7531
+ /* :nodoc: */
7264
7532
  static VALUE
7265
7533
  d_lite_marshal_dump_old(VALUE self)
7266
7534
  {
@@ -7548,17 +7816,7 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass)
7548
7816
  }
7549
7817
 
7550
7818
  /*
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 ...>
7819
+ * Same as DateTime.new.
7562
7820
  */
7563
7821
  static VALUE
7564
7822
  datetime_s_civil(int argc, VALUE *argv, VALUE klass)
@@ -7748,6 +8006,7 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass)
7748
8006
  }
7749
8007
 
7750
8008
  #ifndef NDEBUG
8009
+ /* :nodoc: */
7751
8010
  static VALUE
7752
8011
  datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
7753
8012
  {
@@ -7817,6 +8076,7 @@ datetime_s_weeknum(int argc, VALUE *argv, VALUE klass)
7817
8076
  return ret;
7818
8077
  }
7819
8078
 
8079
+ /* :nodoc: */
7820
8080
  static VALUE
7821
8081
  datetime_s_nth_kday(int argc, VALUE *argv, VALUE klass)
7822
8082
  {
@@ -8162,9 +8422,9 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8162
8422
  * Parses the given representation of date and time, and creates a
8163
8423
  * DateTime object.
8164
8424
  *
8165
- * This method *does not* function as a validator. If the input
8425
+ * This method *does* *not* function as a validator. If the input
8166
8426
  * string does not match valid formats strictly, you may get a cryptic
8167
- * result. Should consider to use `DateTime.strptime` instead of this
8427
+ * result. Should consider to use DateTime.strptime instead of this
8168
8428
  * method as possible.
8169
8429
  *
8170
8430
  * If the optional second argument is true and the detected year is in
@@ -8178,8 +8438,8 @@ datetime_s_strptime(int argc, VALUE *argv, VALUE klass)
8178
8438
  * #=> #<DateTime: 2001-02-03T16:05:06+00:00 ...>
8179
8439
  *
8180
8440
  * 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.
8441
+ * You can stop this check by passing <code>limit: nil</code>, but note
8442
+ * that it may take a long time to parse.
8183
8443
  */
8184
8444
  static VALUE
8185
8445
  datetime_s_parse(int argc, VALUE *argv, VALUE klass)
@@ -8200,12 +8460,12 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8200
8460
 
8201
8461
  {
8202
8462
  int argc2 = 2;
8203
- VALUE argv2[3];
8463
+ VALUE argv2[3], hash;
8204
8464
  argv2[0] = str;
8205
8465
  argv2[1] = comp;
8206
8466
  argv2[2] = opt;
8207
8467
  if (!NIL_P(opt)) argc2++;
8208
- VALUE hash = date_s__parse(argc2, argv2, klass);
8468
+ hash = date_s__parse(argc2, argv2, klass);
8209
8469
  return dt_new_by_frags(klass, hash, sg);
8210
8470
  }
8211
8471
  }
@@ -8225,8 +8485,8 @@ datetime_s_parse(int argc, VALUE *argv, VALUE klass)
8225
8485
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8226
8486
  *
8227
8487
  * 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.
8488
+ * You can stop this check by passing <code>limit: nil</code>, but note
8489
+ * that it may take a long time to parse.
8230
8490
  */
8231
8491
  static VALUE
8232
8492
  datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
@@ -8245,11 +8505,11 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8245
8505
 
8246
8506
  {
8247
8507
  int argc2 = 1;
8248
- VALUE argv2[2];
8508
+ VALUE argv2[2], hash;
8249
8509
  argv2[0] = str;
8250
8510
  argv2[1] = opt;
8251
8511
  if (!NIL_P(opt)) argc2--;
8252
- VALUE hash = date_s__iso8601(argc2, argv2, klass);
8512
+ hash = date_s__iso8601(argc2, argv2, klass);
8253
8513
  return dt_new_by_frags(klass, hash, sg);
8254
8514
  }
8255
8515
  }
@@ -8265,8 +8525,8 @@ datetime_s_iso8601(int argc, VALUE *argv, VALUE klass)
8265
8525
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8266
8526
  *
8267
8527
  * 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.
8528
+ * You can stop this check by passing <code>limit: nil</code>, but note
8529
+ * that it may take a long time to parse.
8270
8530
  */
8271
8531
  static VALUE
8272
8532
  datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
@@ -8285,11 +8545,11 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8285
8545
 
8286
8546
  {
8287
8547
  int argc2 = 1;
8288
- VALUE argv2[2];
8548
+ VALUE argv2[2], hash;
8289
8549
  argv2[0] = str;
8290
8550
  argv2[1] = opt;
8291
8551
  if (!NIL_P(opt)) argc2++;
8292
- VALUE hash = date_s__rfc3339(argc2, argv2, klass);
8552
+ hash = date_s__rfc3339(argc2, argv2, klass);
8293
8553
  return dt_new_by_frags(klass, hash, sg);
8294
8554
  }
8295
8555
  }
@@ -8305,8 +8565,8 @@ datetime_s_rfc3339(int argc, VALUE *argv, VALUE klass)
8305
8565
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8306
8566
  *
8307
8567
  * 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.
8568
+ * You can stop this check by passing <code>limit: nil</code>, but note
8569
+ * that it may take a long time to parse.
8310
8570
  */
8311
8571
  static VALUE
8312
8572
  datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
@@ -8325,11 +8585,11 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8325
8585
 
8326
8586
  {
8327
8587
  int argc2 = 1;
8328
- VALUE argv2[2];
8588
+ VALUE argv2[2], hash;
8329
8589
  argv2[0] = str;
8330
8590
  argv2[1] = opt;
8331
8591
  if (!NIL_P(opt)) argc2++;
8332
- VALUE hash = date_s__xmlschema(argc2, argv2, klass);
8592
+ hash = date_s__xmlschema(argc2, argv2, klass);
8333
8593
  return dt_new_by_frags(klass, hash, sg);
8334
8594
  }
8335
8595
  }
@@ -8346,8 +8606,8 @@ datetime_s_xmlschema(int argc, VALUE *argv, VALUE klass)
8346
8606
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8347
8607
  *
8348
8608
  * 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.
8609
+ * You can stop this check by passing <code>limit: nil</code>, but note
8610
+ * that it may take a long time to parse.
8351
8611
  */
8352
8612
  static VALUE
8353
8613
  datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
@@ -8366,11 +8626,11 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8366
8626
 
8367
8627
  {
8368
8628
  int argc2 = 1;
8369
- VALUE argv2[2];
8629
+ VALUE argv2[2], hash;
8370
8630
  argv2[0] = str;
8371
8631
  argv2[1] = opt;
8372
8632
  if (!NIL_P(opt)) argc2++;
8373
- VALUE hash = date_s__rfc2822(argc2, argv2, klass);
8633
+ hash = date_s__rfc2822(argc2, argv2, klass);
8374
8634
  return dt_new_by_frags(klass, hash, sg);
8375
8635
  }
8376
8636
  }
@@ -8386,8 +8646,8 @@ datetime_s_rfc2822(int argc, VALUE *argv, VALUE klass)
8386
8646
  * #=> #<DateTime: 2001-02-03T04:05:06+00:00 ...>
8387
8647
  *
8388
8648
  * 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.
8649
+ * You can stop this check by passing <code>limit: nil</code>, but note
8650
+ * that it may take a long time to parse.
8391
8651
  */
8392
8652
  static VALUE
8393
8653
  datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
@@ -8406,11 +8666,11 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8406
8666
 
8407
8667
  {
8408
8668
  int argc2 = 1;
8409
- VALUE argv2[2];
8669
+ VALUE argv2[2], hash;
8410
8670
  argv2[0] = str;
8411
8671
  argv2[1] = opt;
8412
8672
  if (!NIL_P(opt)) argc2++;
8413
- VALUE hash = date_s__httpdate(argc2, argv2, klass);
8673
+ hash = date_s__httpdate(argc2, argv2, klass);
8414
8674
  return dt_new_by_frags(klass, hash, sg);
8415
8675
  }
8416
8676
  }
@@ -8431,8 +8691,8 @@ datetime_s_httpdate(int argc, VALUE *argv, VALUE klass)
8431
8691
  * #=> #<DateTime: 2001-02-03T04:05:06+07:00 ...>
8432
8692
  *
8433
8693
  * 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.
8694
+ * You can stop this check by passing <code>limit: nil</code>, but note
8695
+ * that it may take a long time to parse.
8436
8696
  */
8437
8697
  static VALUE
8438
8698
  datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
@@ -8451,11 +8711,11 @@ datetime_s_jisx0301(int argc, VALUE *argv, VALUE klass)
8451
8711
 
8452
8712
  {
8453
8713
  int argc2 = 1;
8454
- VALUE argv2[2];
8714
+ VALUE argv2[2], hash;
8455
8715
  argv2[0] = str;
8456
8716
  argv2[1] = opt;
8457
8717
  if (!NIL_P(opt)) argc2++;
8458
- VALUE hash = date_s__jisx0301(argc2, argv2, klass);
8718
+ hash = date_s__jisx0301(argc2, argv2, klass);
8459
8719
  return dt_new_by_frags(klass, hash, sg);
8460
8720
  }
8461
8721
  }
@@ -8478,181 +8738,16 @@ dt_lite_to_s(VALUE self)
8478
8738
 
8479
8739
  /*
8480
8740
  * 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.
8741
+ * strftime(format = '%FT%T%:z') -> string
8742
+ *
8743
+ * Returns a string representation of +self+,
8744
+ * formatted according the given +format:
8745
+ *
8746
+ * DateTime.now.strftime # => "2022-07-01T11:03:19-05:00"
8747
+ *
8748
+ * For other formats, see
8749
+ * {Formats for Dates and Times}[doc/strftime_formatting.rdoc].
8750
+ *
8656
8751
  */
8657
8752
  static VALUE
8658
8753
  dt_lite_strftime(int argc, VALUE *argv, VALUE self)
@@ -8740,6 +8835,47 @@ dt_lite_jisx0301(int argc, VALUE *argv, VALUE self)
8740
8835
  iso8601_timediv(self, n));
8741
8836
  }
8742
8837
 
8838
+ /*
8839
+ * call-seq:
8840
+ * deconstruct_keys(array_of_names_or_nil) -> hash
8841
+ *
8842
+ * Returns a hash of the name/value pairs, to use in pattern matching.
8843
+ * Possible keys are: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>,
8844
+ * <tt>:wday</tt>, <tt>:yday</tt>, <tt>:hour</tt>, <tt>:min</tt>,
8845
+ * <tt>:sec</tt>, <tt>:sec_fraction</tt>, <tt>:zone</tt>.
8846
+ *
8847
+ * Possible usages:
8848
+ *
8849
+ * dt = DateTime.new(2022, 10, 5, 13, 30)
8850
+ *
8851
+ * if d in wday: 1..5, hour: 10..18 # uses deconstruct_keys underneath
8852
+ * puts "Working time"
8853
+ * end
8854
+ * #=> prints "Working time"
8855
+ *
8856
+ * case dt
8857
+ * in year: ...2022
8858
+ * puts "too old"
8859
+ * in month: ..9
8860
+ * puts "quarter 1-3"
8861
+ * in wday: 1..5, month:
8862
+ * puts "working day in month #{month}"
8863
+ * end
8864
+ * #=> prints "working day in month 10"
8865
+ *
8866
+ * Note that deconstruction by pattern can also be combined with class check:
8867
+ *
8868
+ * if d in DateTime(wday: 1..5, hour: 10..18, day: ..7)
8869
+ * puts "Working time, first week of the month"
8870
+ * end
8871
+ *
8872
+ */
8873
+ static VALUE
8874
+ dt_lite_deconstruct_keys(VALUE self, VALUE keys)
8875
+ {
8876
+ return deconstruct_keys(self, keys, /* is_datetime=true */ 1);
8877
+ }
8878
+
8743
8879
  /* conversions */
8744
8880
 
8745
8881
  #define f_subsec(x) rb_funcall(x, rb_intern("subsec"), 0)
@@ -8818,7 +8954,7 @@ time_to_datetime(VALUE self)
8818
8954
  ret = d_complex_new_internal(cDateTime,
8819
8955
  nth, 0,
8820
8956
  0, sf,
8821
- of, DEFAULT_SG,
8957
+ of, GREGORIAN,
8822
8958
  ry, m, d,
8823
8959
  h, min, s,
8824
8960
  HAVE_CIVIL | HAVE_TIME);
@@ -8831,10 +8967,15 @@ time_to_datetime(VALUE self)
8831
8967
 
8832
8968
  /*
8833
8969
  * call-seq:
8834
- * d.to_time -> time
8970
+ * to_time -> time
8971
+ *
8972
+ * Returns a new Time object with the same value as +self+;
8973
+ * if +self+ is a Julian date, derives its Gregorian date
8974
+ * for conversion to the \Time object:
8975
+ *
8976
+ * Date.new(2001, 2, 3).to_time # => 2001-02-03 00:00:00 -0600
8977
+ * Date.new(2001, 2, 3, Date::JULIAN).to_time # => 2001-02-16 00:00:00 -0600
8835
8978
  *
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
8979
  */
8839
8980
  static VALUE
8840
8981
  date_to_time(VALUE self)
@@ -8855,9 +8996,9 @@ date_to_time(VALUE self)
8855
8996
 
8856
8997
  /*
8857
8998
  * call-seq:
8858
- * d.to_date -> self
8999
+ * to_date -> self
8859
9000
  *
8860
- * Returns self.
9001
+ * Returns +self+.
8861
9002
  */
8862
9003
  static VALUE
8863
9004
  date_to_date(VALUE self)
@@ -8869,7 +9010,10 @@ date_to_date(VALUE self)
8869
9010
  * call-seq:
8870
9011
  * d.to_datetime -> datetime
8871
9012
  *
8872
- * Returns a DateTime object which denotes self.
9013
+ * Returns a DateTime whose value is the same as +self+:
9014
+ *
9015
+ * Date.new(2001, 2, 3).to_datetime # => #<DateTime: 2001-02-03T00:00:00+00:00>
9016
+ *
8873
9017
  */
8874
9018
  static VALUE
8875
9019
  date_to_datetime(VALUE self)
@@ -8914,12 +9058,17 @@ date_to_datetime(VALUE self)
8914
9058
  static VALUE
8915
9059
  datetime_to_time(VALUE self)
8916
9060
  {
8917
- volatile VALUE dup = dup_obj(self);
9061
+ get_d1(self);
9062
+
9063
+ if (m_julian_p(dat)) {
9064
+ self = d_lite_gregorian(self);
9065
+ get_d1a(self);
9066
+ dat = adat;
9067
+ }
9068
+
8918
9069
  {
8919
9070
  VALUE t;
8920
9071
 
8921
- get_d1(dup);
8922
-
8923
9072
  t = rb_funcall(rb_cTime,
8924
9073
  rb_intern("new"),
8925
9074
  7,
@@ -8987,6 +9136,7 @@ datetime_to_datetime(VALUE self)
8987
9136
  #define MIN_JD -327
8988
9137
  #define MAX_JD 366963925
8989
9138
 
9139
+ /* :nodoc: */
8990
9140
  static int
8991
9141
  test_civil(int from, int to, double sg)
8992
9142
  {
@@ -9007,6 +9157,7 @@ test_civil(int from, int to, double sg)
9007
9157
  return 1;
9008
9158
  }
9009
9159
 
9160
+ /* :nodoc: */
9010
9161
  static VALUE
9011
9162
  date_s_test_civil(VALUE klass)
9012
9163
  {
@@ -9027,6 +9178,7 @@ date_s_test_civil(VALUE klass)
9027
9178
  return Qtrue;
9028
9179
  }
9029
9180
 
9181
+ /* :nodoc: */
9030
9182
  static int
9031
9183
  test_ordinal(int from, int to, double sg)
9032
9184
  {
@@ -9047,6 +9199,7 @@ test_ordinal(int from, int to, double sg)
9047
9199
  return 1;
9048
9200
  }
9049
9201
 
9202
+ /* :nodoc: */
9050
9203
  static VALUE
9051
9204
  date_s_test_ordinal(VALUE klass)
9052
9205
  {
@@ -9067,6 +9220,7 @@ date_s_test_ordinal(VALUE klass)
9067
9220
  return Qtrue;
9068
9221
  }
9069
9222
 
9223
+ /* :nodoc: */
9070
9224
  static int
9071
9225
  test_commercial(int from, int to, double sg)
9072
9226
  {
@@ -9087,6 +9241,7 @@ test_commercial(int from, int to, double sg)
9087
9241
  return 1;
9088
9242
  }
9089
9243
 
9244
+ /* :nodoc: */
9090
9245
  static VALUE
9091
9246
  date_s_test_commercial(VALUE klass)
9092
9247
  {
@@ -9107,6 +9262,7 @@ date_s_test_commercial(VALUE klass)
9107
9262
  return Qtrue;
9108
9263
  }
9109
9264
 
9265
+ /* :nodoc: */
9110
9266
  static int
9111
9267
  test_weeknum(int from, int to, int f, double sg)
9112
9268
  {
@@ -9127,6 +9283,7 @@ test_weeknum(int from, int to, int f, double sg)
9127
9283
  return 1;
9128
9284
  }
9129
9285
 
9286
+ /* :nodoc: */
9130
9287
  static VALUE
9131
9288
  date_s_test_weeknum(VALUE klass)
9132
9289
  {
@@ -9151,6 +9308,7 @@ date_s_test_weeknum(VALUE klass)
9151
9308
  return Qtrue;
9152
9309
  }
9153
9310
 
9311
+ /* :nodoc: */
9154
9312
  static int
9155
9313
  test_nth_kday(int from, int to, double sg)
9156
9314
  {
@@ -9171,6 +9329,7 @@ test_nth_kday(int from, int to, double sg)
9171
9329
  return 1;
9172
9330
  }
9173
9331
 
9332
+ /* :nodoc: */
9174
9333
  static VALUE
9175
9334
  date_s_test_nth_kday(VALUE klass)
9176
9335
  {
@@ -9191,6 +9350,7 @@ date_s_test_nth_kday(VALUE klass)
9191
9350
  return Qtrue;
9192
9351
  }
9193
9352
 
9353
+ /* :nodoc: */
9194
9354
  static int
9195
9355
  test_unit_v2v(VALUE i,
9196
9356
  VALUE (* conv1)(VALUE),
@@ -9202,6 +9362,7 @@ test_unit_v2v(VALUE i,
9202
9362
  return f_eqeq_p(o, i);
9203
9363
  }
9204
9364
 
9365
+ /* :nodoc: */
9205
9366
  static int
9206
9367
  test_unit_v2v_iter2(VALUE (* conv1)(VALUE),
9207
9368
  VALUE (* conv2)(VALUE))
@@ -9233,6 +9394,7 @@ test_unit_v2v_iter2(VALUE (* conv1)(VALUE),
9233
9394
  return 1;
9234
9395
  }
9235
9396
 
9397
+ /* :nodoc: */
9236
9398
  static int
9237
9399
  test_unit_v2v_iter(VALUE (* conv1)(VALUE),
9238
9400
  VALUE (* conv2)(VALUE))
@@ -9244,6 +9406,7 @@ test_unit_v2v_iter(VALUE (* conv1)(VALUE),
9244
9406
  return 1;
9245
9407
  }
9246
9408
 
9409
+ /* :nodoc: */
9247
9410
  static VALUE
9248
9411
  date_s_test_unit_conv(VALUE klass)
9249
9412
  {
@@ -9258,6 +9421,7 @@ date_s_test_unit_conv(VALUE klass)
9258
9421
  return Qtrue;
9259
9422
  }
9260
9423
 
9424
+ /* :nodoc: */
9261
9425
  static VALUE
9262
9426
  date_s_test_all(VALUE klass)
9263
9427
  {
@@ -9324,6 +9488,7 @@ mk_ary_of_str(long len, const char *a[])
9324
9488
  return o;
9325
9489
  }
9326
9490
 
9491
+ /* :nodoc: */
9327
9492
  static VALUE
9328
9493
  d_lite_zero(VALUE x)
9329
9494
  {
@@ -9341,6 +9506,17 @@ Init_date_core(void)
9341
9506
  id_ge_p = rb_intern_const(">=");
9342
9507
  id_eqeq_p = rb_intern_const("==");
9343
9508
 
9509
+ sym_year = ID2SYM(rb_intern_const("year"));
9510
+ sym_month = ID2SYM(rb_intern_const("month"));
9511
+ sym_yday = ID2SYM(rb_intern_const("yday"));
9512
+ sym_wday = ID2SYM(rb_intern_const("wday"));
9513
+ sym_day = ID2SYM(rb_intern_const("day"));
9514
+ sym_hour = ID2SYM(rb_intern_const("hour"));
9515
+ sym_min = ID2SYM(rb_intern_const("min"));
9516
+ sym_sec = ID2SYM(rb_intern_const("sec"));
9517
+ sym_sec_fraction = ID2SYM(rb_intern_const("sec_fraction"));
9518
+ sym_zone = ID2SYM(rb_intern_const("zone"));
9519
+
9344
9520
  half_days_in_day = rb_rational_new2(INT2FIX(1), INT2FIX(2));
9345
9521
 
9346
9522
  #if (LONG_MAX / DAY_IN_SECONDS) > SECOND_IN_NANOSECONDS
@@ -9361,152 +9537,81 @@ Init_date_core(void)
9361
9537
  negative_inf = -INFINITY;
9362
9538
 
9363
9539
  /*
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.
9540
+ * \Class \Date provides methods for storing and manipulating
9541
+ * calendar dates.
9371
9542
  *
9372
- * === Calendar Date
9543
+ * Consider using
9544
+ * {class Time}[https://docs.ruby-lang.org/en/master/Time.html]
9545
+ * instead of class \Date if:
9373
9546
  *
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.
9547
+ * - You need both dates and times; \Date handles only dates.
9548
+ * - You need only Gregorian dates (and not Julian dates);
9549
+ * see {Julian and Gregorian Calendars}[rdoc-ref:calendars.rdoc].
9377
9550
  *
9378
- * In those classes, this is so-called "civil".
9551
+ * A \Date object, once created, is immutable, and cannot be modified.
9379
9552
  *
9380
- * === Ordinal Date
9553
+ * == Creating a \Date
9381
9554
  *
9382
- * The ordinal date is a particular day of a calendar year identified
9383
- * by its ordinal number within the year.
9555
+ * You can create a date for the current date, using Date.today:
9384
9556
  *
9385
- * In those classes, this is so-called "ordinal".
9557
+ * Date.today # => #<Date: 1999-12-31>
9386
9558
  *
9387
- * === Week Date
9559
+ * You can create a specific date from various combinations of arguments:
9388
9560
  *
9389
- * The week date is a date identified by calendar week and day numbers.
9561
+ * - Date.new takes integer year, month, and day-of-month:
9390
9562
  *
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.
9563
+ * Date.new(1999, 12, 31) # => #<Date: 1999-12-31>
9396
9564
  *
9397
- * In those classes, this is so-called "commercial".
9565
+ * - Date.ordinal takes integer year and day-of-year:
9398
9566
  *
9399
- * === Julian Day Number
9567
+ * Date.ordinal(1999, 365) # => #<Date: 1999-12-31>
9400
9568
  *
9401
- * The Julian day number is in elapsed days since noon (Greenwich Mean
9402
- * Time) on January 1, 4713 BCE (in the Julian calendar).
9569
+ * - Date.jd takes integer Julian day:
9403
9570
  *
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.
9571
+ * Date.jd(2451544) # => #<Date: 1999-12-31>
9408
9572
  *
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.
9573
+ * - Date.commercial takes integer commercial data (year, week, day-of-week):
9412
9574
  *
9413
- * In those classes, those are so-called "ajd" and "jd".
9575
+ * Date.commercial(1999, 52, 5) # => #<Date: 1999-12-31>
9414
9576
  *
9415
- * === Modified Julian Day Number
9577
+ * - Date.parse takes a string, which it parses heuristically:
9416
9578
  *
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).
9579
+ * Date.parse('1999-12-31') # => #<Date: 1999-12-31>
9580
+ * Date.parse('31-12-1999') # => #<Date: 1999-12-31>
9581
+ * Date.parse('1999-365') # => #<Date: 1999-12-31>
9582
+ * Date.parse('1999-W52-5') # => #<Date: 1999-12-31>
9420
9583
  *
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.
9584
+ * - Date.strptime takes a date string and a format string,
9585
+ * then parses the date string according to the format string:
9426
9586
  *
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.
9587
+ * Date.strptime('1999-12-31', '%Y-%m-%d') # => #<Date: 1999-12-31>
9588
+ * Date.strptime('31-12-1999', '%d-%m-%Y') # => #<Date: 1999-12-31>
9589
+ * Date.strptime('1999-365', '%Y-%j') # => #<Date: 1999-12-31>
9590
+ * Date.strptime('1999-W52-5', '%G-W%V-%u') # => #<Date: 1999-12-31>
9591
+ * Date.strptime('1999 52 5', '%Y %U %w') # => #<Date: 1999-12-31>
9592
+ * Date.strptime('1999 52 5', '%Y %W %u') # => #<Date: 1999-12-31>
9593
+ * Date.strptime('fri31dec99', '%a%d%b%y') # => #<Date: 1999-12-31>
9430
9594
  *
9431
- * In those classes, those are so-called "amjd" and "mjd".
9432
- *
9433
- * == Date
9434
- *
9435
- * A subclass of Object that includes the Comparable module and
9436
- * easily handles date.
9437
- *
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.
9441
- *
9442
- * require 'date'
9595
+ * See also the specialized methods in
9596
+ * {"Specialized Format Strings" in Formats for Dates and Times}[https://docs.ruby-lang.org/en/master/strftime_formatting_rdoc.html#label-Specialized+Format+Strings]
9443
9597
  *
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 ...>
9598
+ * == Argument +limit+
9458
9599
  *
9459
- * All date objects are immutable; hence cannot modify themselves.
9600
+ * Certain singleton methods in \Date that parse string arguments
9601
+ * also take optional keyword argument +limit+,
9602
+ * which can limit the length of the string argument.
9460
9603
  *
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.
9604
+ * When +limit+ is:
9463
9605
  *
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.
9471
- *
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.
9481
- *
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"
9606
+ * - Non-negative:
9607
+ * raises ArgumentError if the string length is greater than _limit_.
9608
+ * - Other numeric or +nil+: ignores +limit+.
9609
+ * - Other non-numeric: raises TypeError.
9507
9610
  *
9508
9611
  */
9509
9612
  cDate = rb_define_class("Date", rb_cObject);
9613
+
9614
+ /* Exception for invalid date/time */
9510
9615
  eDateError = rb_define_class_under(cDate, "Error", rb_eArgError);
9511
9616
 
9512
9617
  rb_include_module(cDate, rb_mComparable);
@@ -9733,6 +9838,8 @@ Init_date_core(void)
9733
9838
  rb_define_method(cDate, "httpdate", d_lite_httpdate, 0);
9734
9839
  rb_define_method(cDate, "jisx0301", d_lite_jisx0301, 0);
9735
9840
 
9841
+ rb_define_method(cDate, "deconstruct_keys", d_lite_deconstruct_keys, 1);
9842
+
9736
9843
  #ifndef NDEBUG
9737
9844
  rb_define_method(cDate, "marshal_dump_old", d_lite_marshal_dump_old, 0);
9738
9845
  #endif
@@ -9943,6 +10050,8 @@ Init_date_core(void)
9943
10050
  rb_define_method(cDateTime, "rfc3339", dt_lite_rfc3339, -1);
9944
10051
  rb_define_method(cDateTime, "jisx0301", dt_lite_jisx0301, -1);
9945
10052
 
10053
+ rb_define_method(cDateTime, "deconstruct_keys", dt_lite_deconstruct_keys, 1);
10054
+
9946
10055
  /* conversions */
9947
10056
 
9948
10057
  rb_define_method(rb_cTime, "to_time", time_to_time, 0);