mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/date] Promote simple date to complex date to load fractional date (Fixes #20)
https://github.com/ruby/date/commit/e022e8b3ce
This commit is contained in:
parent
ad156f7e2c
commit
97e8b7d098
1 changed files with 7 additions and 4 deletions
|
@ -7202,11 +7202,14 @@ d_lite_marshal_load(VALUE self, VALUE a)
|
||||||
|
|
||||||
if (simple_dat_p(dat)) {
|
if (simple_dat_p(dat)) {
|
||||||
if (df || !f_zero_p(sf) || of) {
|
if (df || !f_zero_p(sf) || of) {
|
||||||
rb_raise(rb_eArgError,
|
/* loading a fractional date; promote to complex */
|
||||||
"cannot load complex into simple");
|
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);
|
set_to_simple(self, &dat->s, nth, jd, sg, 0, 0, 0, HAVE_JD);
|
||||||
} else {
|
} else {
|
||||||
|
complex_data:
|
||||||
set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
|
set_to_complex(self, &dat->c, nth, jd, df, sf, of, sg,
|
||||||
0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0,
|
||||||
HAVE_JD | HAVE_DF);
|
HAVE_JD | HAVE_DF);
|
||||||
|
@ -9318,7 +9321,7 @@ Init_date_core(void)
|
||||||
*/
|
*/
|
||||||
rb_define_const(cDate, "GREGORIAN", DBL2NUM(GREGORIAN));
|
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
|
#ifndef NDEBUG
|
||||||
rb_define_private_method(CLASS_OF(cDate), "_valid_jd?",
|
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, "jd", date_s_jd, -1);
|
||||||
rb_define_singleton_method(cDate, "ordinal", date_s_ordinal, -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, "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);
|
rb_define_singleton_method(cDate, "commercial", date_s_commercial, -1);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#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_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);
|
rb_define_method(cDate, "initialize_copy", d_lite_initialize_copy, 1);
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
Loading…
Add table
Reference in a new issue