From e26e4b2cdf1c684b10f6620502b829390763f517 Mon Sep 17 00:00:00 2001 From: tadf Date: Fri, 11 Mar 2011 16:21:56 +0000 Subject: [PATCH] * ext/date/date_core.c, ext/date/lib/*: moved rdoc descriptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - この行以下は無視されます -- M ChangeLog M ext/date/date_core.c M ext/date/lib/date.rb M ext/date/lib/date/format.rb git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31097 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 + ext/date/date_core.c | 675 ++++++++++++++++++++++++++++++++++++ ext/date/lib/date.rb | 191 ---------- ext/date/lib/date/format.rb | 1 - 4 files changed, 679 insertions(+), 192 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cf5ef5e53..8da7e015b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Mar 12 01:16:02 2011 Tadayoshi Funaba + + * ext/date/date_core.c, ext/date/lib/*: moved rdoc descriptions. + Sat Mar 12 00:06:24 2011 Tadayoshi Funaba * ext/date/lib: moved from lib. diff --git a/ext/date/date_core.c b/ext/date/date_core.c index afdf5683d0..9ca55b2802 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -1049,6 +1049,15 @@ date_s_new_l_bang(int argc, VALUE *argv, VALUE klass) return d_lite_s_new_l_bang(argc, argv, klass); } +/* + * call-seq: + * Date.jd([jd=0[, start=Date::ITALY]]) + * + * Create a new Date object from a Julian Day Number. + * + * +jd+ is the Julian Day Number; if not specified, it defaults to 0. + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE date_s_jd(int argc, VALUE *argv, VALUE klass) { @@ -1080,6 +1089,21 @@ date_s_jd(int argc, VALUE *argv, VALUE klass) return d_lite_s_new_internal_wo_civil(klass, jd, sg, LIGHT_MODE | HAVE_JD); } +/* + * call-seq: + * Date.ordinal([year=-4712[, yday=1[, start=Date::ITALY]]]) + * + * Create a new Date object from an Ordinal Date, specified + * by year +y+ and day-of-year +d+. +d+ can be negative, + * in which it counts backwards from the end of the year. + * No year wraparound is performed, however. An invalid + * value for +d+ results in an ArgumentError being raised. + * + * +y+ defaults to -4712, and +d+ to 1; this is Julian Day + * Number day 0. + * + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE date_s_ordinal(int argc, VALUE *argv, VALUE klass) { @@ -1126,6 +1150,25 @@ date_s_ordinal(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * Date.civil([year=-4712[, mon=1[, mday=1[, start=Date::ITALY]]]]) + * Date.new([year=-4712[, mon=1[, mday=1[, start=Date::ITALY]]]]) + * + * Create a new Date object for the Civil Date specified by + * year +y+, month +m+, and day-of-month +d+. + * + * +m+ and +d+ can be negative, in which case they count + * backwards from the end of the year and the end of the + * month respectively. No wraparound is performed, however, + * and invalid values cause an ArgumentError to be raised. + * can be negative + * + * +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is + * Julian Day Number day 0. + * + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE date_s_civil(int argc, VALUE *argv, VALUE klass) { @@ -1183,6 +1226,25 @@ date_s_civil(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * Date.commercial([cwyear=-4712[, cweek=1[, cwday=1[, start=Date::ITALY]]]]) + * + * Create a new Date object for the Commercial Date specified by + * year +y+, week-of-year +w+, and day-of-week +d+. + * + * Monday is day-of-week 1; Sunday is day-of-week 7. + * + * +w+ and +d+ can be negative, in which case they count + * backwards from the end of the year and the end of the + * week respectively. No wraparound is performed, however, + * and invalid values cause an ArgumentError to be raised. + * + * +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is + * Julian Day Number day 0. + * + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE date_s_commercial(int argc, VALUE *argv, VALUE klass) { @@ -1244,6 +1306,14 @@ localtime_r(const time_t *t, struct tm *tm) } #endif +/* + * call-seq: + * Date.today([start=Date::ITALY]) + * + * Create a new Date object representing today. + * + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE date_s_today(int argc, VALUE *argv, VALUE klass) { @@ -1286,6 +1356,12 @@ date_s_today(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * d.ajd + * + * Get the date as an Astronomical Julian Day Number. + */ static VALUE d_lite_ajd(VALUE self) { @@ -1298,6 +1374,12 @@ d_lite_ajd(VALUE self) } } +/* + * call-seq: + * d.amjd + * + * Get the date as an Astronomical Modified Julian Day Number. + */ static VALUE d_lite_amjd(VALUE self) { @@ -1310,6 +1392,12 @@ d_lite_amjd(VALUE self) } } +/* + * call-seq: + * d.jd + * + * Get the date as a Julian Day Number. + */ static VALUE d_lite_jd(VALUE self) { @@ -1322,6 +1410,12 @@ d_lite_jd(VALUE self) } } +/* + * call-seq: + * d.mjd + * + * Get the date as a Modified Julian Day Number. + */ static VALUE d_lite_mjd(VALUE self) { @@ -1334,6 +1428,12 @@ d_lite_mjd(VALUE self) } } +/* + * call-seq: + * d.ld + * + * Get the date as a Lilian Day Number. + */ static VALUE d_lite_ld(VALUE self) { @@ -1346,6 +1446,12 @@ d_lite_ld(VALUE self) } } +/* + * call-seq: + * d.year + * + * Get the year of this date. + */ static VALUE d_lite_year(VALUE self) { @@ -1358,6 +1464,14 @@ d_lite_year(VALUE self) } } +/* + * call-seq: + * d.yday + * + * Get the day-of-the-year of this date. + * + * January 1 is day-of-the-year 1 + */ static VALUE d_lite_yday(VALUE self) { @@ -1373,6 +1487,14 @@ d_lite_yday(VALUE self) } } +/* + * call-seq: + * d.mon + * + * Get the month of this date. + * + * January is month 1. + */ static VALUE d_lite_mon(VALUE self) { @@ -1385,6 +1507,12 @@ d_lite_mon(VALUE self) } } +/* + * call-seq: + * d.mday + * + * Get the day-of-the-month of this date. + */ static VALUE d_lite_mday(VALUE self) { @@ -1397,6 +1525,12 @@ d_lite_mday(VALUE self) } } +/* + * call-seq: + * d.day_fraction + * + * Get any fractional day part of the date. + */ static VALUE d_lite_day_fraction(VALUE self) { @@ -1436,6 +1570,12 @@ d_lite_wnum1(VALUE self) } } +/* + * call-seq: + * d.hour + * + * Get the hour of this date. + */ static VALUE d_lite_hour(VALUE self) { @@ -1445,6 +1585,13 @@ d_lite_hour(VALUE self) return INT2FIX(0); } +/* + * call-seq: + * d.min + * d.minute + * + * Get the minute of this date. + */ static VALUE d_lite_min(VALUE self) { @@ -1454,6 +1601,13 @@ d_lite_min(VALUE self) return INT2FIX(0); } +/* + * call-seq: + * d.sec + * d.second + * + * Get the second of this date. + */ static VALUE d_lite_sec(VALUE self) { @@ -1463,6 +1617,13 @@ d_lite_sec(VALUE self) return INT2FIX(0); } +/* + * call-seq: + * d.sec_fraction + * d.second_fraction + * + * Get the fraction-of-a-second of this date. + */ static VALUE d_lite_sec_fraction(VALUE self) { @@ -1472,6 +1633,12 @@ d_lite_sec_fraction(VALUE self) return INT2FIX(0); } +/* + * call-seq: + * d.offset + * + * Get the offset of this date. + */ static VALUE d_lite_offset(VALUE self) { @@ -1481,6 +1648,12 @@ d_lite_offset(VALUE self) return INT2FIX(0); } +/* + * call-seq: + * d.zone + * + * Get the zone name of this date. + */ static VALUE d_lite_zone(VALUE self) { @@ -1490,6 +1663,13 @@ d_lite_zone(VALUE self) return rb_usascii_str_new2("+00:00"); } +/* + * call-seq: + * d.cwyear + * + * Get the commercial year of this date. See *Commercial* *Date* + * in the introduction for how this differs from the normal year. + */ static VALUE d_lite_cwyear(VALUE self) { @@ -1505,6 +1685,12 @@ d_lite_cwyear(VALUE self) } } +/* + * call-seq: + * d.cweek + * + * Get the commercial week of the year of this date. + */ static VALUE d_lite_cweek(VALUE self) { @@ -1520,6 +1706,13 @@ d_lite_cweek(VALUE self) } } +/* + * call-seq: + * d.cwday + * + * Get the commercial day of the week of this date. Monday is + * commercial day-of-week 1; Sunday is commercial day-of-week 7. + */ static VALUE d_lite_cwday(VALUE self) { @@ -1537,6 +1730,13 @@ d_lite_cwday(VALUE self) } } +/* + * call-seq: + * d.wday + * + * Get the week day of this date. Sunday is day-of-week 0; + * Saturday is day-of-week 6. + */ static VALUE d_lite_wday(VALUE self) { @@ -1549,6 +1749,12 @@ d_lite_wday(VALUE self) } } +/* + * call-seq: + * d.julian? + * + * Is the current date old-style (Julian Calendar)? + */ static VALUE d_lite_julian_p(VALUE self) { @@ -1558,6 +1764,12 @@ d_lite_julian_p(VALUE self) return Qfalse; } +/* + * call-seq: + * d.gregorian? + * + * Is the current date new-style (Gregorian Calendar)? + */ static VALUE d_lite_gregorian_p(VALUE self) { @@ -1567,6 +1779,12 @@ d_lite_gregorian_p(VALUE self) return Qtrue; } +/* + * call-seq: + * d.leap? + * + * Is this a leap year? + */ static VALUE d_lite_leap_p(VALUE self) { @@ -1579,6 +1797,12 @@ d_lite_leap_p(VALUE self) } } +/* + * call-seq: + * d.start + * + * When is the Day of Calendar Reform for this Date object? + */ static VALUE d_lite_start(VALUE self) { @@ -1588,6 +1812,12 @@ d_lite_start(VALUE self) return DBL2NUM(dat->l.sg); } +/* + * call-seq: + * d.new_start([start=Date::ITALY]) + * + * Create a copy of this Date object using a new Day of Calendar Reform. + */ static VALUE d_lite_new_start(int argc, VALUE *argv, VALUE self) { @@ -1619,6 +1849,12 @@ d_lite_new_start(int argc, VALUE *argv, VALUE self) } } +/* + * call-seq: + * d.new_offset([offset=0]) + * + * Create a copy of this Date object using a new offset. + */ static VALUE d_lite_new_offset(int argc, VALUE *argv, VALUE self) { @@ -1649,6 +1885,20 @@ d_lite_new_offset(int argc, VALUE *argv, VALUE self) } } +/* + * call-seq: + * d + n + * + * Return a new Date object that is +n+ days later than the + * current one. + * + * +n+ may be a negative value, in which case the new Date + * is earlier than the current one; however, #-() might be + * more intuitive. + * + * If +n+ is not a Numeric, a TypeError will be thrown. In + * particular, two Dates cannot be added to each other. + */ static VALUE d_lite_plus(VALUE self, VALUE other) { @@ -1731,6 +1981,20 @@ minus_dd(VALUE self, VALUE other) return iforwardop("minus_r"); } +/* + * call-seq: + * d - n + * d - d2 + * + * If +x+ is a Numeric value, create a new Date object that is + * +x+ days earlier than the current one. + * + * If +x+ is a Date, return the number of days between the + * two dates; or, more precisely, how many days later the current + * date is than +x+. + * + * If +x+ is neither Numeric nor a Date, a TypeError is raised. + */ static VALUE d_lite_minus(VALUE self, VALUE other) { @@ -1803,6 +2067,23 @@ cmp_dd(VALUE self, VALUE other) return iforwardop("cmp_r"); } +/* + * call-seq: + * d <=> n + * d <=> d2 + * + * Compare this date with another date. + * + * +other+ can also be a Numeric value, in which case it is + * interpreted as an Astronomical Julian Day Number. + * + * Comparison is by Astronomical Julian Day Number, including + * fractional days. This means that both the time and the + * offset are taken into account when comparing + * two DateTime instances. When comparing a DateTime instance + * with a Date instance, the time of the latter will be + * considered as falling on midnight UTC. + */ static VALUE d_lite_cmp(VALUE self, VALUE other) { @@ -1877,6 +2158,17 @@ equal_dd(VALUE self, VALUE other) return iforwardop("equal_r"); } +/* + * call-seq: + * d == other + * + * The relationship operator for Date. + * + * Compares dates by Julian Day Number. When comparing + * two DateTime instances, or a DateTime with a Date, + * the instances will be regarded as equivalent if they + * fall on the same date in local time. + */ static VALUE d_lite_equal(VALUE self, VALUE other) { @@ -1931,6 +2223,14 @@ eql_p_dd(VALUE self, VALUE other) return iforwardop("eql_r?"); } +/* + * call-seq: + * d.eql?(other) + * + * Is this Date equal to +other+? + * + * +other+ must both be a Date object, and represent the same date. + */ static VALUE d_lite_eql_p(VALUE self, VALUE other) { @@ -1964,6 +2264,12 @@ d_lite_eql_p(VALUE self, VALUE other) return iforwardop("eql_r?"); } +/* + * call-seq: + * d.hash + * + * Calculate a hash value for this date. + */ static VALUE d_lite_hash(VALUE self) { @@ -1973,6 +2279,12 @@ d_lite_hash(VALUE self) return rb_hash(d_lite_ajd(self)); } +/* + * call-seq: + * d.to_s + * + * Return the date as a human-readable string. + */ static VALUE d_lite_to_s(VALUE self) { @@ -1987,6 +2299,12 @@ d_lite_to_s(VALUE self) } } +/* + * call-seq: + * d.inspect + * + * Return internal object state as a programmer-readable string. + */ static VALUE d_lite_inspect(VALUE self) { @@ -2004,6 +2322,12 @@ d_lite_inspect(VALUE self) } } +/* + * call-seq: + * d.marshal_dump + * + * Dump to Marshal format. + */ static VALUE d_lite_marshal_dump(VALUE self) { @@ -2026,6 +2350,12 @@ d_lite_marshal_dump(VALUE self) return a; } +/* + * call-seq: + * d.marshal_load(ary) + * + * Load from Marshal format. + */ static VALUE d_lite_marshal_load(VALUE self, VALUE a) { @@ -2152,6 +2482,24 @@ datetime_s_new_l_bang(int argc, VALUE *argv, VALUE klass) return dt_lite_s_new_l_bang(argc, argv, klass); } +/* + * call-seq: + * DateTime.jd([jd=0[, hour=0[, min=0[, sec=0[, offset=0[, start=Date::ITALY]]]]]]) + * + * Create a new DateTime object corresponding to the specified + * Julian Day Number +jd+ and hour +h+, minute +min+, second +s+. + * + * The 24-hour clock is used. Negative values of +h+, +min+, and + * +sec+ are treating as counting backwards from the end of the + * next larger unit (e.g. a +min+ of -2 is treated as 58). No + * wraparound is performed. If an invalid time portion is specified, + * an ArgumentError is raised. + * + * +of+ is the offset from UTC as a fraction of a day (defaults to 0). + * +sg+ specifies the Day of Calendar Reform. + * + * All day/time values default to 0. + */ static VALUE datetime_s_jd(int argc, VALUE *argv, VALUE klass) { @@ -2204,6 +2552,25 @@ datetime_s_jd(int argc, VALUE *argv, VALUE klass) LIGHT_MODE | HAVE_JD | HAVE_TIME); } +/* + * call-seq: + * DateTime.ordinal([year=-4712[, yday=1[, hour=0[, min=0[, sec=0[, offset=0[, start=Date::ITALY]]]]]]]) + * + * Create a new DateTime object corresponding to the specified + * Ordinal Date and hour +h+, minute +min+, second +s+. + * + * The 24-hour clock is used. Negative values of +h+, +min+, and + * +sec+ are treating as counting backwards from the end of the + * next larger unit (e.g. a +min+ of -2 is treated as 58). No + * wraparound is performed. If an invalid time portion is specified, + * an ArgumentError is raised. + * + * +of+ is the offset from UTC as a fraction of a day (defaults to 0). + * +sg+ specifies the Day of Calendar Reform. + * + * +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number + * day 0. The time values default to 0. +*/ static VALUE datetime_s_ordinal(int argc, VALUE *argv, VALUE klass) { @@ -2272,6 +2639,26 @@ datetime_s_ordinal(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * DateTime.civil([year=-4712[, mon=1[, mday=1[, hour=0[, min=0[, sec=0[, offset=0[, start=Date::ITALY]]]]]]]]) + * DateTime.new([year=-4712[, mon=1[, mday=1[, hour=0[, min=0[, sec=0[, offset=0[, start=Date::ITALY]]]]]]]]) + * + * Create a new DateTime object corresponding to the specified + * Civil Date and hour +h+, minute +min+, second +s+. + * + * The 24-hour clock is used. Negative values of +h+, +min+, and + * +sec+ are treating as counting backwards from the end of the + * next larger unit (e.g. a +min+ of -2 is treated as 58). No + * wraparound is performed. If an invalid time portion is specified, + * an ArgumentError is raised. + * + * +of+ is the offset from UTC as a fraction of a day (defaults to 0). + * +sg+ specifies the Day of Calendar Reform. + * + * +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day + * Number day 0. The time values default to 0. + */ static VALUE datetime_s_civil(int argc, VALUE *argv, VALUE klass) { @@ -2355,6 +2742,26 @@ datetime_s_civil(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * DateTime.commercial([cwyear=-4712[, cweek=1[, cwday=1[, hour=0[, min=0[, sec=0[, offset=0[, start=Date::ITALY]]]]]]]]) + * + * Create a new DateTime object corresponding to the specified + * Commercial Date and hour +h+, minute +min+, second +s+. + * + * The 24-hour clock is used. Negative values of +h+, +min+, and + * +sec+ are treating as counting backwards from the end of the + * next larger unit (e.g. a +min+ of -2 is treated as 58). No + * wraparound is performed. If an invalid time portion is specified, + * an ArgumentError is raised. + * + * +of+ is the offset from UTC as a fraction of a day (defaults to 0). + * +sg+ specifies the Day of Calendar Reform. + * + * +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is + * Julian Day Number day 0. + * The time values default to 0. + */ static VALUE datetime_s_commercial(int argc, VALUE *argv, VALUE klass) { @@ -2427,6 +2834,14 @@ datetime_s_commercial(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * DateTime.now([start=Date::ITALY]) + * + * Create a new DateTime object representing the current time. + * + * +sg+ specifies the Day of Calendar Reform. + */ static VALUE datetime_s_now(int argc, VALUE *argv, VALUE klass) { @@ -2503,6 +2918,12 @@ datetime_s_now(int argc, VALUE *argv, VALUE klass) } } +/* + * call-seq: + * dt.ajd + * + * Get the date as an Astronomical Julian Day Number. + */ static VALUE dt_lite_ajd(VALUE self) { @@ -2525,6 +2946,12 @@ dt_lite_ajd(VALUE self) } } +/* + * call-seq: + * dt.amjd + * + * Get the date as an Astronomical Modified Julian Day Number. + */ static VALUE dt_lite_amjd(VALUE self) { @@ -2547,6 +2974,12 @@ dt_lite_amjd(VALUE self) } } +/* + * call-seq: + * dt.jd + * + * Get the date as a Julian Day Number. + */ static VALUE dt_lite_jd(VALUE self) { @@ -2560,6 +2993,12 @@ dt_lite_jd(VALUE self) } } +/* + * call-seq: + * dt.mjd + * + * Get the date as a Modified Julian Day Number. + */ static VALUE dt_lite_mjd(VALUE self) { @@ -2573,6 +3012,12 @@ dt_lite_mjd(VALUE self) } } +/* + * call-seq: + * dt.ld + * + * Get the date as a Lilian Day Number. + */ static VALUE dt_lite_ld(VALUE self) { @@ -2586,6 +3031,12 @@ dt_lite_ld(VALUE self) } } +/* + * call-seq: + * dt.year + * + * Get the year of this date. + */ static VALUE dt_lite_year(VALUE self) { @@ -2598,6 +3049,14 @@ dt_lite_year(VALUE self) } } +/* + * call-seq: + * dt.yday + * + * Get the day-of-the-year of this date. + * + * January 1 is day-of-the-year 1 + */ static VALUE dt_lite_yday(VALUE self) { @@ -2614,6 +3073,14 @@ dt_lite_yday(VALUE self) } } +/* + * call-seq: + * dt.mon + * + * Get the month of this date. + * + * January is month 1. + */ static VALUE dt_lite_mon(VALUE self) { @@ -2626,6 +3093,12 @@ dt_lite_mon(VALUE self) } } +/* + * call-seq: + * dt.mday + * + * Get the day-of-the-month of this date. + */ static VALUE dt_lite_mday(VALUE self) { @@ -2638,6 +3111,12 @@ dt_lite_mday(VALUE self) } } +/* + * call-seq: + * dt.day_fraction + * + * Get any fractional day part of the date. + */ static VALUE dt_lite_day_fraction(VALUE self) { @@ -2683,6 +3162,12 @@ dt_lite_wnum1(VALUE self) } } +/* + * call-seq: + * dt.hour + * + * Get the hour of this date. + */ static VALUE dt_lite_hour(VALUE self) { @@ -2695,6 +3180,13 @@ dt_lite_hour(VALUE self) } } +/* + * call-seq: + * dt.min + * dt.minute + * + * Get the minute of this date. + */ static VALUE dt_lite_min(VALUE self) { @@ -2707,6 +3199,13 @@ dt_lite_min(VALUE self) } } +/* + * call-seq: + * dt.sec + * dt.second + * + * Get the second of this date. + */ static VALUE dt_lite_sec(VALUE self) { @@ -2719,6 +3218,13 @@ dt_lite_sec(VALUE self) } } +/* + * call-seq: + * dt.sec_fraction + * dt.second_fraction + * + * Get the fraction-of-a-second of this date. + */ static VALUE dt_lite_sec_fraction(VALUE self) { @@ -2728,6 +3234,12 @@ dt_lite_sec_fraction(VALUE self) return rb_rational_new2(INT2FIX(dat->l.sf), INT2FIX(SECOND_IN_NANOSECONDS)); } +/* + * call-seq: + * dt.offset + * + * Get the offset of this date. + */ static VALUE dt_lite_offset(VALUE self) { @@ -2746,6 +3258,12 @@ dt_lite_offset(VALUE self) m = a % 3600 / 60;\ } +/* + * call-seq: + * dt.zone + * + * Get the zone name of this date. + */ static VALUE dt_lite_zone(VALUE self) { @@ -2758,6 +3276,13 @@ dt_lite_zone(VALUE self) return rb_enc_sprintf(rb_usascii_encoding(), "%c%02d:%02d", s, h, m); } +/* + * call-seq: + * dt.cwyear + * + * Get the commercial year of this date. See *Commercial* *Date* + * in the introduction for how this differs from the normal year. + */ static VALUE dt_lite_cwyear(VALUE self) { @@ -2774,6 +3299,12 @@ dt_lite_cwyear(VALUE self) } } +/* + * call-seq: + * dt.cweek + * + * Get the commercial week of the year of this date. + */ static VALUE dt_lite_cweek(VALUE self) { @@ -2790,6 +3321,13 @@ dt_lite_cweek(VALUE self) } } +/* + * call-seq: + * dt.cwday + * + * Get the commercial day of the week of this date. Monday is + * commercial day-of-week 1; Sunday is commercial day-of-week 7. + */ static VALUE dt_lite_cwday(VALUE self) { @@ -2808,6 +3346,13 @@ dt_lite_cwday(VALUE self) } } +/* + * call-seq: + * dt.wday + * + * Get the week day of this date. Sunday is day-of-week 0; + * Saturday is day-of-week 6. + */ static VALUE dt_lite_wday(VALUE self) { @@ -2824,6 +3369,12 @@ dt_lite_wday(VALUE self) } } +/* + * call-seq: + * dt.julian? + * + * Is the current date old-style (Julian Calendar)? + */ static VALUE dt_lite_julian_p(VALUE self) { @@ -2833,6 +3384,12 @@ dt_lite_julian_p(VALUE self) return Qfalse; } +/* + * call-seq: + * dt.gregorian? + * + * Is the current date new-style (Gregorian Calendar)? + */ static VALUE dt_lite_gregorian_p(VALUE self) { @@ -2842,6 +3399,12 @@ dt_lite_gregorian_p(VALUE self) return Qtrue; } +/* + * call-seq: + * dt.leap? + * + * Is this a leap year? + */ static VALUE dt_lite_leap_p(VALUE self) { @@ -2854,6 +3417,12 @@ dt_lite_leap_p(VALUE self) } } +/* + * call-seq: + * dt.start + * + * When is the Day of Calendar Reform for this Date object? + */ static VALUE dt_lite_start(VALUE self) { @@ -2863,6 +3432,12 @@ dt_lite_start(VALUE self) return DBL2NUM(dat->l.sg); } +/* + * call-seq: + * dt.new_start([start=Date::ITALY]) + * + * Create a copy of this Date object using a new Day of Calendar Reform. + */ static VALUE dt_lite_new_start(int argc, VALUE *argv, VALUE self) { @@ -2898,6 +3473,12 @@ dt_lite_new_start(int argc, VALUE *argv, VALUE self) } } +/* + * call-seq: + * dt.new_offset([offset=0]) + * + * Create a copy of this Date object using a new offset. + */ static VALUE dt_lite_new_offset(int argc, VALUE *argv, VALUE self) { @@ -2932,6 +3513,20 @@ dt_lite_new_offset(int argc, VALUE *argv, VALUE self) } } +/* + * call-seq: + * dt + n + * + * Return a new Date object that is +n+ days later than the + * current one. + * + * +n+ may be a negative value, in which case the new Date + * is earlier than the current one; however, #-() might be + * more intuitive. + * + * If +n+ is not a Numeric, a TypeError will be thrown. In + * particular, two Dates cannot be added to each other. + */ static VALUE dt_lite_plus(VALUE self, VALUE other) { @@ -3040,6 +3635,20 @@ dt_lite_plus(VALUE self, VALUE other) return iforwardop("plus_r"); } +/* + * call-seq: + * dt - n + * dt - dt2 + * + * If +x+ is a Numeric value, create a new Date object that is + * +x+ days earlier than the current one. + * + * If +x+ is a Date, return the number of days between the + * two dates; or, more precisely, how many days later the current + * date is than +x+. + * + * If +x+ is neither Numeric nor a Date, a TypeError is raised. + */ static VALUE dt_lite_minus(VALUE self, VALUE other) { @@ -3055,6 +3664,23 @@ dt_lite_minus(VALUE self, VALUE other) return iforwardop("minus_r"); } +/* + * call-seq: + * dt <=> n + * dt <=> d2 + * + * Compare this date with another date. + * + * +other+ can also be a Numeric value, in which case it is + * interpreted as an Astronomical Julian Day Number. + * + * Comparison is by Astronomical Julian Day Number, including + * fractional days. This means that both the time and the + * offset are taken into account when comparing + * two DateTime instances. When comparing a DateTime instance + * with a Date instance, the time of the latter will be + * considered as falling on midnight UTC. + */ static VALUE dt_lite_cmp(VALUE self, VALUE other) { @@ -3063,6 +3689,17 @@ dt_lite_cmp(VALUE self, VALUE other) return iforwardop("cmp_r"); } +/* + * call-seq: + * dt == other + * + * The relationship operator for Date. + * + * Compares dates by Julian Day Number. When comparing + * two DateTime instances, or a DateTime with a Date, + * the instances will be regarded as equivalent if they + * fall on the same date in local time. + */ static VALUE dt_lite_equal(VALUE self, VALUE other) { @@ -3071,6 +3708,14 @@ dt_lite_equal(VALUE self, VALUE other) return iforwardop("equal_r"); } +/* + * call-seq: + * dt.eql?(other) + * + * Is this Date equal to +other+? + * + * +other+ must both be a Date object, and represent the same date. + */ static VALUE dt_lite_eql_p(VALUE self, VALUE other) { @@ -3079,6 +3724,12 @@ dt_lite_eql_p(VALUE self, VALUE other) return iforwardop("eql_r?"); } +/* + * call-seq: + * dt.hash + * + * Calculate a hash value for this date. + */ static VALUE dt_lite_hash(VALUE self) { @@ -3088,6 +3739,12 @@ dt_lite_hash(VALUE self) return rb_hash(dt_lite_ajd(self)); } +/* + * call-seq: + * dt.to_s + * + * Return the date as a human-readable string. + */ static VALUE dt_lite_to_s(VALUE self) { @@ -3108,6 +3765,12 @@ dt_lite_to_s(VALUE self) } } +/* + * call-seq: + * dt.inspect + * + * Return internal object state as a programmer-readable string. + */ static VALUE dt_lite_inspect(VALUE self) { @@ -3135,6 +3798,12 @@ dt_lite_inspect(VALUE self) } } +/* + * call-seq: + * dt.marshal_dump + * + * Dump to Marshal format. + */ static VALUE dt_lite_marshal_dump(VALUE self) { @@ -3161,6 +3830,12 @@ dt_lite_marshal_dump(VALUE self) return a; } +/* + * call-seq: + * dt.marshal_load(ary) + * + * Load from Marshal format. + */ static VALUE dt_lite_marshal_load(VALUE self, VALUE a) { diff --git a/ext/date/lib/date.rb b/ext/date/lib/date.rb index 66fa67a579..e48da79359 100644 --- a/ext/date/lib/date.rb +++ b/ext/date/lib/date.rb @@ -783,11 +783,6 @@ class Date new_l!(jd, sg) end - # Create a new Date object from a Julian Day Number. - # - # +jd+ is the Julian Day Number; if not specified, it defaults to - # 0. - # +sg+ specifies the Day of Calendar Reform. def self.jd_r(jd=0, sg=ITALY) # :nodoc: jd = _valid_jd?(jd, sg) new_r!(jd_to_ajd(jd, 0, 0), 0, sg) @@ -795,16 +790,6 @@ class Date private_class_method :jd_r - # Create a new Date object from an Ordinal Date, specified - # by year +y+ and day-of-year +d+. +d+ can be negative, - # in which it counts backwards from the end of the year. - # No year wraparound is performed, however. An invalid - # value for +d+ results in an ArgumentError being raised. - # - # +y+ defaults to -4712, and +d+ to 1; this is Julian Day - # Number day 0. - # - # +sg+ specifies the Day of Calendar Reform. def self.ordinal_r(y=-4712, d=1, sg=ITALY) # :nodoc: unless jd = _valid_ordinal?(y, d, sg) raise ArgumentError, 'invalid date' @@ -814,19 +799,6 @@ class Date private_class_method :ordinal_r - # Create a new Date object for the Civil Date specified by - # year +y+, month +m+, and day-of-month +d+. - # - # +m+ and +d+ can be negative, in which case they count - # backwards from the end of the year and the end of the - # month respectively. No wraparound is performed, however, - # and invalid values cause an ArgumentError to be raised. - # can be negative - # - # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is - # Julian Day Number day 0. - # - # +sg+ specifies the Day of Calendar Reform. def self.civil_r(y=-4712, m=1, d=1, sg=ITALY) # :nodoc: unless jd = _valid_civil?(y, m, d, sg) raise ArgumentError, 'invalid date' @@ -836,20 +808,6 @@ class Date private_class_method :civil_r - # Create a new Date object for the Commercial Date specified by - # year +y+, week-of-year +w+, and day-of-week +d+. - # - # Monday is day-of-week 1; Sunday is day-of-week 7. - # - # +w+ and +d+ can be negative, in which case they count - # backwards from the end of the year and the end of the - # week respectively. No wraparound is performed, however, - # and invalid values cause an ArgumentError to be raised. - # - # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is - # Julian Day Number day 0. - # - # +sg+ specifies the Day of Calendar Reform. def self.commercial_r(y=-4712, w=1, d=1, sg=ITALY) # :nodoc: unless jd = _valid_commercial?(y, w, d, sg) raise ArgumentError, 'invalid date' @@ -1141,7 +1099,6 @@ class Date end - # Get the date as an Astronomical Modified Julian Day Number. def amjd_r() ajd_to_amjd(ajd) end once :amjd_r @@ -1151,29 +1108,16 @@ class Date once :daynum private :daynum - # Get the date as a Julian Day Number. def jd_r() daynum[0] end # :nodoc: - - # Get any fractional day part of the date. def day_fraction_r() daynum[1] end # :nodoc: - - # Get the date as a Modified Julian Day Number. def mjd_r() jd_to_mjd(jd) end # :nodoc: - - # Get the date as the number of days since the Day of Calendar - # Reform (in Italy and the Catholic countries). def ld_r() jd_to_ld(jd) end # :nodoc: once :jd_r, :day_fraction_r, :mjd_r, :ld_r private :jd_r, :day_fraction_r, :mjd_r, :ld_r - # Get the date as a Civil Date, [year, month, day_of_month] def civil() jd_to_civil(jd, start) end # :nodoc: - - # Get the date as an Ordinal Date, [year, day_of_year] def ordinal() jd_to_ordinal(jd, start) end # :nodoc: - - # Get the date as a Commercial Date, [year, week_of_year, day_of_week] def commercial() jd_to_commercial(jd, start) end # :nodoc: def weeknum0() jd_to_weeknum(jd, 0, start) end # :nodoc: @@ -1182,20 +1126,9 @@ class Date once :civil, :ordinal, :commercial, :weeknum0, :weeknum1 private :civil, :ordinal, :commercial, :weeknum0, :weeknum1 - # Get the year of this date. def year_r() civil[0] end # :nodoc: - - # Get the day-of-the-year of this date. - # - # January 1 is day-of-the-year 1 def yday_r() ordinal[1] end # :nodoc: - - # Get the month of this date. - # - # January is month 1. def mon_r() civil[1] end # :nodoc: - - # Get the day-of-the-month of this date. def mday_r() civil[2] end # :nodoc: private :year_r, :yday_r, :mon_r, :mday_r @@ -1205,8 +1138,6 @@ class Date private :wnum0_r, :wnum1_r - # Get the time of this date as [hours, minutes, seconds, - # fraction_of_a_second] def time() day_fraction_to_time(day_fraction) end # :nodoc: def time_wo_sf() day_fraction_to_time_wo_sf(day_fraction) end # :nodoc: def time_sf() day_fraction % SECONDS_IN_DAY * 86400 end # :nodoc: @@ -1214,16 +1145,9 @@ class Date once :time, :time_wo_sf, :time_sf private :time, :time_wo_sf, :time_sf - # Get the hour of this date. def hour_r() time_wo_sf[0] end # :nodoc: # 4p - - # Get the minute of this date. def min_r() time_wo_sf[1] end # :nodoc: # 4p - - # Get the second of this date. def sec_r() time_wo_sf[2] end # :nodoc: # 4p - - # Get the fraction-of-a-second of this date. def sec_fraction_r() time_sf end # 4p private :hour_r, :min_r, :sec_r, :sec_fraction_r @@ -1239,21 +1163,12 @@ class Date private :zone_r - # Get the commercial year of this date. See *Commercial* *Date* - # in the introduction for how this differs from the normal year. def cwyear_r() commercial[0] end # :nodoc: - - # Get the commercial week of the year of this date. def cweek_r() commercial[1] end # :nodoc: - - # Get the commercial day of the week of this date. Monday is - # commercial day-of-week 1; Sunday is commercial day-of-week 7. def cwday_r() commercial[2] end # :nodoc: private :cwyear_r, :cweek_r, :cwday_r - # Get the week day of this date. Sunday is day-of-week 0; - # Saturday is day-of-week 6. def wday_r() jd_to_wday(jd) end # :nodoc: once :wday_r @@ -1277,10 +1192,7 @@ class Date private :nth_kday? - # Is the current date old-style (Julian Calendar)? def julian_r? () jd < start end # :nodoc: - - # Is the current date new-style (Gregorian Calendar)? def gregorian_r? () !julian? end # :nodoc: once :julian_r?, :gregorian_r? @@ -1294,7 +1206,6 @@ class Date private :fix_style - # Is this a leap year? def leap_r? # :nodoc: jd_to_civil(civil_to_jd(year, 3, 1, fix_style) - 1, fix_style)[-1] == 29 @@ -1303,10 +1214,6 @@ class Date once :leap_r? private :leap_r? - # When is the Day of Calendar Reform for this Date object? - def start_r() @sg end # :nodoc: - - # Create a copy of this Date object using a new Day of Calendar Reform. def new_start_r(sg=self.class::ITALY) self.class.new_r!(ajd, offset, sg) end # :nodoc: private :start_r, :new_start_r @@ -1338,15 +1245,6 @@ class Date private :new_offset_r - # Return a new Date object that is +n+ days later than the - # current one. - # - # +n+ may be a negative value, in which case the new Date - # is earlier than the current one; however, #-() might be - # more intuitive. - # - # If +n+ is not a Numeric, a TypeError will be thrown. In - # particular, two Dates cannot be added to each other. def plus_r (n) # :nodoc: case n when Numeric @@ -1360,14 +1258,6 @@ class Date private :plus_r - # If +x+ is a Numeric value, create a new Date object that is - # +x+ days earlier than the current one. - # - # If +x+ is a Date, return the number of days between the - # two dates; or, more precisely, how many days later the current - # date is than +x+. - # - # If +x+ is neither Numeric nor a Date, a TypeError is raised. def minus_r (x) # :nodoc: case x when Numeric @@ -1383,17 +1273,6 @@ class Date private :minus_r - # Compare this date with another date. - # - # +other+ can also be a Numeric value, in which case it is - # interpreted as an Astronomical Julian Day Number. - # - # Comparison is by Astronomical Julian Day Number, including - # fractional days. This means that both the time and the - # offset are taken into account when comparing - # two DateTime instances. When comparing a DateTime instance - # with a Date instance, the time of the latter will be - # considered as falling on midnight UTC. def cmp_r (other) # :nodoc: case other when Numeric; return ajd <=> other @@ -1410,12 +1289,6 @@ class Date private :cmp_r - # The relationship operator for Date. - # - # Compares dates by Julian Day Number. When comparing - # two DateTime instances, or a DateTime with a Date, - # the instances will be regarded as equivalent if they - # fall on the same date in local time. def equal_r (other) # :nodoc: case other when Numeric; return jd == other @@ -1507,28 +1380,20 @@ class Date step(min, -1, &block) end - # Is this Date equal to +other+? - # - # +other+ must both be a Date object, and represent the same date. def eql_r? (other) Date === other && self == other end # :nodoc: private :eql_r? - # Calculate a hash value for this date. def hash_r() ajd.hash end # :nodoc: private :hash_r - # Return internal object state as a programmer-readable string. def inspect_r # :nodoc: format('#<%s[R]: %s (%s,%s,%s)>', self.class, to_s_r, ajd, offset, start) end private :inspect_r - # Return the date as a human-readable string. - # - # The format used is YYYY-MM-DD. def to_s_r() format('%.4d-%02d-%02d', year, mon, mday) end # :nodoc: # 4p private :to_s_r @@ -1598,19 +1463,6 @@ class DateTime < Date new_l!(jd, df, sf, odf, sg) end - # Create a new DateTime object corresponding to the specified - # Julian Day Number +jd+ and hour +h+, minute +min+, second +s+. - # - # The 24-hour clock is used. Negative values of +h+, +min+, and - # +sec+ are treating as counting backwards from the end of the - # next larger unit (e.g. a +min+ of -2 is treated as 58). No - # wraparound is performed. If an invalid time portion is specified, - # an ArgumentError is raised. - # - # +of+ is the offset from UTC as a fraction of a day (defaults to 0). - # +sg+ specifies the Day of Calendar Reform. - # - # All day/time values default to 0. def self.jd_r(jd=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: unless (jd = _valid_jd?(jd, sg)) && (fr = _valid_time?(h, min, s)) @@ -1626,20 +1478,6 @@ class DateTime < Date private_class_method :jd_r - # Create a new DateTime object corresponding to the specified - # Ordinal Date and hour +h+, minute +min+, second +s+. - # - # The 24-hour clock is used. Negative values of +h+, +min+, and - # +sec+ are treating as counting backwards from the end of the - # next larger unit (e.g. a +min+ of -2 is treated as 58). No - # wraparound is performed. If an invalid time portion is specified, - # an ArgumentError is raised. - # - # +of+ is the offset from UTC as a fraction of a day (defaults to 0). - # +sg+ specifies the Day of Calendar Reform. - # - # +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number - # day 0. The time values default to 0. def self.ordinal_r(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: unless (jd = _valid_ordinal?(y, d, sg)) && (fr = _valid_time?(h, min, s)) @@ -1655,20 +1493,6 @@ class DateTime < Date private_class_method :ordinal_r - # Create a new DateTime object corresponding to the specified - # Civil Date and hour +h+, minute +min+, second +s+. - # - # The 24-hour clock is used. Negative values of +h+, +min+, and - # +sec+ are treating as counting backwards from the end of the - # next larger unit (e.g. a +min+ of -2 is treated as 58). No - # wraparound is performed. If an invalid time portion is specified, - # an ArgumentError is raised. - # - # +of+ is the offset from UTC as a fraction of a day (defaults to 0). - # +sg+ specifies the Day of Calendar Reform. - # - # +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day - # Number day 0. The time values default to 0. def self.civil_r(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: unless (jd = _valid_civil?(y, m, d, sg)) && (fr = _valid_time?(h, min, s)) @@ -1684,21 +1508,6 @@ class DateTime < Date private_class_method :civil_r - # Create a new DateTime object corresponding to the specified - # Commercial Date and hour +h+, minute +min+, second +s+. - # - # The 24-hour clock is used. Negative values of +h+, +min+, and - # +sec+ are treating as counting backwards from the end of the - # next larger unit (e.g. a +min+ of -2 is treated as 58). No - # wraparound is performed. If an invalid time portion is specified, - # an ArgumentError is raised. - # - # +of+ is the offset from UTC as a fraction of a day (defaults to 0). - # +sg+ specifies the Day of Calendar Reform. - # - # +y+ defaults to -4712, +w+ to 1, and +d+ to 1; this is - # Julian Day Number day 0. - # The time values default to 0. def self.commercial_r(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc: unless (jd = _valid_commercial?(y, w, d, sg)) && (fr = _valid_time?(h, min, s)) diff --git a/ext/date/lib/date/format.rb b/ext/date/lib/date/format.rb index 6894e945e3..04168ef014 100644 --- a/ext/date/lib/date/format.rb +++ b/ext/date/lib/date/format.rb @@ -1,5 +1,4 @@ # format.rb: Written by Tadayoshi Funaba 1999-2010 -# $Id: format.rb,v 2.43 2008-01-17 20:16:31+09 tadf Exp $ class Date