mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Revert r11453
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4ee717dcae
commit
46fa18da5b
23 changed files with 466 additions and 352 deletions
23
ChangeLog
23
ChangeLog
|
@ -1,11 +1,24 @@
|
||||||
Wed Jan 3 11:36:51 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* io.c (ruby_dup): start GC on ENOMEM as well.
|
* lib/rdoc/parsers/c_parser.rb: Make Rdoc accessible. Update constant
|
||||||
|
value information.
|
||||||
|
|
||||||
Thu Dec 21 15:37:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Mon Jan 1 06:13:11 2007 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* string.c (rb_str_slice_bang): rdoc description bug fixed.
|
* ext/bigdecimal/bigdecimal.c: Update constant comments to provide
|
||||||
[ruby-core:09754]
|
values for RDoc.
|
||||||
|
|
||||||
|
Mon Jan 1 06:05:55 2007 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts):
|
||||||
|
Allow RDoc comment to give friendly value for rb_define_const. Patch
|
||||||
|
by Daniel Berger <djberg96 at gmail.com>, [ruby-patches-7499].
|
||||||
|
* lib/rdoc/parsers/parse_c.rb (RDoc::C_Parser#handle_constansts): Fix
|
||||||
|
whitespace handling in constant comments.
|
||||||
|
|
||||||
|
Sun Dec 31 00:31:16 2006 Tadayoshi Funaba <tadf@dotrb.org>
|
||||||
|
|
||||||
|
* lib/date.rb, lib/date/format.rb: updated based on date2 4.0.
|
||||||
|
|
||||||
Thu Dec 14 18:29:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Thu Dec 14 18:29:13 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
|
|
@ -1811,76 +1811,94 @@ Init_bigdecimal(void)
|
||||||
/* Exceptions */
|
/* Exceptions */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines whether overflow, underflow or zero divide result in
|
* 0xff: Determines whether overflow, underflow or zero divide result in
|
||||||
* an exception being thrown. See BigDecimal.mode.
|
* an exception being thrown. See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_ALL",INT2FIX(VP_EXCEPTION_ALL));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_ALL",INT2FIX(VP_EXCEPTION_ALL));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when the result of a computation is not a
|
* 0x02: Determines what happens when the result of a computation is not a
|
||||||
* number (NaN). See BigDecimal.mode.
|
* number (NaN). See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_NaN",INT2FIX(VP_EXCEPTION_NaN));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_NaN",INT2FIX(VP_EXCEPTION_NaN));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when the result of a computation is infinity.
|
* 0x01: Determines what happens when the result of a computation is
|
||||||
* See BigDecimal.mode.
|
* infinity. See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_INFINITY",INT2FIX(VP_EXCEPTION_INFINITY));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_INFINITY",INT2FIX(VP_EXCEPTION_INFINITY));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when the result of a computation is an underflow
|
* 0x04: Determines what happens when the result of a computation is an
|
||||||
* (a result too small to be represented). See BigDecimal.mode.
|
* underflow (a result too small to be represented). See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_UNDERFLOW",INT2FIX(VP_EXCEPTION_UNDERFLOW));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_UNDERFLOW",INT2FIX(VP_EXCEPTION_UNDERFLOW));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when the result of a computation is an underflow
|
* 0x01: Determines what happens when the result of a computation is an
|
||||||
* (a result too large to be represented). See BigDecimal.mode.
|
* underflow (a result too large to be represented). See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_OVERFLOW",INT2FIX(VP_EXCEPTION_OVERFLOW));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_OVERFLOW",INT2FIX(VP_EXCEPTION_OVERFLOW));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when a division by zero is performed.
|
* 0x01: Determines what happens when a division by zero is performed.
|
||||||
* See BigDecimal.mode.
|
* See BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "EXCEPTION_ZERODIVIDE",INT2FIX(VP_EXCEPTION_ZERODIVIDE));
|
rb_define_const(rb_cBigDecimal, "EXCEPTION_ZERODIVIDE",INT2FIX(VP_EXCEPTION_ZERODIVIDE));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determines what happens when a result must be rounded in order to
|
* 0x100: Determines what happens when a result must be rounded in order to
|
||||||
* fit in the appropriate number of significant digits. See
|
* fit in the appropriate number of significant digits. See
|
||||||
* BigDecimal.mode.
|
* BigDecimal.mode.
|
||||||
*/
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_MODE",INT2FIX(VP_ROUND_MODE));
|
rb_define_const(rb_cBigDecimal, "ROUND_MODE",INT2FIX(VP_ROUND_MODE));
|
||||||
|
|
||||||
/* Indicates that values should be rounded away from zero. See BigDecimal.mode. */
|
/* 1: Indicates that values should be rounded away from zero. See
|
||||||
|
* BigDecimal.mode.
|
||||||
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_UP",INT2FIX(VP_ROUND_UP));
|
rb_define_const(rb_cBigDecimal, "ROUND_UP",INT2FIX(VP_ROUND_UP));
|
||||||
/* Indicates that values should be rounded towards zero. See BigDecimal.mode. */
|
|
||||||
|
/* 2: Indicates that values should be rounded towards zero. See
|
||||||
|
* BigDecimal.mode.
|
||||||
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_DOWN",INT2FIX(VP_ROUND_DOWN));
|
rb_define_const(rb_cBigDecimal, "ROUND_DOWN",INT2FIX(VP_ROUND_DOWN));
|
||||||
/* Indicates that digits >= 5 should be rounded up, others rounded down. See BigDecimal.mode. */
|
|
||||||
|
/* 3: Indicates that digits >= 5 should be rounded up, others rounded down.
|
||||||
|
* See BigDecimal.mode. */
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_HALF_UP",INT2FIX(VP_ROUND_HALF_UP));
|
rb_define_const(rb_cBigDecimal, "ROUND_HALF_UP",INT2FIX(VP_ROUND_HALF_UP));
|
||||||
/* Indicates that digits >= 6 should be rounded up, others rounded down. See BigDecimal.mode. */
|
|
||||||
|
/* 4: Indicates that digits >= 6 should be rounded up, others rounded down.
|
||||||
|
* See BigDecimal.mode.
|
||||||
|
*/
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_HALF_DOWN",INT2FIX(VP_ROUND_HALF_DOWN));
|
rb_define_const(rb_cBigDecimal, "ROUND_HALF_DOWN",INT2FIX(VP_ROUND_HALF_DOWN));
|
||||||
/* Round towards +infinity. See BigDecimal.mode. */
|
/* 5: Round towards +infinity. See BigDecimal.mode. */
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_CEILING",INT2FIX(VP_ROUND_CEIL));
|
rb_define_const(rb_cBigDecimal, "ROUND_CEILING",INT2FIX(VP_ROUND_CEIL));
|
||||||
/* Round towards -infinity. See BigDecimal.mode. */
|
|
||||||
|
/* 6: Round towards -infinity. See BigDecimal.mode. */
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_FLOOR",INT2FIX(VP_ROUND_FLOOR));
|
rb_define_const(rb_cBigDecimal, "ROUND_FLOOR",INT2FIX(VP_ROUND_FLOOR));
|
||||||
/* Round towards the even neighbor. See BigDecimal.mode. */
|
|
||||||
|
/* 7: Round towards the even neighbor. See BigDecimal.mode. */
|
||||||
rb_define_const(rb_cBigDecimal, "ROUND_HALF_EVEN",INT2FIX(VP_ROUND_HALF_EVEN));
|
rb_define_const(rb_cBigDecimal, "ROUND_HALF_EVEN",INT2FIX(VP_ROUND_HALF_EVEN));
|
||||||
|
|
||||||
/* Indicates that a value is not a number. See BigDecimal.sign. */
|
/* 0: Indicates that a value is not a number. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_NaN",INT2FIX(VP_SIGN_NaN));
|
rb_define_const(rb_cBigDecimal, "SIGN_NaN",INT2FIX(VP_SIGN_NaN));
|
||||||
/* Indicates that a value is +0. See BigDecimal.sign. */
|
|
||||||
|
/* 1: Indicates that a value is +0. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_ZERO",INT2FIX(VP_SIGN_POSITIVE_ZERO));
|
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_ZERO",INT2FIX(VP_SIGN_POSITIVE_ZERO));
|
||||||
/* Indicates that a value is -0. See BigDecimal.sign. */
|
|
||||||
|
/* -1: Indicates that a value is -0. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_ZERO",INT2FIX(VP_SIGN_NEGATIVE_ZERO));
|
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_ZERO",INT2FIX(VP_SIGN_NEGATIVE_ZERO));
|
||||||
/* Indicates that a value is positive and finite. See BigDecimal.sign. */
|
|
||||||
|
/* 2: Indicates that a value is positive and finite. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_FINITE",INT2FIX(VP_SIGN_POSITIVE_FINITE));
|
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_FINITE",INT2FIX(VP_SIGN_POSITIVE_FINITE));
|
||||||
/* Indicates that a value is negative and finite. See BigDecimal.sign. */
|
|
||||||
|
/* -2: Indicates that a value is negative and finite. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_FINITE",INT2FIX(VP_SIGN_NEGATIVE_FINITE));
|
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_FINITE",INT2FIX(VP_SIGN_NEGATIVE_FINITE));
|
||||||
/* Indicates that a value is positive and infinite. See BigDecimal.sign. */
|
|
||||||
|
/* 3: Indicates that a value is positive and infinite. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_INFINITE",INT2FIX(VP_SIGN_POSITIVE_INFINITE));
|
rb_define_const(rb_cBigDecimal, "SIGN_POSITIVE_INFINITE",INT2FIX(VP_SIGN_POSITIVE_INFINITE));
|
||||||
/* Indicates that a value is negative and infinite. See BigDecimal.sign. */
|
|
||||||
|
/* -3: Indicates that a value is negative and infinite. See BigDecimal.sign. */
|
||||||
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE",INT2FIX(VP_SIGN_NEGATIVE_INFINITE));
|
rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE",INT2FIX(VP_SIGN_NEGATIVE_INFINITE));
|
||||||
|
|
||||||
/* instance methods */
|
/* instance methods */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: extconf.rb,v $ -- Generator for Makefile
|
= $RCSfile$ -- Generator for Makefile
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: ftptls.rb,v $ -- SSL/TLS enhancement for Net::HTTP.
|
= $RCSfile$ -- SSL/TLS enhancement for Net::HTTP.
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: telnets.rb,v $ -- SSL/TLS enhancement for Net::Telnet.
|
= $RCSfile$ -- SSL/TLS enhancement for Net::Telnet.
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: openssl.rb,v $ -- Loader for all OpenSSL C-space and Ruby-space definitions
|
= $RCSfile$ -- Loader for all OpenSSL C-space and Ruby-space definitions
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: bn.rb,v $ -- Ruby-space definitions that completes C-space funcs for BN
|
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for BN
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: buffering.rb,v $ -- Buffering mix-in module.
|
= $RCSfile$ -- Buffering mix-in module.
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: cipher.rb,v $ -- Ruby-space predefined Cipher subclasses
|
= $RCSfile$ -- Ruby-space predefined Cipher subclasses
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: digest.rb,v $ -- Ruby-space predefined Digest subclasses
|
= $RCSfile$ -- Ruby-space predefined Digest subclasses
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: ssl.rb,v $ -- Ruby-space definitions that completes C-space funcs for SSL
|
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for SSL
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
=begin
|
=begin
|
||||||
= $RCSfile: x509.rb,v $ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses
|
= $RCSfile$ -- Ruby-space definitions that completes C-space funcs for X509 and subclasses
|
||||||
|
|
||||||
= Info
|
= Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
2
io.c
2
io.c
|
@ -318,7 +318,7 @@ ruby_dup(orig)
|
||||||
|
|
||||||
fd = dup(orig);
|
fd = dup(orig);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) {
|
if (errno == EMFILE || errno == ENFILE) {
|
||||||
rb_gc();
|
rb_gc();
|
||||||
fd = dup(orig);
|
fd = dup(orig);
|
||||||
}
|
}
|
||||||
|
|
412
lib/date.rb
412
lib/date.rb
|
@ -6,7 +6,7 @@
|
||||||
# Documentation: William Webber <william@williamwebber.com>
|
# Documentation: William Webber <william@williamwebber.com>
|
||||||
#
|
#
|
||||||
#--
|
#--
|
||||||
# $Id: date.rb,v 2.29 2006-11-05 18:21:29+09 tadf Exp $
|
# $Id: date.rb,v 2.30 2006-12-30 21:43:41+09 tadf Exp $
|
||||||
#++
|
#++
|
||||||
#
|
#
|
||||||
# == Overview
|
# == Overview
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
# This file provides two classes for working with
|
# This file provides two classes for working with
|
||||||
# dates and times.
|
# dates and times.
|
||||||
#
|
#
|
||||||
# The first class, Date, represents dates.
|
# The first class, Date, represents dates.
|
||||||
# It works with years, months, weeks, and days.
|
# It works with years, months, weeks, and days.
|
||||||
# See the Date class documentation for more details.
|
# See the Date class documentation for more details.
|
||||||
#
|
#
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
# The standard civil year is 365 days long. However, the
|
# The standard civil year is 365 days long. However, the
|
||||||
# solar year is fractionally longer than this. To account
|
# solar year is fractionally longer than this. To account
|
||||||
# for this, a *leap* *year* is occasionally inserted. This
|
# for this, a *leap* *year* is occasionally inserted. This
|
||||||
# is a year with 366 days, the extra day falling on February 29.
|
# is a year with 366 days, the extra day falling on February 29.
|
||||||
# In the early days of the civil calendar, every fourth
|
# In the early days of the civil calendar, every fourth
|
||||||
# year without exception was a leap year. This way of
|
# year without exception was a leap year. This way of
|
||||||
# reckoning leap years is the *Julian* *Calendar*.
|
# reckoning leap years is the *Julian* *Calendar*.
|
||||||
|
@ -148,7 +148,7 @@
|
||||||
# of time zones. Time zones are represented as an offset
|
# of time zones. Time zones are represented as an offset
|
||||||
# from UTC, as a fraction of a day. This offset is the
|
# from UTC, as a fraction of a day. This offset is the
|
||||||
# how much local time is later (or earlier) than UTC.
|
# how much local time is later (or earlier) than UTC.
|
||||||
# UTC offset 0 is centred on England (also known as GMT).
|
# UTC offset 0 is centred on England (also known as GMT).
|
||||||
# As you travel east, the offset increases until you
|
# As you travel east, the offset increases until you
|
||||||
# reach the dateline in the middle of the Pacific Ocean;
|
# reach the dateline in the middle of the Pacific Ocean;
|
||||||
# as you travel west, the offset decreases. This offset
|
# as you travel west, the offset decreases. This offset
|
||||||
|
@ -323,6 +323,7 @@ class Date
|
||||||
# the answer is true; or it may a number representing the Day of
|
# the answer is true; or it may a number representing the Day of
|
||||||
# Calendar Reform. Date::ENGLAND and Date::ITALY are two possible such
|
# Calendar Reform. Date::ENGLAND and Date::ITALY are two possible such
|
||||||
# days.
|
# days.
|
||||||
|
|
||||||
def self.julian? (jd, sg)
|
def self.julian? (jd, sg)
|
||||||
case sg
|
case sg
|
||||||
when Numeric
|
when Numeric
|
||||||
|
@ -341,7 +342,7 @@ class Date
|
||||||
#
|
#
|
||||||
# The reverse of self.os? See the documentation for that method for
|
# The reverse of self.os? See the documentation for that method for
|
||||||
# more details.
|
# more details.
|
||||||
def self.gregorian? (jd, sg) not julian?(jd, sg) end
|
def self.gregorian? (jd, sg) !julian?(jd, sg) end
|
||||||
|
|
||||||
def self.fix_style(jd, sg) # :nodoc:
|
def self.fix_style(jd, sg) # :nodoc:
|
||||||
if julian?(jd, sg)
|
if julian?(jd, sg)
|
||||||
|
@ -351,6 +352,29 @@ class Date
|
||||||
|
|
||||||
private_class_method :fix_style
|
private_class_method :fix_style
|
||||||
|
|
||||||
|
# Convert an Ordinal Date to a Julian Day Number.
|
||||||
|
#
|
||||||
|
# +y+ and +d+ are the year and day-of-year to convert.
|
||||||
|
# +sg+ specifies the Day of Calendar Reform.
|
||||||
|
#
|
||||||
|
# Returns the corresponding Julian Day Number.
|
||||||
|
def self.ordinal_to_jd(y, d, sg=GREGORIAN)
|
||||||
|
civil_to_jd(y, 1, d, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Convert a Julian Day Number to an Ordinal Date.
|
||||||
|
#
|
||||||
|
# +jd+ is the Julian Day Number to convert.
|
||||||
|
# +sg+ specifies the Day of Calendar Reform.
|
||||||
|
#
|
||||||
|
# Returns the corresponding Ordinal Date as
|
||||||
|
# [year, day_of_year]
|
||||||
|
def self.jd_to_ordinal(jd, sg=GREGORIAN)
|
||||||
|
y = jd_to_civil(jd, sg)[0]
|
||||||
|
doy = jd - civil_to_jd(y - 1, 12, 31, fix_style(jd, sg))
|
||||||
|
return y, doy
|
||||||
|
end
|
||||||
|
|
||||||
# Convert a Civil Date to a Julian Day Number.
|
# Convert a Civil Date to a Julian Day Number.
|
||||||
# +y+, +m+, and +d+ are the year, month, and day of the
|
# +y+, +m+, and +d+ are the year, month, and day of the
|
||||||
# month. +sg+ specifies the Day of Calendar Reform.
|
# month. +sg+ specifies the Day of Calendar Reform.
|
||||||
|
@ -400,27 +424,16 @@ class Date
|
||||||
return y, m, dom
|
return y, m, dom
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert a Julian Day Number to an Ordinal Date.
|
# Convert a Commercial Date to a Julian Day Number.
|
||||||
#
|
#
|
||||||
# +jd+ is the Julian Day Number to convert.
|
# +y+, +w+, and +d+ are the (commercial) year, week of the year,
|
||||||
|
# and day of the week of the Commercial Date to convert.
|
||||||
# +sg+ specifies the Day of Calendar Reform.
|
# +sg+ specifies the Day of Calendar Reform.
|
||||||
#
|
def self.commercial_to_jd(y, w, d, ns=GREGORIAN)
|
||||||
# Returns the corresponding Ordinal Date as
|
jd = civil_to_jd(y, 1, 4, ns)
|
||||||
# [year, day_of_year]
|
(jd - (((jd - 1) + 1) % 7)) +
|
||||||
def self.jd_to_ordinal(jd, sg=GREGORIAN)
|
7 * (w - 1) +
|
||||||
y = jd_to_civil(jd, sg)[0]
|
(d - 1)
|
||||||
doy = jd - civil_to_jd(y - 1, 12, 31, fix_style(jd, sg))
|
|
||||||
return y, doy
|
|
||||||
end
|
|
||||||
|
|
||||||
# Convert an Ordinal Date to a Julian Day Number.
|
|
||||||
#
|
|
||||||
# +y+ and +d+ are the year and day-of-year to convert.
|
|
||||||
# +sg+ specifies the Day of Calendar Reform.
|
|
||||||
#
|
|
||||||
# Returns the corresponding Julian Day Number.
|
|
||||||
def self.ordinal_to_jd(y, d, sg=GREGORIAN)
|
|
||||||
civil_to_jd(y, 1, d, sg)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert a Julian Day Number to a Commercial Date
|
# Convert a Julian Day Number to a Commercial Date
|
||||||
|
@ -436,39 +449,29 @@ class Date
|
||||||
y = if jd >= commercial_to_jd(a + 1, 1, 1, ns) then a + 1 else a end
|
y = if jd >= commercial_to_jd(a + 1, 1, 1, ns) then a + 1 else a end
|
||||||
w = 1 + ((jd - commercial_to_jd(y, 1, 1, ns)) / 7).floor
|
w = 1 + ((jd - commercial_to_jd(y, 1, 1, ns)) / 7).floor
|
||||||
d = (jd + 1) % 7
|
d = (jd + 1) % 7
|
||||||
if d.zero? then d = 7 end
|
d = 7 if d == 0
|
||||||
return y, w, d
|
return y, w, d
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert a Commercial Date to a Julian Day Number.
|
def self.weeknum_to_jd(y, w, d, f=0, ns=GREGORIAN) # :nodoc:
|
||||||
#
|
a = civil_to_jd(y, 1, 1, ns) + 6
|
||||||
# +y+, +w+, and +d+ are the (commercial) year, week of the year,
|
(a - ((a - f) + 1) % 7 - 7) + 7 * w + d
|
||||||
# and day of the week of the Commercial Date to convert.
|
|
||||||
# +sg+ specifies the Day of Calendar Reform.
|
|
||||||
def self.commercial_to_jd(y, w, d, ns=GREGORIAN)
|
|
||||||
jd = civil_to_jd(y, 1, 4, ns)
|
|
||||||
(jd - (((jd - 1) + 1) % 7)) +
|
|
||||||
7 * (w - 1) +
|
|
||||||
(d - 1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.jd_to_weeknum(jd, k=0, sg=GREGORIAN) # :nodoc:
|
def self.jd_to_weeknum(jd, f=0, sg=GREGORIAN) # :nodoc:
|
||||||
ns = fix_style(jd, sg)
|
ns = fix_style(jd, sg)
|
||||||
y, m, d = jd_to_civil(jd, ns)
|
y, m, d = jd_to_civil(jd, ns)
|
||||||
a = civil_to_jd(y, 1, 1, ns) + 6
|
a = civil_to_jd(y, 1, 1, ns) + 6
|
||||||
w, d = (jd - (a - ((a - k) + 1) % 7) + 7).divmod(7)
|
w, d = (jd - (a - ((a - f) + 1) % 7) + 7).divmod(7)
|
||||||
return y, w, d
|
return y, w, d
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.weeknum_to_jd(y, w, d, k=0, ns=GREGORIAN) # :nodoc:
|
private_class_method :weeknum_to_jd, :jd_to_weeknum
|
||||||
a = civil_to_jd(y, 1, 1, ns) + 6
|
|
||||||
(a - ((a - k) + 1) % 7 - 7) + 7 * w + d
|
|
||||||
end
|
|
||||||
|
|
||||||
# Convert an Astronomical Julian Day Number to a (civil) Julian
|
# Convert an Astronomical Julian Day Number to a (civil) Julian
|
||||||
# Day Number.
|
# Day Number.
|
||||||
#
|
#
|
||||||
# +ajd+ is the Astronomical Julian Day Number to convert.
|
# +ajd+ is the Astronomical Julian Day Number to convert.
|
||||||
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
|
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
|
||||||
#
|
#
|
||||||
# Returns the (civil) Julian Day Number as [day_number,
|
# Returns the (civil) Julian Day Number as [day_number,
|
||||||
|
@ -479,7 +482,7 @@ class Date
|
||||||
# Day Number.
|
# Day Number.
|
||||||
#
|
#
|
||||||
# +jd+ is the Julian Day Number to convert, and +fr+ is a
|
# +jd+ is the Julian Day Number to convert, and +fr+ is a
|
||||||
# fractional day.
|
# fractional day.
|
||||||
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
|
# +of+ is the offset from UTC as a fraction of a day (defaults to 0).
|
||||||
#
|
#
|
||||||
# Returns the Astronomical Julian Day Number as a single
|
# Returns the Astronomical Julian Day Number as a single
|
||||||
|
@ -539,10 +542,10 @@ class Date
|
||||||
#
|
#
|
||||||
# All years divisible by 4 are leap years in the Gregorian calendar,
|
# All years divisible by 4 are leap years in the Gregorian calendar,
|
||||||
# except for years divisible by 100 and not by 400.
|
# except for years divisible by 100 and not by 400.
|
||||||
def self.gregorian_leap? (y) y % 4 == 0 and y % 100 != 0 or y % 400 == 0 end
|
def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end
|
||||||
|
|
||||||
class << self; alias_method :leap?, :gregorian_leap? end
|
class << self; alias_method :leap?, :gregorian_leap? end
|
||||||
class << self; alias_method :new0, :new end
|
class << self; alias_method :new!, :new end
|
||||||
|
|
||||||
# Is +jd+ a valid Julian Day Number?
|
# Is +jd+ a valid Julian Day Number?
|
||||||
#
|
#
|
||||||
|
@ -550,16 +553,6 @@ class Date
|
||||||
# Julian Day Number.
|
# Julian Day Number.
|
||||||
def self.valid_jd? (jd, sg=ITALY) jd end
|
def self.valid_jd? (jd, sg=ITALY) jd 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(jd=0, sg=ITALY)
|
|
||||||
jd = valid_jd?(jd, sg)
|
|
||||||
new0(jd_to_ajd(jd, 0, 0), 0, sg)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do the year +y+ and day-of-year +d+ make a valid Ordinal Date?
|
# Do the year +y+ and day-of-year +d+ make a valid Ordinal Date?
|
||||||
# Returns the corresponding Julian Day Number if they do, or
|
# Returns the corresponding Julian Day Number if they do, or
|
||||||
# nil if they don't.
|
# nil if they don't.
|
||||||
|
@ -568,7 +561,7 @@ class Date
|
||||||
# from the end of the year (-1 being the last day of the year).
|
# from the end of the year (-1 being the last day of the year).
|
||||||
# No year wraparound is performed, however, so valid values of
|
# No year wraparound is performed, however, so valid values of
|
||||||
# +d+ are -365 .. -1, 1 .. 365 on a non-leap-year,
|
# +d+ are -365 .. -1, 1 .. 365 on a non-leap-year,
|
||||||
# -366 .. -1, 1 .. 366 on a leap year.
|
# -366 .. -1, 1 .. 366 on a leap year.
|
||||||
# A date falling in the period skipped in the Day of Calendar Reform
|
# A date falling in the period skipped in the Day of Calendar Reform
|
||||||
# adjustment is not valid.
|
# adjustment is not valid.
|
||||||
#
|
#
|
||||||
|
@ -587,23 +580,6 @@ class Date
|
||||||
jd
|
jd
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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(y=-4712, d=1, sg=ITALY)
|
|
||||||
unless jd = valid_ordinal?(y, d, sg)
|
|
||||||
raise ArgumentError, 'invalid date'
|
|
||||||
end
|
|
||||||
new0(jd_to_ajd(jd, 0, 0), 0, sg)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do year +y+, month +m+, and day-of-month +d+ make a
|
# Do year +y+, month +m+, and day-of-month +d+ make a
|
||||||
# valid Civil Date? Returns the corresponding Julian
|
# valid Civil Date? Returns the corresponding Julian
|
||||||
# Day Number if they do, nil if they don't.
|
# Day Number if they do, nil if they don't.
|
||||||
|
@ -636,28 +612,6 @@ class Date
|
||||||
|
|
||||||
class << self; alias_method :valid_date?, :valid_civil? end
|
class << self; alias_method :valid_date?, :valid_civil? end
|
||||||
|
|
||||||
# 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(y=-4712, m=1, d=1, sg=ITALY)
|
|
||||||
unless jd = valid_civil?(y, m, d, sg)
|
|
||||||
raise ArgumentError, 'invalid date'
|
|
||||||
end
|
|
||||||
new0(jd_to_ajd(jd, 0, 0), 0, sg)
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self; alias_method :new, :civil end
|
|
||||||
|
|
||||||
# Do year +y+, week-of-year +w+, and day-of-week +d+ make a
|
# Do year +y+, week-of-year +w+, and day-of-week +d+ make a
|
||||||
# valid Commercial Date? Returns the corresponding Julian
|
# valid Commercial Date? Returns the corresponding Julian
|
||||||
# Day Number if they do, nil if they don't.
|
# Day Number if they do, nil if they don't.
|
||||||
|
@ -677,7 +631,10 @@ class Date
|
||||||
d += 8
|
d += 8
|
||||||
end
|
end
|
||||||
if w < 0
|
if w < 0
|
||||||
w = jd_to_commercial(commercial_to_jd(y + 1, 1, 1) + w * 7)[1]
|
ny, nw, nd =
|
||||||
|
jd_to_commercial(commercial_to_jd(y + 1, 1, 1) + w * 7)
|
||||||
|
return unless ny == y
|
||||||
|
w = nw
|
||||||
end
|
end
|
||||||
jd = commercial_to_jd(y, w, d)
|
jd = commercial_to_jd(y, w, d)
|
||||||
return unless gregorian?(jd, sg)
|
return unless gregorian?(jd, sg)
|
||||||
|
@ -685,6 +642,95 @@ class Date
|
||||||
jd
|
jd
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.valid_weeknum? (y, w, d, f, sg=ITALY) # :nodoc:
|
||||||
|
if d < 0
|
||||||
|
d += 7
|
||||||
|
end
|
||||||
|
if w < 0
|
||||||
|
ny, nw, nd, nf =
|
||||||
|
jd_to_weeknum(weeknum_to_jd(y + 1, 1, f, f) + w * 7, f)
|
||||||
|
return unless ny == y
|
||||||
|
w = nw
|
||||||
|
end
|
||||||
|
jd = weeknum_to_jd(y, w, d, f)
|
||||||
|
return unless gregorian?(jd, sg)
|
||||||
|
return unless [y, w, d] == jd_to_weeknum(jd, f)
|
||||||
|
jd
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method :valid_weeknum?
|
||||||
|
|
||||||
|
# Do hour +h+, minute +min+, and second +s+ constitute a valid time?
|
||||||
|
#
|
||||||
|
# If they do, returns their value as a fraction of a day. If not,
|
||||||
|
# returns nil.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
def self.valid_time? (h, min, s)
|
||||||
|
h += 24 if h < 0
|
||||||
|
min += 60 if min < 0
|
||||||
|
s += 60 if s < 0
|
||||||
|
return unless ((0..23) === h &&
|
||||||
|
(0..59) === min &&
|
||||||
|
(0..59) === s) ||
|
||||||
|
(24 == h &&
|
||||||
|
0 == min &&
|
||||||
|
0 == s)
|
||||||
|
time_to_day_fraction(h, min, s)
|
||||||
|
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(jd=0, sg=ITALY)
|
||||||
|
jd = valid_jd?(jd, sg)
|
||||||
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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(y=-4712, d=1, sg=ITALY)
|
||||||
|
unless jd = valid_ordinal?(y, d, sg)
|
||||||
|
raise ArgumentError, 'invalid date'
|
||||||
|
end
|
||||||
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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(y=-4712, m=1, d=1, sg=ITALY)
|
||||||
|
unless jd = valid_civil?(y, m, d, sg)
|
||||||
|
raise ArgumentError, 'invalid date'
|
||||||
|
end
|
||||||
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
class << self; alias_method :new, :civil end
|
||||||
|
|
||||||
# Create a new Date object for the Commercial Date specified by
|
# Create a new Date object for the Commercial Date specified by
|
||||||
# year +y+, week-of-year +w+, and day-of-week +d+.
|
# year +y+, week-of-year +w+, and day-of-week +d+.
|
||||||
#
|
#
|
||||||
|
@ -703,24 +749,19 @@ class Date
|
||||||
unless jd = valid_commercial?(y, w, d, sg)
|
unless jd = valid_commercial?(y, w, d, sg)
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
new0(jd_to_ajd(jd, 0, 0), 0, sg)
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.valid_weeknum? (y, w, d, k, sg=ITALY) # :nodoc:
|
def self.weeknum(y=1582, w=41, d=5, f=0, sg=ITALY) # :nodoc:
|
||||||
if d < 0
|
unless jd = valid_weeknum?(y, w, d, f, sg)
|
||||||
d += 7
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
if w < 0
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
w = jd_to_weeknum(weeknum_to_jd(y + 1, 1, k, k) + w * 7, k)[1]
|
|
||||||
end
|
|
||||||
jd = weeknum_to_jd(y, w, d, k)
|
|
||||||
return unless [y, w, d] == jd_to_weeknum(jd, k)
|
|
||||||
jd
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method :valid_weeknum?
|
private_class_method :weeknum
|
||||||
|
|
||||||
def self.rewrite_hash(elem) # :nodoc:
|
def self.rewrite_frags(elem) # :nodoc:
|
||||||
elem ||= {}
|
elem ||= {}
|
||||||
if seconds = elem[:seconds]
|
if seconds = elem[:seconds]
|
||||||
d, fr = seconds.divmod(86400)
|
d, fr = seconds.divmod(86400)
|
||||||
|
@ -738,7 +779,9 @@ class Date
|
||||||
elem
|
elem
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.complete_hash(elem) # :nodoc:
|
private_class_method :rewrite_frags
|
||||||
|
|
||||||
|
def self.complete_frags(elem) # :nodoc:
|
||||||
i = 0
|
i = 0
|
||||||
g = [[:time, [:hour, :min, :sec]],
|
g = [[:time, [:hour, :min, :sec]],
|
||||||
[nil, [:jd]],
|
[nil, [:jd]],
|
||||||
|
@ -812,7 +855,9 @@ class Date
|
||||||
elem
|
elem
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.valid_date_with_hash?(elem, sg) # :nodoc:
|
private_class_method :complete_frags
|
||||||
|
|
||||||
|
def self.valid_date_frags?(elem, sg) # :nodoc:
|
||||||
catch :jd do
|
catch :jd do
|
||||||
a = elem.values_at(:jd)
|
a = elem.values_at(:jd)
|
||||||
if a.all?
|
if a.all?
|
||||||
|
@ -870,17 +915,25 @@ class Date
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new_with_hash(elem, sg) # :nodoc:
|
private_class_method :valid_date_frags?
|
||||||
elem = rewrite_hash(elem)
|
|
||||||
elem = complete_hash(elem)
|
def self.valid_time_frags? (elem) # :nodoc:
|
||||||
unless jd = valid_date_with_hash?(elem, sg)
|
h, min, s = elem.values_at(:hour, :min, :sec)
|
||||||
raise ArgumentError, 'invalid date'
|
valid_time?(h, min, s)
|
||||||
end
|
|
||||||
new0(jd_to_ajd(jd, 0, 0), 0, sg)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method :rewrite_hash, :complete_hash,
|
private_class_method :valid_time_frags?
|
||||||
:valid_date_with_hash?, :new_with_hash
|
|
||||||
|
def self.new_by_frags(elem, sg) # :nodoc:
|
||||||
|
elem = rewrite_frags(elem)
|
||||||
|
elem = complete_frags(elem)
|
||||||
|
unless jd = valid_date_frags?(elem, sg)
|
||||||
|
raise ArgumentError, 'invalid date'
|
||||||
|
end
|
||||||
|
new!(jd_to_ajd(jd, 0, 0), 0, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method :new_by_frags
|
||||||
|
|
||||||
# Create a new Date object by parsing from a String
|
# Create a new Date object by parsing from a String
|
||||||
# according to a specified format.
|
# according to a specified format.
|
||||||
|
@ -899,13 +952,13 @@ class Date
|
||||||
# parsed.
|
# parsed.
|
||||||
def self.strptime(str='-4712-01-01', fmt='%F', sg=ITALY)
|
def self.strptime(str='-4712-01-01', fmt='%F', sg=ITALY)
|
||||||
elem = _strptime(str, fmt)
|
elem = _strptime(str, fmt)
|
||||||
new_with_hash(elem, sg)
|
new_by_frags(elem, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new Date object by parsing from a String,
|
# Create a new Date object by parsing from a String,
|
||||||
# without specifying the format.
|
# without specifying the format.
|
||||||
#
|
#
|
||||||
# +str+ is a String holding a date representation.
|
# +str+ is a String holding a date representation.
|
||||||
# +comp+ specifies whether to interpret 2-digit years
|
# +comp+ specifies whether to interpret 2-digit years
|
||||||
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
|
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
|
||||||
# The method will attempt to parse a date from the String
|
# The method will attempt to parse a date from the String
|
||||||
|
@ -919,7 +972,7 @@ class Date
|
||||||
# +sg+ specifies the Day of Calendar Reform.
|
# +sg+ specifies the Day of Calendar Reform.
|
||||||
def self.parse(str='-4712-01-01', comp=false, sg=ITALY)
|
def self.parse(str='-4712-01-01', comp=false, sg=ITALY)
|
||||||
elem = _parse(str, comp)
|
elem = _parse(str, comp)
|
||||||
new_with_hash(elem, sg)
|
new_by_frags(elem, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -940,7 +993,7 @@ class Date
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# *NOTE* this is the documentation for the method new0(). If
|
# *NOTE* this is the documentation for the method new!(). If
|
||||||
# you are reading this as the documentation for new(), that is
|
# you are reading this as the documentation for new(), that is
|
||||||
# because rdoc doesn't fully support the aliasing of the
|
# because rdoc doesn't fully support the aliasing of the
|
||||||
# initialize() method.
|
# initialize() method.
|
||||||
|
@ -993,8 +1046,8 @@ class Date
|
||||||
# Get the date as a Commercial Date, [year, week_of_year, day_of_week]
|
# Get the date as a Commercial Date, [year, week_of_year, day_of_week]
|
||||||
def commercial() self.class.jd_to_commercial(jd, @sg) end # :nodoc:
|
def commercial() self.class.jd_to_commercial(jd, @sg) end # :nodoc:
|
||||||
|
|
||||||
def weeknum0() self.class.jd_to_weeknum(jd, 0, @sg) end # :nodoc:
|
def weeknum0() self.class.__send__(:jd_to_weeknum, jd, 0, @sg) end # :nodoc:
|
||||||
def weeknum1() self.class.jd_to_weeknum(jd, 1, @sg) end # :nodoc:
|
def weeknum1() self.class.__send__(:jd_to_weeknum, jd, 1, @sg) end # :nodoc:
|
||||||
|
|
||||||
once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
|
once :civil, :ordinal, :commercial, :weeknum0, :weeknum1
|
||||||
private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
|
private :civil, :ordinal, :commercial, :weeknum0, :weeknum1
|
||||||
|
@ -1039,7 +1092,8 @@ class Date
|
||||||
# Get the second of this date.
|
# Get the second of this date.
|
||||||
def sec() time[2] end
|
def sec() time[2] end
|
||||||
|
|
||||||
# Get the fraction-of-a-second of this date.
|
# Get the fraction-of-a-second of this date. The unit is in days.
|
||||||
|
# I do NOT recommend you to use this method.
|
||||||
def sec_fraction() time[3] end
|
def sec_fraction() time[3] end
|
||||||
|
|
||||||
private :hour, :min, :sec, :sec_fraction
|
private :hour, :min, :sec, :sec_fraction
|
||||||
|
@ -1105,7 +1159,7 @@ class Date
|
||||||
def start() @sg end
|
def start() @sg end
|
||||||
|
|
||||||
# Create a copy of this Date object using a new Day of Calendar Reform.
|
# Create a copy of this Date object using a new Day of Calendar Reform.
|
||||||
def new_start(sg=self.class::ITALY) self.class.new0(@ajd, @of, sg) end
|
def new_start(sg=self.class::ITALY) self.class.new!(@ajd, @of, sg) end
|
||||||
|
|
||||||
# Create a copy of this Date object that uses the Italian/Catholic
|
# Create a copy of this Date object that uses the Italian/Catholic
|
||||||
# Day of Calendar Reform.
|
# Day of Calendar Reform.
|
||||||
|
@ -1129,7 +1183,7 @@ class Date
|
||||||
if String === of
|
if String === of
|
||||||
of = (self.class.zone_to_diff(of) || 0).to_r/86400
|
of = (self.class.zone_to_diff(of) || 0).to_r/86400
|
||||||
end
|
end
|
||||||
self.class.new0(@ajd, of, @sg)
|
self.class.new!(@ajd, of, @sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
private :offset, :new_offset
|
private :offset, :new_offset
|
||||||
|
@ -1145,7 +1199,7 @@ class Date
|
||||||
# particular, two Dates cannot be added to each other.
|
# particular, two Dates cannot be added to each other.
|
||||||
def + (n)
|
def + (n)
|
||||||
case n
|
case n
|
||||||
when Numeric; return self.class.new0(@ajd + n, @of, @sg)
|
when Numeric; return self.class.new!(@ajd + n, @of, @sg)
|
||||||
end
|
end
|
||||||
raise TypeError, 'expected numeric'
|
raise TypeError, 'expected numeric'
|
||||||
end
|
end
|
||||||
|
@ -1160,7 +1214,7 @@ class Date
|
||||||
# If +x+ is neither Numeric nor a Date, a TypeError is raised.
|
# If +x+ is neither Numeric nor a Date, a TypeError is raised.
|
||||||
def - (x)
|
def - (x)
|
||||||
case x
|
case x
|
||||||
when Numeric; return self.class.new0(@ajd - x, @of, @sg)
|
when Numeric; return self.class.new!(@ajd - x, @of, @sg)
|
||||||
when Date; return @ajd - x.ajd
|
when Date; return @ajd - x.ajd
|
||||||
end
|
end
|
||||||
raise TypeError, 'expected numeric or date'
|
raise TypeError, 'expected numeric or date'
|
||||||
|
@ -1217,7 +1271,7 @@ class Date
|
||||||
# of the returned Date will be the last day of the target month.
|
# of the returned Date will be the last day of the target month.
|
||||||
def >> (n)
|
def >> (n)
|
||||||
y, m = (year * 12 + (mon - 1) + n).divmod(12)
|
y, m = (year * 12 + (mon - 1) + n).divmod(12)
|
||||||
m, = (m + 1).divmod(1)
|
m, = (m + 1) .divmod(1)
|
||||||
d = mday
|
d = mday
|
||||||
d -= 1 until jd2 = self.class.valid_civil?(y, m, d, fix_style)
|
d -= 1 until jd2 = self.class.valid_civil?(y, m, d, fix_style)
|
||||||
self + (jd2 - jd)
|
self + (jd2 - jd)
|
||||||
|
@ -1275,7 +1329,7 @@ class Date
|
||||||
# Is this Date equal to +other+?
|
# Is this Date equal to +other+?
|
||||||
#
|
#
|
||||||
# +other+ must both be a Date object, and represent the same date.
|
# +other+ must both be a Date object, and represent the same date.
|
||||||
def eql? (other) Date === other and self == other end
|
def eql? (other) Date === other && self == other end
|
||||||
|
|
||||||
# Calculate a hash value for this date.
|
# Calculate a hash value for this date.
|
||||||
def hash() @ajd.hash end
|
def hash() @ajd.hash end
|
||||||
|
@ -1291,7 +1345,7 @@ class Date
|
||||||
# Dump to Marshal format.
|
# Dump to Marshal format.
|
||||||
def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end
|
def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end
|
||||||
|
|
||||||
# def self._load(str) new0(*Marshal.load(str)) end
|
# def self._load(str) new!(*Marshal.load(str)) end
|
||||||
|
|
||||||
# Load from Marshall format.
|
# Load from Marshall format.
|
||||||
def self._load(str)
|
def self._load(str)
|
||||||
|
@ -1303,7 +1357,7 @@ class Date
|
||||||
else
|
else
|
||||||
ajd, of, sg = a
|
ajd, of, sg = a
|
||||||
end
|
end
|
||||||
new0(ajd, of, sg)
|
new!(ajd, of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1338,7 +1392,8 @@ end
|
||||||
# === sec_fraction()
|
# === sec_fraction()
|
||||||
#
|
#
|
||||||
# Get the fraction of a second of the time. This is returned as
|
# Get the fraction of a second of the time. This is returned as
|
||||||
# a +Rational+.
|
# a +Rational+. The unit is in days.
|
||||||
|
# I do NOT recommend you to use this method.
|
||||||
#
|
#
|
||||||
# === zone()
|
# === zone()
|
||||||
#
|
#
|
||||||
|
@ -1358,35 +1413,6 @@ end
|
||||||
#
|
#
|
||||||
class DateTime < Date
|
class DateTime < Date
|
||||||
|
|
||||||
# Do hour +h+, minute +min+, and second +s+ constitute a valid time?
|
|
||||||
#
|
|
||||||
# If they do, returns their value as a fraction of a day. If not,
|
|
||||||
# returns nil.
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
def self.valid_time? (h, min, s)
|
|
||||||
h += 24 if h < 0
|
|
||||||
min += 60 if min < 0
|
|
||||||
s += 60 if s < 0
|
|
||||||
return unless ((0..23) === h and
|
|
||||||
(0..59) === min and
|
|
||||||
(0..59) === s) or
|
|
||||||
(24 == h and
|
|
||||||
0 == min and
|
|
||||||
0 == s)
|
|
||||||
time_to_day_fraction(h, min, s)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.valid_time_with_hash? (elem) # :nodoc:
|
|
||||||
h, min, s = elem.values_at(:hour, :min, :sec)
|
|
||||||
valid_time?(h, min, s)
|
|
||||||
end
|
|
||||||
|
|
||||||
private_class_method :valid_time_with_hash?
|
|
||||||
|
|
||||||
# Create a new DateTime object corresponding to the specified
|
# Create a new DateTime object corresponding to the specified
|
||||||
# Julian Day Number +jd+ and hour +h+, minute +min+, second +s+.
|
# Julian Day Number +jd+ and hour +h+, minute +min+, second +s+.
|
||||||
#
|
#
|
||||||
|
@ -1401,14 +1427,14 @@ class DateTime < Date
|
||||||
#
|
#
|
||||||
# All day/time values default to 0.
|
# All day/time values default to 0.
|
||||||
def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
|
def self.jd(jd=0, h=0, min=0, s=0, of=0, sg=ITALY)
|
||||||
unless (jd = valid_jd?(jd, sg)) and
|
unless (jd = valid_jd?(jd, sg)) &&
|
||||||
(fr = valid_time?(h, min, s))
|
(fr = valid_time?(h, min, s))
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
if String === of
|
if String === of
|
||||||
of = (zone_to_diff(of) || 0).to_r/86400
|
of = (zone_to_diff(of) || 0).to_r/86400
|
||||||
end
|
end
|
||||||
new0(jd_to_ajd(jd, fr, of), of, sg)
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new DateTime object corresponding to the specified
|
# Create a new DateTime object corresponding to the specified
|
||||||
|
@ -1426,14 +1452,14 @@ class DateTime < Date
|
||||||
# +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
|
# +y+ defaults to -4712, and +d+ to 1; this is Julian Day Number
|
||||||
# day 0. The time values default to 0.
|
# day 0. The time values default to 0.
|
||||||
def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
def self.ordinal(y=-4712, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
||||||
unless (jd = valid_ordinal?(y, d, sg)) and
|
unless (jd = valid_ordinal?(y, d, sg)) &&
|
||||||
(fr = valid_time?(h, min, s))
|
(fr = valid_time?(h, min, s))
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
if String === of
|
if String === of
|
||||||
of = (zone_to_diff(of) || 0).to_r/86400
|
of = (zone_to_diff(of) || 0).to_r/86400
|
||||||
end
|
end
|
||||||
new0(jd_to_ajd(jd, fr, of), of, sg)
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new DateTime object corresponding to the specified
|
# Create a new DateTime object corresponding to the specified
|
||||||
|
@ -1451,14 +1477,14 @@ class DateTime < Date
|
||||||
# +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
|
# +y+ defaults to -4712, +m+ to 1, and +d+ to 1; this is Julian Day
|
||||||
# Number day 0. The time values default to 0.
|
# Number day 0. The time values default to 0.
|
||||||
def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
def self.civil(y=-4712, m=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
|
||||||
unless (jd = valid_civil?(y, m, d, sg)) and
|
unless (jd = valid_civil?(y, m, d, sg)) &&
|
||||||
(fr = valid_time?(h, min, s))
|
(fr = valid_time?(h, min, s))
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
if String === of
|
if String === of
|
||||||
of = (zone_to_diff(of) || 0).to_r/86400
|
of = (zone_to_diff(of) || 0).to_r/86400
|
||||||
end
|
end
|
||||||
new0(jd_to_ajd(jd, fr, of), of, sg)
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self; alias_method :new, :civil end
|
class << self; alias_method :new, :civil end
|
||||||
|
@ -1479,31 +1505,44 @@ class DateTime < Date
|
||||||
# Calendar Reform for Italy and the Catholic countries.
|
# Calendar Reform for Italy and the Catholic countries.
|
||||||
# The time values default to 0.
|
# The time values default to 0.
|
||||||
def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY)
|
def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY)
|
||||||
unless (jd = valid_commercial?(y, w, d, sg)) and
|
unless (jd = valid_commercial?(y, w, d, sg)) &&
|
||||||
(fr = valid_time?(h, min, s))
|
(fr = valid_time?(h, min, s))
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
if String === of
|
if String === of
|
||||||
of = (zone_to_diff(of) || 0).to_r/86400
|
of = (zone_to_diff(of) || 0).to_r/86400
|
||||||
end
|
end
|
||||||
new0(jd_to_ajd(jd, fr, of), of, sg)
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new_with_hash(elem, sg) # :nodoc:
|
def self.weeknum(y=1582, w=41, d=5, f=0, h=0, min=0, s=0, of=0, sg=ITALY) # :nodoc:
|
||||||
elem = rewrite_hash(elem)
|
unless (jd = valid_weeknum?(y, w, d, f, sg)) &&
|
||||||
elem = complete_hash(elem)
|
(fr = valid_time?(h, min, s))
|
||||||
unless (jd = valid_date_with_hash?(elem, sg)) and
|
raise ArgumentError, 'invalid date'
|
||||||
(fr = valid_time_with_hash?(elem))
|
end
|
||||||
|
if String === of
|
||||||
|
of = (zone_to_diff(of) || 0).to_r/86400
|
||||||
|
end
|
||||||
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
|
end
|
||||||
|
|
||||||
|
private_class_method :weeknum
|
||||||
|
|
||||||
|
def self.new_by_frags(elem, sg) # :nodoc:
|
||||||
|
elem = rewrite_frags(elem)
|
||||||
|
elem = complete_frags(elem)
|
||||||
|
unless (jd = valid_date_frags?(elem, sg)) &&
|
||||||
|
(fr = valid_time_frags?(elem))
|
||||||
raise ArgumentError, 'invalid date'
|
raise ArgumentError, 'invalid date'
|
||||||
end
|
end
|
||||||
sf = (elem[:sec_fraction] || 0)
|
sf = (elem[:sec_fraction] || 0)
|
||||||
fr += sf/86400
|
fr += sf/86400
|
||||||
of = (elem[:offset] || 0)
|
of = (elem[:offset] || 0)
|
||||||
of = of.to_r/86400
|
of = of.to_r/86400
|
||||||
new0(jd_to_ajd(jd, fr, of), of, sg)
|
new!(jd_to_ajd(jd, fr, of), of, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method :new_with_hash
|
private_class_method :new_by_frags
|
||||||
|
|
||||||
# Create a new DateTime object by parsing from a String
|
# Create a new DateTime object by parsing from a String
|
||||||
# according to a specified format.
|
# according to a specified format.
|
||||||
|
@ -1521,13 +1560,13 @@ class DateTime < Date
|
||||||
# parsed.
|
# parsed.
|
||||||
def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY)
|
def self.strptime(str='-4712-01-01T00:00:00+00:00', fmt='%FT%T%z', sg=ITALY)
|
||||||
elem = _strptime(str, fmt)
|
elem = _strptime(str, fmt)
|
||||||
new_with_hash(elem, sg)
|
new_by_frags(elem, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new DateTime object by parsing from a String,
|
# Create a new DateTime object by parsing from a String,
|
||||||
# without specifying the format.
|
# without specifying the format.
|
||||||
#
|
#
|
||||||
# +str+ is a String holding a date-time representation.
|
# +str+ is a String holding a date-time representation.
|
||||||
# +comp+ specifies whether to interpret 2-digit years
|
# +comp+ specifies whether to interpret 2-digit years
|
||||||
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
|
# as 19XX (>= 69) or 20XX (< 69); the default is not to.
|
||||||
# The method will attempt to parse a date-time from the String
|
# The method will attempt to parse a date-time from the String
|
||||||
|
@ -1541,7 +1580,7 @@ class DateTime < Date
|
||||||
# +sg+ specifies the Day of Calendar Reform.
|
# +sg+ specifies the Day of Calendar Reform.
|
||||||
def self.parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY)
|
def self.parse(str='-4712-01-01T00:00:00+00:00', comp=false, sg=ITALY)
|
||||||
elem = _parse(str, comp)
|
elem = _parse(str, comp)
|
||||||
new_with_hash(elem, sg)
|
new_by_frags(elem, sg)
|
||||||
end
|
end
|
||||||
|
|
||||||
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
|
public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
|
||||||
|
@ -1554,7 +1593,7 @@ class Time
|
||||||
|
|
||||||
def to_date
|
def to_date
|
||||||
jd = Date.civil_to_jd(year, mon, mday, Date::ITALY)
|
jd = Date.civil_to_jd(year, mon, mday, Date::ITALY)
|
||||||
Date.new0(Date.jd_to_ajd(jd, 0, 0), 0, Date::ITALY)
|
Date.new!(Date.jd_to_ajd(jd, 0, 0), 0, Date::ITALY)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_datetime
|
def to_datetime
|
||||||
|
@ -1562,7 +1601,7 @@ class Time
|
||||||
fr = DateTime.time_to_day_fraction(hour, min, [sec, 59].min) +
|
fr = DateTime.time_to_day_fraction(hour, min, [sec, 59].min) +
|
||||||
usec.to_r/86400000000
|
usec.to_r/86400000000
|
||||||
of = utc_offset.to_r/86400
|
of = utc_offset.to_r/86400
|
||||||
DateTime.new0(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
|
DateTime.new!(DateTime.jd_to_ajd(jd, fr, of), of, DateTime::ITALY)
|
||||||
end
|
end
|
||||||
|
|
||||||
private :to_date, :to_datetime
|
private :to_date, :to_datetime
|
||||||
|
@ -1574,7 +1613,7 @@ class Date
|
||||||
=begin
|
=begin
|
||||||
def to_time() Time.local(year, mon, mday) end
|
def to_time() Time.local(year, mon, mday) end
|
||||||
def to_date() self end
|
def to_date() self end
|
||||||
def to_datetime() DateTime.new0(self.class.jd_to_ajd(jd, 0, 0), @of, @sg) end
|
def to_datetime() DateTime.new!(self.class.jd_to_ajd(jd, 0, 0), @of, @sg) end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
# Create a new Date object representing today.
|
# Create a new Date object representing today.
|
||||||
|
@ -1603,7 +1642,7 @@ class DateTime < Date
|
||||||
getlocal
|
getlocal
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_date() Date.new0(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
|
def to_date() Date.new!(self.class.jd_to_ajd(jd, 0, 0), 0, @sg) end
|
||||||
def to_datetime() self end
|
def to_datetime() self end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -1621,6 +1660,7 @@ class Date
|
||||||
%w(exist3? valid_date?),
|
%w(exist3? valid_date?),
|
||||||
%w(exist? valid_date?),
|
%w(exist? valid_date?),
|
||||||
%w(existw? valid_commercial?),
|
%w(existw? valid_commercial?),
|
||||||
|
%w(new0 new!),
|
||||||
%w(new1 jd),
|
%w(new1 jd),
|
||||||
%w(new2 ordinal),
|
%w(new2 ordinal),
|
||||||
%w(new3 new),
|
%w(new3 new),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# format.rb: Written by Tadayoshi Funaba 1999-2006
|
# format.rb: Written by Tadayoshi Funaba 1999-2006
|
||||||
# $Id: format.rb,v 2.28 2006-10-25 06:45:12+09 tadf Exp $
|
# $Id: format.rb,v 2.29 2006-12-30 21:43:41+09 tadf Exp $
|
||||||
|
|
||||||
require 'rational'
|
require 'rational'
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0] and $VERBOSE
|
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: getopts is deprecated after Ruby 1.8.1; use optparse instead" if caller[0] and $VERBOSE
|
||||||
|
|
||||||
$RCS_ID=%q$Header: /var/cvs/src/ruby/lib/getopts.rb,v 1.8.2.4 2006/08/04 22:00:21 drbrain Exp $
|
$RCS_ID=%q$Header$
|
||||||
|
|
||||||
# getopts is obsolete. Use GetoptLong.
|
# getopts is obsolete. Use GetoptLong.
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
|
|
||||||
= $RCSfile: https.rb,v $ -- SSL/TLS enhancement for Net::HTTP.
|
= $RCSfile$ -- SSL/TLS enhancement for Net::HTTP.
|
||||||
|
|
||||||
== Info
|
== Info
|
||||||
'OpenSSL for Ruby 2' project
|
'OpenSSL for Ruby 2' project
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: parsearg is deprecated after Ruby 1.8.1; use optparse instead"
|
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: parsearg is deprecated after Ruby 1.8.1; use optparse instead"
|
||||||
|
|
||||||
$RCS_ID=%q$Header: /var/cvs/src/ruby/lib/parsearg.rb,v 1.2.2.2 2006/08/04 22:00:21 drbrain Exp $
|
$RCS_ID=%q$Header$
|
||||||
|
|
||||||
require "getopts"
|
require "getopts"
|
||||||
|
|
||||||
|
|
|
@ -1,104 +1,16 @@
|
||||||
# We attempt to parse C extension files. Basically we look for
|
# Classes and modules built in to the interpreter. We need
|
||||||
# the standard patterns that you find in extensions: <tt>rb_define_class,
|
# these to define superclasses of user objects
|
||||||
# rb_define_method</tt> and so on. We also try to find the corresponding
|
|
||||||
# C source for the methods and extract comments, but if we fail
|
|
||||||
# we don't worry too much.
|
|
||||||
#
|
|
||||||
# The comments associated with a Ruby method are extracted from the C
|
|
||||||
# comment block associated with the routine that _implements_ that
|
|
||||||
# method, that is to say the method whose name is given in the
|
|
||||||
# <tt>rb_define_method</tt> call. For example, you might write:
|
|
||||||
#
|
|
||||||
# /*
|
|
||||||
# * Returns a new array that is a one-dimensional flattening of this
|
|
||||||
# * array (recursively). That is, for every element that is an array,
|
|
||||||
# * extract its elements into the new array.
|
|
||||||
# *
|
|
||||||
# * s = [ 1, 2, 3 ] #=> [1, 2, 3]
|
|
||||||
# * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
|
|
||||||
# * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
|
|
||||||
# * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
||||||
# */
|
|
||||||
# static VALUE
|
|
||||||
# rb_ary_flatten(ary)
|
|
||||||
# VALUE ary;
|
|
||||||
# {
|
|
||||||
# ary = rb_obj_dup(ary);
|
|
||||||
# rb_ary_flatten_bang(ary);
|
|
||||||
# return ary;
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# ...
|
|
||||||
#
|
|
||||||
# void
|
|
||||||
# Init_Array()
|
|
||||||
# {
|
|
||||||
# ...
|
|
||||||
# rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
|
|
||||||
#
|
|
||||||
# Here RDoc will determine from the rb_define_method line that there's a
|
|
||||||
# method called "flatten" in class Array, and will look for the implementation
|
|
||||||
# in the method rb_ary_flatten. It will then use the comment from that
|
|
||||||
# method in the HTML output. This method must be in the same source file
|
|
||||||
# as the rb_define_method.
|
|
||||||
#
|
|
||||||
# C classes can be diagramed (see /tc/dl/ruby/ruby/error.c), and RDoc
|
|
||||||
# integrates C and Ruby source into one tree
|
|
||||||
#
|
|
||||||
# The comment blocks may include special direcives:
|
|
||||||
#
|
|
||||||
# [Document-class: <i>name</i>]
|
|
||||||
# This comment block is documentation for the given class. Use this
|
|
||||||
# when the <tt>Init_xxx</tt> method is not named after the class.
|
|
||||||
#
|
|
||||||
# [Document-method: <i>name</i>]
|
|
||||||
# This comment documents the named method. Use when RDoc cannot outomatically
|
|
||||||
# find the method from it's declaration
|
|
||||||
#
|
|
||||||
# [call-seq: <i>text up to an empty line</i>]
|
|
||||||
# Because C source doesn't give descripive names to Ruby-level parameters,
|
|
||||||
# you need to document the calling sequence explicitly
|
|
||||||
#
|
|
||||||
# In additon, RDoc assumes by default that the C method implementing a
|
|
||||||
# Ruby function is in the same source file as the rb_define_method call.
|
|
||||||
# If this isn't the case, add the comment
|
|
||||||
#
|
|
||||||
# rb_define_method(....); // in: filename
|
|
||||||
#
|
|
||||||
# As an example, we might have an extension that defines multiple classes
|
|
||||||
# in its Init_xxx method. We could document them using
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# /*
|
|
||||||
# * Document-class: MyClass
|
|
||||||
# *
|
|
||||||
# * Encapsulate the writing and reading of the configuration
|
|
||||||
# * file. ...
|
|
||||||
# */
|
|
||||||
#
|
|
||||||
# /*
|
|
||||||
# * Document-method: read_value
|
|
||||||
# *
|
|
||||||
# * call-seq:
|
|
||||||
# * cfg.read_value(key) -> value
|
|
||||||
# * cfg.read_value(key} { |key| } -> value
|
|
||||||
# *
|
|
||||||
# * Return the value corresponding to +key+ from the configuration.
|
|
||||||
# * In the second form, if the key isn't found, invoke the
|
|
||||||
# * block and return its value.
|
|
||||||
# */
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
# Classes and modules built in to the interpreter. We need
|
|
||||||
# these to define superclasses of user objects
|
|
||||||
|
|
||||||
require "rdoc/code_objects"
|
require "rdoc/code_objects"
|
||||||
require "rdoc/parsers/parserfactory"
|
require "rdoc/parsers/parserfactory"
|
||||||
|
require "rdoc/options"
|
||||||
|
require "rdoc/rdoc"
|
||||||
|
|
||||||
module RDoc
|
module RDoc
|
||||||
|
|
||||||
|
##
|
||||||
|
# Ruby's built-in classes.
|
||||||
|
|
||||||
KNOWN_CLASSES = {
|
KNOWN_CLASSES = {
|
||||||
"rb_cObject" => "Object",
|
"rb_cObject" => "Object",
|
||||||
"rb_cArray" => "Array",
|
"rb_cArray" => "Array",
|
||||||
|
@ -158,13 +70,103 @@ module RDoc
|
||||||
"rb_mGC" => "GC",
|
"rb_mGC" => "GC",
|
||||||
"rb_mMath" => "Math",
|
"rb_mMath" => "Math",
|
||||||
"rb_mProcess" => "Process"
|
"rb_mProcess" => "Process"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# See rdoc/c_parse.rb
|
##
|
||||||
|
# We attempt to parse C extension files. Basically we look for
|
||||||
|
# the standard patterns that you find in extensions: <tt>rb_define_class,
|
||||||
|
# rb_define_method</tt> and so on. We also try to find the corresponding
|
||||||
|
# C source for the methods and extract comments, but if we fail
|
||||||
|
# we don't worry too much.
|
||||||
|
#
|
||||||
|
# The comments associated with a Ruby method are extracted from the C
|
||||||
|
# comment block associated with the routine that _implements_ that
|
||||||
|
# method, that is to say the method whose name is given in the
|
||||||
|
# <tt>rb_define_method</tt> call. For example, you might write:
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * Returns a new array that is a one-dimensional flattening of this
|
||||||
|
# * array (recursively). That is, for every element that is an array,
|
||||||
|
# * extract its elements into the new array.
|
||||||
|
# *
|
||||||
|
# * s = [ 1, 2, 3 ] #=> [1, 2, 3]
|
||||||
|
# * t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
|
||||||
|
# * a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
|
||||||
|
# * a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
|
# */
|
||||||
|
# static VALUE
|
||||||
|
# rb_ary_flatten(ary)
|
||||||
|
# VALUE ary;
|
||||||
|
# {
|
||||||
|
# ary = rb_obj_dup(ary);
|
||||||
|
# rb_ary_flatten_bang(ary);
|
||||||
|
# return ary;
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# ...
|
||||||
|
#
|
||||||
|
# void
|
||||||
|
# Init_Array()
|
||||||
|
# {
|
||||||
|
# ...
|
||||||
|
# rb_define_method(rb_cArray, "flatten", rb_ary_flatten, 0);
|
||||||
|
#
|
||||||
|
# Here RDoc will determine from the rb_define_method line that there's a
|
||||||
|
# method called "flatten" in class Array, and will look for the implementation
|
||||||
|
# in the method rb_ary_flatten. It will then use the comment from that
|
||||||
|
# method in the HTML output. This method must be in the same source file
|
||||||
|
# as the rb_define_method.
|
||||||
|
#
|
||||||
|
# C classes can be diagramed (see /tc/dl/ruby/ruby/error.c), and RDoc
|
||||||
|
# integrates C and Ruby source into one tree
|
||||||
|
#
|
||||||
|
# The comment blocks may include special direcives:
|
||||||
|
#
|
||||||
|
# [Document-class: <i>name</i>]
|
||||||
|
# This comment block is documentation for the given class. Use this
|
||||||
|
# when the <tt>Init_xxx</tt> method is not named after the class.
|
||||||
|
#
|
||||||
|
# [Document-method: <i>name</i>]
|
||||||
|
# This comment documents the named method. Use when RDoc cannot
|
||||||
|
# automatically find the method from it's declaration
|
||||||
|
#
|
||||||
|
# [call-seq: <i>text up to an empty line</i>]
|
||||||
|
# Because C source doesn't give descripive names to Ruby-level parameters,
|
||||||
|
# you need to document the calling sequence explicitly
|
||||||
|
#
|
||||||
|
# In additon, RDoc assumes by default that the C method implementing a
|
||||||
|
# Ruby function is in the same source file as the rb_define_method call.
|
||||||
|
# If this isn't the case, add the comment
|
||||||
|
#
|
||||||
|
# rb_define_method(....); // in: filename
|
||||||
|
#
|
||||||
|
# As an example, we might have an extension that defines multiple classes
|
||||||
|
# in its Init_xxx method. We could document them using
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * Document-class: MyClass
|
||||||
|
# *
|
||||||
|
# * Encapsulate the writing and reading of the configuration
|
||||||
|
# * file. ...
|
||||||
|
# */
|
||||||
|
#
|
||||||
|
# /*
|
||||||
|
# * Document-method: read_value
|
||||||
|
# *
|
||||||
|
# * call-seq:
|
||||||
|
# * cfg.read_value(key) -> value
|
||||||
|
# * cfg.read_value(key} { |key| } -> value
|
||||||
|
# *
|
||||||
|
# * Return the value corresponding to +key+ from the configuration.
|
||||||
|
# * In the second form, if the key isn't found, invoke the
|
||||||
|
# * block and return its value.
|
||||||
|
# */
|
||||||
|
#
|
||||||
|
|
||||||
class C_Parser
|
class C_Parser
|
||||||
|
|
||||||
|
attr_accessor :progress
|
||||||
|
|
||||||
extend ParserFactory
|
extend ParserFactory
|
||||||
parse_files_matching(/\.(c|cc|cpp|CC)$/)
|
parse_files_matching(/\.(c|cc|cpp|CC)$/)
|
||||||
|
@ -217,8 +219,9 @@ module RDoc
|
||||||
comment.sub!(/\/?\*--.*/m, '')
|
comment.sub!(/\/?\*--.*/m, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove lines that are commented out that might otherwise get
|
##
|
||||||
# picked up when scanning for classes and methods
|
# removes lines that are commented out that might otherwise get picked up
|
||||||
|
# when scanning for classes and methods
|
||||||
|
|
||||||
def remove_commented_out_lines
|
def remove_commented_out_lines
|
||||||
@body.gsub!(%r{//.*rb_define_}, '//')
|
@body.gsub!(%r{//.*rb_define_}, '//')
|
||||||
|
@ -260,7 +263,6 @@ module RDoc
|
||||||
@classes[var_name] = cm
|
@classes[var_name] = cm
|
||||||
@known_classes[var_name] = cm.full_name
|
@known_classes[var_name] = cm.full_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
|
@ -425,7 +427,16 @@ module RDoc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
############################################################
|
##
|
||||||
|
# Adds constant comments. By providing some_value: at the start ofthe
|
||||||
|
# comment you can override the C value of the comment to give a friendly
|
||||||
|
# definition.
|
||||||
|
#
|
||||||
|
# /* 300: The perfect score in bowling */
|
||||||
|
# rb_define_const(cFoo, "PERFECT", INT2FIX(300);
|
||||||
|
#
|
||||||
|
# Will override +INT2FIX(300)+ with the value +300+ in the output RDoc.
|
||||||
|
# Values may include quotes and escaped colons (\:).
|
||||||
|
|
||||||
def handle_constants(type, var_name, const_name, definition)
|
def handle_constants(type, var_name, const_name, definition)
|
||||||
#@stats.num_constants += 1
|
#@stats.num_constants += 1
|
||||||
|
@ -442,14 +453,39 @@ module RDoc
|
||||||
|
|
||||||
comment = find_const_comment(type, const_name)
|
comment = find_const_comment(type, const_name)
|
||||||
|
|
||||||
con = Constant.new(const_name, definition, mangle_comment(comment))
|
# In the case of rb_define_const, the definition and comment are in
|
||||||
|
# "/* definition: comment */" form. The literal ':' and '\' characters
|
||||||
|
# can be escaped with a backslash.
|
||||||
|
if type.downcase == 'const' then
|
||||||
|
elements = mangle_comment(comment).split(':')
|
||||||
|
if elements.nil? or elements.empty? then
|
||||||
|
con = Constant.new(const_name, definition, mangle_comment(comment))
|
||||||
|
else
|
||||||
|
new_definition = elements[0..-2].join(':')
|
||||||
|
if new_definition.empty? then # Default to literal C definition
|
||||||
|
new_definition = definition
|
||||||
|
else
|
||||||
|
new_definition.gsub!("\:", ":")
|
||||||
|
new_definition.gsub!("\\", '\\')
|
||||||
|
end
|
||||||
|
new_definition.sub!(/\A(\s+)/, '')
|
||||||
|
new_comment = $1.nil? ? elements.last : "#{$1}#{elements.last.lstrip}"
|
||||||
|
con = Constant.new(const_name, new_definition,
|
||||||
|
mangle_comment(new_comment))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
con = Constant.new(const_name, definition, mangle_comment(comment))
|
||||||
|
end
|
||||||
|
|
||||||
class_obj.add_constant(con)
|
class_obj.add_constant(con)
|
||||||
end
|
end
|
||||||
|
|
||||||
###########################################################
|
##
|
||||||
|
# Finds a comment matching +type+ and +const_name+ either above the
|
||||||
|
# comment or in the matching Document- section.
|
||||||
|
|
||||||
def find_const_comment(type, const_name)
|
def find_const_comment(type, const_name)
|
||||||
if @body =~ %r{((?>/\*.*?\*/\s+))
|
if @body =~ %r{((?>^\s*/\*.*?\*/\s+))
|
||||||
rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
|
rb_define_#{type}\((?:\s*(\w+),)?\s*"#{const_name}"\s*,.*?\)\s*;}xmi
|
||||||
$1
|
$1
|
||||||
elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m
|
elsif @body =~ %r{Document-(?:const|global|variable):\s#{const_name}\s*?\n((?>.*?\*/))}m
|
||||||
|
@ -610,13 +646,15 @@ module RDoc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
##################################################
|
##
|
||||||
#
|
# If the comment block contains a section that looks like:
|
||||||
# If the comment block contains a section that looks like
|
#
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# Array.new
|
# Array.new
|
||||||
# Array.new(10)
|
# Array.new(10)
|
||||||
# use it for the parameters
|
#
|
||||||
|
# use it for the parameters.
|
||||||
|
|
||||||
def find_modifiers(comment, meth_obj)
|
def find_modifiers(comment, meth_obj)
|
||||||
if comment.sub!(/:nodoc:\s*^\s*\*?\s*$/m, '') or
|
if comment.sub!(/:nodoc:\s*^\s*\*?\s*$/m, '') or
|
||||||
comment.sub!(/\A\/\*\s*:nodoc:\s*\*\/\Z/, '')
|
comment.sub!(/\A\/\*\s*:nodoc:\s*\*\/\Z/, '')
|
||||||
|
@ -639,10 +677,11 @@ module RDoc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
############################################################
|
##
|
||||||
|
# Look for includes of the form:
|
||||||
# Look for includes of the form
|
#
|
||||||
# rb_include_module(rb_cArray, rb_mEnumerable);
|
# rb_include_module(rb_cArray, rb_mEnumerable);
|
||||||
|
|
||||||
def do_includes
|
def do_includes
|
||||||
@body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
|
@body.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
|
||||||
if cls = @classes[c]
|
if cls = @classes[c]
|
||||||
|
@ -652,8 +691,7 @@ module RDoc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
############################################################
|
##
|
||||||
|
|
||||||
# Remove the /*'s and leading asterisks from C comments
|
# Remove the /*'s and leading asterisks from C comments
|
||||||
|
|
||||||
def mangle_comment(comment)
|
def mangle_comment(comment)
|
||||||
|
@ -686,7 +724,8 @@ module RDoc
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove #ifdefs that would otherwise confuse us
|
##
|
||||||
|
# Removes #ifdefs that would otherwise confuse us
|
||||||
|
|
||||||
def handle_ifdefs_in(body)
|
def handle_ifdefs_in(body)
|
||||||
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 }
|
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m) { $1 }
|
||||||
|
@ -695,3 +734,4 @@ module RDoc
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ unless defined? Thread
|
||||||
end
|
end
|
||||||
|
|
||||||
module Sync_m
|
module Sync_m
|
||||||
RCS_ID='-$Header: /var/cvs/src/ruby/lib/sync.rb,v 1.4 2001/06/06 14:19:33 keiju Exp $-'
|
RCS_ID='-$Header$-'
|
||||||
|
|
||||||
# lock mode
|
# lock mode
|
||||||
UN = :UN
|
UN = :UN
|
||||||
|
|
|
@ -34,11 +34,11 @@
|
||||||
;;;
|
;;;
|
||||||
;;; HISTORY
|
;;; HISTORY
|
||||||
;;; senda - 8 Apr 1998: Created.
|
;;; senda - 8 Apr 1998: Created.
|
||||||
;;; $Log: inf-ruby.el,v $
|
;;; $Log$
|
||||||
;;; Revision 1.6.2.1 2004/07/27 07:51:28 matz
|
;;; Revision 1.6.2.1 2004/07/27 07:51:28 matz
|
||||||
;;; * object.c (Init_Object): "===" calls rb_obj_equal() directly.
|
;;; * object.c (Init_Object): "===" calls rb_obj_equal() directly.
|
||||||
;;; [ruby-list:39937]
|
;;; [ruby-list:39937]
|
||||||
;;;
|
;;;
|
||||||
;;; Revision 1.6 2002/09/07 14:35:46 nobu
|
;;; Revision 1.6 2002/09/07 14:35:46 nobu
|
||||||
;;; * misc/inf-ruby.el (inferior-ruby-error-regexp-alist): regexp
|
;;; * misc/inf-ruby.el (inferior-ruby-error-regexp-alist): regexp
|
||||||
;;; alist for error message from ruby.
|
;;; alist for error message from ruby.
|
||||||
|
|
5
string.c
5
string.c
|
@ -1863,7 +1863,10 @@ rb_str_insert(str, idx, str2)
|
||||||
* str.slice!(other_str) => new_str or nil
|
* str.slice!(other_str) => new_str or nil
|
||||||
*
|
*
|
||||||
* Deletes the specified portion from <i>str</i>, and returns the portion
|
* Deletes the specified portion from <i>str</i>, and returns the portion
|
||||||
* deleted.
|
* deleted. The forms that take a <code>Fixnum</code> will raise an
|
||||||
|
* <code>IndexError</code> if the value is out of range; the <code>Range</code>
|
||||||
|
* form will raise a <code>RangeError</code>, and the <code>Regexp</code> and
|
||||||
|
* <code>String</code> forms will silently ignore the assignment.
|
||||||
*
|
*
|
||||||
* string = "this is a string"
|
* string = "this is a string"
|
||||||
* string.slice!(2) #=> 105
|
* string.slice!(2) #=> 105
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#define RUBY_VERSION "1.8.5"
|
#define RUBY_VERSION "1.8.5"
|
||||||
#define RUBY_RELEASE_DATE "2006-12-15"
|
#define RUBY_RELEASE_DATE "2006-12-31"
|
||||||
#define RUBY_VERSION_CODE 185
|
#define RUBY_VERSION_CODE 185
|
||||||
#define RUBY_RELEASE_CODE 20061215
|
#define RUBY_RELEASE_CODE 20061231
|
||||||
#define RUBY_PATCHLEVEL 5000
|
#define RUBY_PATCHLEVEL 5000
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
#define RUBY_VERSION_TEENY 5
|
#define RUBY_VERSION_TEENY 5
|
||||||
#define RUBY_RELEASE_YEAR 2006
|
#define RUBY_RELEASE_YEAR 2006
|
||||||
#define RUBY_RELEASE_MONTH 12
|
#define RUBY_RELEASE_MONTH 12
|
||||||
#define RUBY_RELEASE_DAY 15
|
#define RUBY_RELEASE_DAY 31
|
||||||
|
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
RUBY_EXTERN const char ruby_release_date[];
|
RUBY_EXTERN const char ruby_release_date[];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue