Make Time#to_date compliant with MRI 1.9-2 #740

Merged
merged 1 commit into from May 17, 2013

Projects

None yet

2 participants

@teleological

Time#to_date should use the proleptic Gregorian calendar to construct a Date,
but should return a Date object with the default calendar reform day. This is
unlike the behavior of Ruby 1.8 Time#to_date, which was private and seems to
have served as the basis for the current implementation. A specification
for this method has been added to rubyspec.

Riley Lynch Make Time#to_date compliant with MRI 1.9-2
Time#to_date should use the proleptic Gregorian calendar to construct a Date,
but should return a Date object with the default calendar reform day. This is
unlike the behavior of Ruby 1.8 Time#to_date, which was private and seems to
have served as the basis for the current implementation. A specification
for this method has been added to rubyspec.
feb5b7f
@teleological

This patch was accepted by rubinius (along with a few other rubinius-specific fixes).
rubinius/rubinius@57068d0

@headius
Member
headius commented May 17, 2013

So...was this a bug in MRI's date.rb? We largely ship the same stdlib code and don't like to diverge without good reason.

@headius
Member
headius commented May 17, 2013

I do see that MRI's native date ext does the GREGORIAN version too:

/*
 * call-seq:
 *    t.to_date  ->  date
 *
 * Returns a Date object which denotes self.
 */
static VALUE
time_to_date(VALUE self)
{
    VALUE y, nth, ret;
    int ry, m, d;

    y = f_year(self);
    m = FIX2INT(f_mon(self));
    d = FIX2INT(f_mday(self));

    decode_year(y, -1, &nth, &ry);

    ret = d_simple_new_internal(cDate,
                nth, 0,
                GREGORIAN,
                ry, m, d,
                HAVE_CIVIL);
    {
    get_d1(ret);
    set_sg(dat, DEFAULT_SG);
    }
    return ret;
}
@headius headius merged commit 60b50e3 into jruby:master May 17, 2013

1 check failed

default The Travis CI build failed
Details
@headius
Member
headius commented May 17, 2013

I went ahead and merged it. I think I understand that this was incorrect behavior inherited from 1.8, fixed in 1.9.2 and then ported into C for 1.9.3. Perhaps we should be incorporating 1.9.2's date.rb, if we're not already?

@headius headius added a commit to jruby/ruby that referenced this pull request May 17, 2013
@headius headius Fix to_date as in jruby/jruby#740. 2876188
@teleological

The 1.9 date library is unusual in so far as it is not loaded with the core, but it has a native implementation. Is anything like that done for JRuby? Are there any core classes which are extended by native standard libraries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment