ruby-changes:72443
From: Burdette <ko1@a...>
Date: Thu, 7 Jul 2022 03:58:16 +0900 (JST)
Subject: [ruby-changes:72443] dbb23f29cb (master): [ruby/date] [DOC] Enhanced RDoc (https://github.com/ruby/date/pull/57)
https://git.ruby-lang.org/ruby.git/commit/?id=dbb23f29cb From dbb23f29cb721e11f9d07e1edefb4c65ef212d37 Mon Sep 17 00:00:00 2001 From: Burdette Lamar <BurdetteLamar@Y...> Date: Wed, 6 Jul 2022 13:57:48 -0500 Subject: [ruby/date] [DOC] Enhanced RDoc (https://github.com/ruby/date/pull/57) All things commercial. https://github.com/ruby/date/commit/9d3bc61728 --- ext/date/date_core.c | 77 ++++++++++++++++++++++++++++++++++++++-------------- 1 file 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2732 /* * 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L2740 * 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L3529 /* * 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L5256 /* * 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L5274 /* * 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) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L5291 /* * 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) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/