Skip to content

Commit 9d3bc61

Browse files
[DOC] Enhanced RDoc (#57)
All things commercial.
1 parent 6af49d4 commit 9d3bc61

File tree

1 file changed

+57
-20
lines changed

1 file changed

+57
-20
lines changed

ext/date/date_core.c

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2732,14 +2732,16 @@ date_s__valid_commercial_p(int argc, VALUE *argv, VALUE klass)
27322732

27332733
/*
27342734
* call-seq:
2735-
* Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
2735+
* Date.valid_commercial?(cwyear, cweek, cwday, start = Date::ITALY) -> true or false
27362736
*
27372737
* Returns +true+ if the arguments define a valid commercial date,
27382738
* +false+ otherwise:
27392739
*
27402740
* Date.valid_commercial?(2001, 5, 6) # => true
27412741
* Date.valid_commercial?(2001, 5, 8) # => false
27422742
*
2743+
* See Date.commercial.
2744+
*
27432745
* See {Argument start}[rdoc-ref:Date@Argument+start].
27442746
*
27452747
* Related: Date.jd, Date.commercial.
@@ -3527,19 +3529,47 @@ date_initialize(int argc, VALUE *argv, VALUE self)
35273529

35283530
/*
35293531
* call-seq:
3530-
* Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) -> date
3532+
* Date.commercial(cwyear=-4712, cweek=1, cwday=1, start=Date::ITALY) -> date
3533+
*
3534+
* Returns a new \Date object constructed from the arguments.
3535+
*
3536+
* Argument +cwyear+ gives the year, and should be an integer.
3537+
*
3538+
* Argument +cweek+ gives the index of the week within the year,
3539+
* and should be in range (1..53) or (-53..-1);
3540+
* in some years, 53 or -53 will be out-of-range;
3541+
* if negative, counts backward from the end of the year:
3542+
*
3543+
* Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3544+
* Date.commercial(2022, 52, 1).to_s # => "2022-12-26"
3545+
*
3546+
* Argument +cwday+ gives the indes of the weekday within the week,
3547+
* and should be in range (1..7) or (-7..-1);
3548+
* 1 or -7 is Monday;
3549+
* if negative, counts backward from the end of the week:
3550+
*
3551+
* Date.commercial(2022, 1, 1).to_s # => "2022-01-03"
3552+
* Date.commercial(2022, 1, -7).to_s # => "2022-01-03"
35313553
*
3532-
* Creates a date object denoting the given week date.
3554+
* When +cweek+ is 1:
35333555
*
3534-
* The week and the day of week should be a negative or a positive
3535-
* number (as a relative week/day from the end of year/week when
3536-
* negative). They should not be zero.
3556+
* - If January 1 is a Friday, Saturday, or Sunday,
3557+
* the first week begins in the week after:
35373558
*
3538-
* Date.commercial(2001) #=> #<Date: 2001-01-01 ...>
3539-
* Date.commercial(2002) #=> #<Date: 2001-12-31 ...>
3540-
* Date.commercial(2001,5,6) #=> #<Date: 2001-02-03 ...>
3559+
* Date::ABBR_DAYNAMES[Date.new(2023, 1, 1).wday] # => "Sun"
3560+
* Date.commercial(2023, 1, 1).to_s # => "2023-01-02"
3561+
Date.commercial(2023, 1, 7).to_s # => "2023-01-08"
35413562
*
3542-
* See also ::jd and ::new.
3563+
* - Otherwise, the first week is the week of January 1,
3564+
* which may mean some of the days fall on the year before:
3565+
*
3566+
* Date::ABBR_DAYNAMES[Date.new(2020, 1, 1).wday] # => "Wed"
3567+
* Date.commercial(2020, 1, 1).to_s # => "2019-12-30"
3568+
Date.commercial(2020, 1, 7).to_s # => "2020-01-05"
3569+
*
3570+
* See {Argument start}[rdoc-ref:Date@Argument+start].
3571+
*
3572+
* Related: Date.jd, Date.new, Date.ordinal.
35433573
*/
35443574
static VALUE
35453575
date_s_commercial(int argc, VALUE *argv, VALUE klass)
@@ -5226,12 +5256,14 @@ d_lite_day_fraction(VALUE self)
52265256

52275257
/*
52285258
* call-seq:
5229-
* d.cwyear -> integer
5259+
* cwyear -> integer
52305260
*
5231-
* Returns the calendar week based year.
5261+
* Returns commercial-date year for +self+
5262+
* (see Date.commercial):
5263+
*
5264+
* Date.new(2001, 2, 3).cwyear # => 2001
5265+
* Date.new(2000, 1, 1).cwyear # => 1999
52325266
*
5233-
* Date.new(2001,2,3).cwyear #=> 2001
5234-
* Date.new(2000,1,1).cwyear #=> 1999
52355267
*/
52365268
static VALUE
52375269
d_lite_cwyear(VALUE self)
@@ -5242,11 +5274,13 @@ d_lite_cwyear(VALUE self)
52425274

52435275
/*
52445276
* call-seq:
5245-
* d.cweek -> fixnum
5277+
* cweek -> integer
5278+
*
5279+
* Returns commercial-date week index for +self+
5280+
* (see Date.commercial):
52465281
*
5247-
* Returns the calendar week number (1-53).
5282+
* Date.new(2001, 2, 3).cweek # => 5
52485283
*
5249-
* Date.new(2001,2,3).cweek #=> 5
52505284
*/
52515285
static VALUE
52525286
d_lite_cweek(VALUE self)
@@ -5257,11 +5291,14 @@ d_lite_cweek(VALUE self)
52575291

52585292
/*
52595293
* call-seq:
5260-
* d.cwday -> fixnum
5294+
* cwday -> integer
5295+
*
5296+
* Returns the commercial-date weekday index for +self+
5297+
* (see Date.commercial);
5298+
* 1 is Monday:
52615299
*
5262-
* Returns the day of calendar week (1-7, Monday is 1).
5300+
* Date.new(2001, 2, 3).cwday # => 6
52635301
*
5264-
* Date.new(2001,2,3).cwday #=> 6
52655302
*/
52665303
static VALUE
52675304
d_lite_cwday(VALUE self)

0 commit comments

Comments
 (0)