Skip to content

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

Merged
headius merged 1 commit intojruby:masterfrom
teleological:time_to_date_19
May 17, 2013
Merged

Make Time#to_date compliant with MRI 1.9-2#740
headius merged 1 commit intojruby:masterfrom
teleological:time_to_date_19

Conversation

@teleological
Copy link

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.

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.
@teleological
Copy link
Author

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

@headius
Copy link
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
Copy link
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 added a commit that referenced this pull request May 17, 2013
Make Time#to_date compliant with MRI 1.9-2
@headius headius merged commit 60b50e3 into jruby:master May 17, 2013
@headius
Copy link
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 added a commit to jruby/ruby that referenced this pull request May 17, 2013
@teleological
Copy link
Author

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants