8000 Promote simple date to complex date to load fractional date (Fixes #20) · ruby/date@e022e8b · GitHub
[go: up one dir, main page]

Skip to content

Commit e022e8b

Browse files
committed
Promote simple date to complex date to load fractional date (Fixes #20)
1 parent 6bb8d8f commit e022e8b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ext/date/date_core.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7202,11 +7202,14 @@ d_lite_marshal_load(VALUE self, VALUE a)
72027202

72037203
if (simple_dat_p(dat)) {
72047204
if (df || !f_zero_p(sf) || of) {
7205-
rb_raise(rb_eArgError,
7206-
"cannot load complex into simple");
7205+
/* loading a fractional date; promote to complex */
7206+
dat = ruby_xrealloc(dat, sizeof(struct ComplexDateData));
7207+
RTYPEDDATA(self)->data = dat;
7208+
goto complex_data;
72077209
}
72087210
set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
72097211
} else {
7212+
complex_data:
72107213
set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
72117214
0, 0, 0, 0, 0, 0,
72127215
HAVE_JD | HAVE_DF);
@@ -9318,7 +9321,7 @@ Init_date_core(void)
93189321
*/
93199322
rb_define_const(cDate, "GREGORIAN", DBL2NUM(GREGORIAN));
93209323

9321-
rb_define_alloc_func(cDate, d_lite_s_alloc_complex);
9324+
rb_define_alloc_func(cDate, d_lite_s_alloc_simple);
93229325

93239326
#ifndef NDEBUG
93249327
rb_define_private_method(CLASS_OF(cDate), "_valid_jd?",
@@ -9368,7 +9371,6 @@ Init_date_core(void)
93689371
rb_define_singleton_method(cDate, "jd", date_s_jd, -1);
93699372
rb_define_singleton_method(cDate, "ordinal", date_s_ordinal, -1);
93709373
rb_define_singleton_method(cDate, "civil", date_s_civil, -1);
9371-
rb_define_singleton_method(cDate, "new", date_s_civil, -1);
93729374
rb_define_singleton_method(cDate, "commercial", date_s_commercial, -1);
93739375

93749376
#ifndef NDEBUG
@@ -9396,6 +9398,7 @@ Init_date_core(void)
93969398
rb_define_singleton_method(cDate, "_jisx0301", date_s__jisx0301, 1);
93979399
rb_define_singleton_method(cDate, "jisx0301", date_s_jisx0301, -1);
93989400

9401+
rb_define_method(cDate, "initialize", date_initialize, -1);
93999402
rb_define_method(cDate, "initialize_copy", d_lite_initialize_copy, 1);
94009403

94019404
#ifndef NDEBUG

0 commit comments

Comments
 (0)
0