summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorBurdette Lamar <BurdetteLamar@Yahoo.com>2022-07-06 13:57:48 -0500
committergit <svn-admin@ruby-lang.org>2022-07-07 03:58:02 +0900
commitdbb23f29cb721e11f9d07e1edefb4c65ef212d37 (patch)
tree1d0d4dcf390813b184ac99ac834ed2b305c3b121 /ext/date
parentc6b38e43b030782fcb95ed57333d69fe75863503 (diff)
[ruby/date] [DOC] Enhanced RDoc (https://github.com/ruby/date/pull/57)
All things commercial. https://github.com/ruby/date/commit/9d3bc61728
Diffstat (limited to 'ext/date')
-rw-r--r--ext/date/date_core.c77
1 files changed, 57 insertions, 20 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 3ba66ce1c4..dc0f00169a 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -2732,7 +2732,7 @@ date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
/*
* call-seq:
- * Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
+ * Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
*
* Returns +true+ if the arguments define a valid commercial date,
* +false+ otherwise:
@@ -2740,6 +2740,8 @@ date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
* Date.valid_commercial?(2001, 5, 6) # => true
* Date.valid_commercial?(2001, 5, 8) # => false
*
+ * See Date.commercial.
+ *
* See {Argument start}[rdoc-ref:Date@Argument+start].
*
* Related: Date.jd, Date.commercial.
@@ -3527,19 +3529,47 @@ date_initialize(int argc, VALUE *argv, VALUE self)
/*
* call-seq:
- * Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) -> date
+ * Date.commercial(cwyear=-4712, cweek=1, cwday=1, start=Date::ITALY) -> date
+ *
+ * Returns a new \Date object constructed from the arguments.
+ *
+ * Argument +cwyear+ gives the year, and should be an integer.
+ *
+ * Argument +cweek+ gives the index of the week within the year,
+ * and should be in range (1..53) or (-53..-1);
+ * in some years, 53 or -53 will be out-of-range;
+ * if negative, counts backward from the end of the year:
+ *
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
+ * Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
+ *
+ * Argument +cwday+ gives the indes of the weekday within the week,
+ * and should be in range (1..7) or (-7..-1);
+ * 1 or -7 is Monday;
+ * if negative, counts backward from the end of the week:
+ *
+ * Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
+ * Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
*
- * Creates a date object denoting the given week date.
+ * When +cweek+ is 1:
*
- * The week and the day of week should be a negative or a positive
- * number (as a relative week/day from the end of year/week when
- * negative). They should not be zero.
+ * - If January 1 is a Friday, Saturday, or Sunday,
+ * the first week begins in the week after:
*
- * Date.commercial(2001) #=> #<Date: 2001-01-01 ...>
- * Date.commercial(2002) #=> #<Date: 2001-12-31 ...>
- * Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
+ * Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun"
+ * Date.commercial(2023, 1, 1).to_s # => "2023-01-02"
+ Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
*
- * See also ::jd and ::new.
+ * - Otherwise, the first week is the week of January 1,
+ * which may mean some of the days fall on the year before:
+ *
+ * Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed"
+ * Date.commercial(2020, 1, 1).to_s # => "2019-12-30"
+ Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
+ *
+ * See {Argument start}[rdoc-ref:Date@Argument+start].
+ *
+ * Related: Date.jd, Date.new, Date.ordinal.
*/
static VALUE
date_s_commercial(int argc, VALUE *argv, VALUE klass)
@@ -5226,12 +5256,14 @@ d_lite_day_fraction(VALUE self)
/*
* call-seq:
- * d.cwyear -> integer
+ * cwyear -> integer
*
- * Returns the calendar week based year.
+ * Returns commercial-date year for +self+
+ * (see Date.commercial):
+ *
+ * Date.new(2001, 2, 3).cwyear # => 2001
+ * Date.new(2000, 1, 1).cwyear # => 1999
*
- * Date.new(2001,2,3).cwyear #=> 2001
- * Date.new(2000,1,1).cwyear #=> 1999
*/
static VALUE
d_lite_cwyear(VALUE self)
@@ -5242,11 +5274,13 @@ d_lite_cwyear(VALUE self)
/*
* call-seq:
- * d.cweek -> fixnum
+ * cweek -> integer
+ *
+ * Returns commercial-date week index for +self+
+ * (see Date.commercial):
*
- * Returns the calendar week number (1-53).
+ * Date.new(2001, 2, 3).cweek # => 5
*
- * Date.new(2001,2,3).cweek #=> 5
*/
static VALUE
d_lite_cweek(VALUE self)
@@ -5257,11 +5291,14 @@ d_lite_cweek(VALUE self)
/*
* call-seq:
- * d.cwday -> fixnum
+ * cwday -> integer
+ *
+ * Returns the commercial-date weekday index for +self+
+ * (see Date.commercial);
+ * 1 is Monday:
*
- * Returns the day of calendar week (1-7, Monday is 1).
+ * Date.new(2001, 2, 3).cwday # => 6
*
- * Date.new(2001,2,3).cwday #=> 6
*/
static VALUE
d_lite_cwday(VALUE self)