diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-06-12 15:32:09 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-06-20 18:35:03 +0900 |
commit | 97e8b7d0983bb22ecd707449819933fb543143d4 (patch) | |
tree | ca6dbf04f293f2b994a4d97c2363680ac7676406 /ext/date/date_core.c | |
parent | ad156f7e2caa28f429a9f05f3b9b184118b85432 (diff) |
[ruby/date] Promote simple date to complex date to load fractional date (Fixes #20)
https://github.com/ruby/date/commit/e022e8b3ce
Diffstat (limited to 'ext/date/date_core.c')
-rw-r--r-- | ext/date/date_core.c | 11 |
1 files 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 |