From 97e8b7d0983bb22ecd707449819933fb543143d4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 12 Jun 2020 15:32:09 +0900 Subject: [ruby/date] Promote simple date to complex date to load fractional date (Fixes #20) https://github.com/ruby/date/commit/e022e8b3ce --- ext/date/date_core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 8c5d280d1d..666f278a9b 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -7202,11 +7202,14 @@ d_lite_marshal_load(VALUE self, VALUE a) if (simple_dat_p(dat)) { if (df || !f_zero_p(sf) || of) { - rb_raise(rb_eArgError, - "cannot load complex into simple"); + /* loading a fractional date; promote to complex */ + dat = ruby_xrealloc(dat, sizeof(struct ComplexDateData)); + RTYPEDDATA(self)->data = dat; + goto complex_data; } set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD); } else { + complex_data: set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg, 0, 0, 0, 0, 0, 0, HAVE_JD | HAVE_DF); @@ -9318,7 +9321,7 @@ Init_date_core(void) */ rb_define_const(cDate, "GREGORIAN", DBL2NUM(GREGORIAN)); - rb_define_alloc_func(cDate, d_lite_s_alloc_complex); + rb_define_alloc_func(cDate, d_lite_s_alloc_simple); #ifndef NDEBUG rb_define_private_method(CLASS_OF(cDate), "_valid_jd?", @@ -9368,7 +9371,6 @@ Init_date_core(void) rb_define_singleton_method(cDate, "jd", date_s_jd, -1); rb_define_singleton_method(cDate, "ordinal", date_s_ordinal, -1); rb_define_singleton_method(cDate, "civil", date_s_civil, -1); - rb_define_singleton_method(cDate, "new", date_s_civil, -1); rb_define_singleton_method(cDate, "commercial", date_s_commercial, -1); #ifndef NDEBUG @@ -9396,6 +9398,7 @@ Init_date_core(void) rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1); rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1); + rb_define_method(cDate, "initialize", date_initialize, -1); rb_define_method(cDate, "initialize_copy", d_lite_initialize_copy, 1); #ifndef NDEBUG -- cgit v1.2.3