Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from May 17, 2013

Conversation

Projects
None yet
2 participants
@teleological
Copy link

commented May 16, 2013

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.
@teleological

This comment has been minimized.

Copy link
Author

commented May 17, 2013

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

@headius

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Member

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

Merge pull request #740 from teleological/time_to_date_19
Make Time#to_date compliant with MRI 1.9-2

@headius headius merged commit 60b50e3 into jruby:master May 17, 2013

1 check failed

default The Travis CI build failed
Details
@headius

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented May 17, 2013

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
You can’t perform that action at this time.