/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.35 from the
 * contents of Simple.xs. Do not edit this file, edit Simple.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "Simple.xs"
#define PERL_POLLUTE

#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>


static UV dim[14]
	= { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28 };
static IV tweak[12]
	= { 1, 2, 4, 5, 7, 8, 9, 11, 12, 14, 15, 16 };
static IV cum_days[12]
	= { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333 };

static bool
is_leap_year (IV y)
{
	return (y % 4 == 0) && ((y % 100 != 0) || (y % 400 == 0));
}

static IV
days_in_month (IV month, IV year)
{
	IV ret = dim [ month - 1 ];
	if (ret == 0)
		ret = is_leap_year (year) ? 29 : 28;
	return ret;
}

/* Compute the number of days since 1970.  */
static bool
ymd_to_days (IV y, IV m, IV d, IV* days)
{
	IV x;
	IV nonleap_days;
	IV leap_days_4;
	IV leap_holes_100;
	IV leap_days_400;

	if (m < 1 || m > 12 || d < 1 || (d > 28 && d > days_in_month (m, y)))
		return FALSE;

	x = (m <= 2 ? y - 1 : y);
	nonleap_days = d + cum_days [m - 1] + 365 * (y - 1970);

	leap_days_4 = (x - 1968) >> 2;
	if (x >= 1900)
		leap_holes_100 = (x - 1900) / 100;
	else
		leap_holes_100 = - (1999 - x) / 100;
	if (x >= 1600)
		leap_days_400 = (x - 1600) / 400;
	else
		leap_days_400 = - (1999 - x) / 400;

	*days = nonleap_days + leap_days_4 - leap_holes_100 + leap_days_400;
	return TRUE;
}

/* Compute year, month, and day given days_since_1970.  */
static void
days_to_ymd (IV days, IV ymd[3])
{
	IV year;
	IV month, day, quot;

	/* Shift frame of reference from 1 Jan 1970 to (the imaginary)
	   1 Mar 0AD.  */
	days += 719468;

	/* Do the math.  */

	quot = days / 146097;
	days -= 146097 * quot;
	year = 400 * quot;

	if (days == 146096)
	{
		/* Handle 29 Feb 2000, 2400, ...  */
		year += 400;
		month = 2;
		day = 29;
	}
	else
	{
		quot = days / 36524;
		days -= 36524 * quot;
		year += 100 * quot;

		quot = days / 1461;
		days -= 1461 * quot;
		year += 4 * quot;

		if (days == 1460)
		{
			year += 4;
			month = 2;
			day = 29;
		}
		else
		{
			quot = days / 365;
			days -= 365 * quot;
			year += quot;

			quot = days / 32;
			days -= 32 * quot;
			month = quot;

			day = days + tweak [month];
			days = dim [month + 2];

			if (day > days)
			{
				day -= days;
				month += 1;
			}
			if (month > 9)
			{
				month -= 9;
				year += 1;
			}
			else
				month += 3;
		}
	}
	ymd[0] = year;
	ymd[1] = month;
	ymd[2] = day;
}

static bool
d8_to_days (SV* d8, IV* days)
{
	char buf[5];
	STRLEN len;
	char* p;

	p = SvPV(d8, len);
	if (len == 8)
	{
		while (len > 0)
		{
			if (!isDIGIT(p[len - 1]))
				break;
			len--;
		}
		if (len != 0)
			return FALSE;
	}
	else
		return FALSE;

	return ymd_to_days(10*(10*(10*(p[0]-'0')+p[1]-'0')+p[2]-'0')+p[3]-'0',
			   10*(p[4]-'0')+p[5]-'0', 10*(p[6]-'0')+p[7]-'0',
			   days);
}

static SV*
days_to_date (IV days, SV* pkg)
{
        char* pack=0;
        if (SvROK (pkg)) {
            HV* stash;
            stash=SvSTASH(SvRV(pkg));
       	    return sv_bless( newRV_noinc (newSViv (days)), stash );
        } else if (SvTRUE(pkg)) {
            pack=SvPV_nolen(pkg);
        }
        return sv_bless( newRV_noinc (newSViv (days)),
			 gv_stashpv (pack == 0 ? "Date::Simple" : pack, 1));
}

static int
is_object (SV* sv)
{
	return (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVMG);
}

static SV*
new_for_cmp (SV* left, SV* right, int croak_on_fail)
{
	dSP;
	SV* ret;

	/* Comparing date with non-date.
	   Try to convert the right side to a date.  */
	EXTEND (sp, 2);
	PUSHMARK(sp);
	PUSHs (left);
	PUSHs (right);
	PUTBACK;
	perl_call_method (croak_on_fail ? "new" : "_new", G_SCALAR);
	SPAGAIN;
	ret = POPs;
	if (croak_on_fail && ! is_object (ret))
	{
		PUSHMARK(sp);
		PUSHs (left);
		PUSHs (right);
		PUTBACK;
		perl_call_pv ("Date::Simple::_inval", G_VOID);
		SPAGAIN;
	}
	return ret;
}

#line 218 "Simple.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
	    Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
        else
	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#define croak_xs_usage        S_croak_xs_usage

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#if PERL_VERSION_LE(5, 21, 5)
#  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
#else
#  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
#endif

#line 362 "Simple.c"

XS_EUPXS(XS_Date__Simple__ymd); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__ymd)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "obj_or_class, y, m, d");
    {
	SV*	obj_or_class = ST(0)
;
	IV	y = (IV)SvIV(ST(1))
;
	IV	m = (IV)SvIV(ST(2))
;
	IV	d = (IV)SvIV(ST(3))
;
	SV *	RETVAL;
#line 217 "Simple.xs"
	{
		IV days;
		if (ymd_to_days (y, m, d, &days))
			RETVAL = days_to_date (days, obj_or_class);
		else
			XSRETURN_UNDEF;
	}
#line 388 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple__d8); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__d8)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "obj_or_class, d8");
    {
	SV*	obj_or_class = ST(0)
;
	SV*	d8 = ST(1)
;
	SV *	RETVAL;
#line 232 "Simple.xs"
	{
		IV days;
		if (d8_to_days (d8, &days))
			RETVAL = days_to_date (days, obj_or_class);
		else
			XSRETURN_UNDEF;
	}
#line 416 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_leap_year); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_leap_year)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "y");
    {
	IV	y = (IV)SvIV(ST(0))
;
	bool	RETVAL;
#line 246 "Simple.xs"
	{
		RETVAL = is_leap_year (y);
	}
#line 438 "Simple.c"
	ST(0) = boolSV(RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_days_in_month); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_days_in_month)
{
    dVAR; dXSARGS;
    if (items != 2)
       croak_xs_usage(cv,  "y, m");
    {
	IV	y = (IV)SvIV(ST(0))
;
	IV	m = (IV)SvIV(ST(1))
;
	IV	RETVAL;
	dXSTARG;
#line 257 "Simple.xs"
	{
		if (m < 1 || m > 12)
			croak ("days_in_month: month out of range (%d)",
			       (int) m);
		RETVAL = days_in_month (m, y);
	}
#line 465 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_validate); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_validate)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "ysv, m, d");
    {
	SV*	ysv = ST(0)
;
	IV	m = (IV)SvIV(ST(1))
;
	IV	d = (IV)SvIV(ST(2))
;
	IV	RETVAL;
	dXSTARG;
#line 272 "Simple.xs"
	{
		IV y;
		y = SvIV (ysv);
		if ((IV) SvNV (ysv) != y)
			RETVAL = 0;
		else if (m < 1 || m > 12)
			RETVAL = 0;
		else if (d < 1 || d > days_in_month (m, y))
			RETVAL = 0;
		else
			RETVAL = 1;
	}
#line 500 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_ymd_to_days); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_ymd_to_days)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "y, m, d");
    {
	IV	y = (IV)SvIV(ST(0))
;
	IV	m = (IV)SvIV(ST(1))
;
	IV	d = (IV)SvIV(ST(2))
;
#line 293 "Simple.xs"
	{
		IV days;
		if (! ymd_to_days (y, m, d, &days))
			XSRETURN_UNDEF;
		else
			XSRETURN_IV (days);
	}
#line 528 "Simple.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Date__Simple_days_since_1970); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_days_since_1970)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    {
	SV*	date = ST(0)
;
	SV *	RETVAL;
#line 305 "Simple.xs"
	{
		if (SvROK(date))
			RETVAL = SvREFCNT_inc (SvRV(date));
		else
			XSRETURN_UNDEF;
	}
#line 551 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_days_to_ymd); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_days_to_ymd)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "days");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	IV	days = (IV)SvIV(ST(0))
;
#line 318 "Simple.xs"
	{
		IV ymd[3];
		days_to_ymd (days, ymd);
		EXTEND (sp, 3);
		PUSHs (sv_2mortal (newSViv (ymd[0])));
		PUSHs (sv_2mortal (newSViv (ymd[1])));
		PUSHs (sv_2mortal (newSViv (ymd[2])));
	}
#line 579 "Simple.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Date__Simple_year); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_year)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    {
	SV*	date = ST(0)
;
	IV	RETVAL;
	dXSTARG;
#line 331 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_UNDEF;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		RETVAL = ymd[0];
	}
#line 606 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_month); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_month)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    {
	SV*	date = ST(0)
;
	IV	RETVAL;
	dXSTARG;
#line 346 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_UNDEF;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		RETVAL = ymd[1];
	}
#line 633 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_day); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_day)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    {
	SV*	date = ST(0)
;
	IV	RETVAL;
	dXSTARG;
#line 361 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_UNDEF;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		RETVAL = ymd[2];
	}
#line 660 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_as_iso); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_as_iso)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "date, ...");
    {
	SV*	date = ST(0)
;
	SV *	RETVAL;
#line 378 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_UNDEF;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		RETVAL = newSVpvf ("%04d-%02d-%02d", (int) ymd[0] % 10000,
				   (int) ymd[1], (int) ymd[2]);
	}
#line 687 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_as_d8); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_as_d8)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "date, ...");
    {
	SV*	date = ST(0)
;
	SV *	RETVAL;
#line 395 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_UNDEF;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		RETVAL = newSVpvf ("%04d%02d%02d", (int)ymd[0] % 10000,
				   (int) ymd[1], (int) ymd[2]);
	}
#line 715 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_as_ymd); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_as_ymd)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	SV*	date = ST(0)
;
#line 411 "Simple.xs"
	{
		IV ymd[3];
		if (! SvROK (date))
			XSRETURN_EMPTY;

		days_to_ymd (SvIV (SvRV (date)), ymd);
		EXTEND (sp, 3);
		PUSHs (sv_2mortal (newSViv (ymd[0])));
		PUSHs (sv_2mortal (newSViv (ymd[1])));
		PUSHs (sv_2mortal (newSViv (ymd[2])));
	}
#line 746 "Simple.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Date__Simple__add); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__add)
{
    dVAR; dXSARGS;
    if (items < 2)
       croak_xs_usage(cv,  "date, diff, ...");
    {
	SV*	date = ST(0)
;
	IV	diff = (IV)SvIV(ST(1))
;
	SV *	RETVAL;
#line 428 "Simple.xs"
	{
	        dSP;

	        SV* new_date;
		SV* format;

		IV days;

		if (! is_object (date))
			XSRETURN_UNDEF;

		days = SvIV (SvRV (date)) + diff;

		new_date = sv_bless(newRV_noinc(newSViv(days)),
				    SvSTASH(SvRV(date)));

		PUSHMARK(SP);
		XPUSHs(date);
		PUTBACK;

		call_method("default_format", G_SCALAR);

		SPAGAIN;

		format = POPs;

		PUSHMARK(SP);
		XPUSHs(new_date);
		XPUSHs(format);
		PUTBACK;

		call_method("default_format", G_DISCARD);

		RETVAL = new_date;

	}
#line 802 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple__subtract); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__subtract)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "left, right, reverse");
    {
	SV*	left = ST(0)
;
	SV*	right = ST(1)
;
	SV*	reverse = ST(2)
;
	SV *	RETVAL;
#line 473 "Simple.xs"
	{
		if (! is_object (left))
			XSRETURN_UNDEF;

		if (SvTRUE (reverse))
			croak ("Can't subtract a date from a non-date");

		if (SvROK (right))
		{
			IV diff = SvIV (SvRV (left)) - SvIV (SvRV (right));
			RETVAL = newSViv (diff);
		}
		else
		{
			IV days = SvIV (SvRV (left)) - SvIV (right);
			SV* new_date = sv_bless (newRV_noinc (newSViv (days)),
						 SvSTASH (SvRV (left)));
			SV* format;

			dSP;

			PUSHMARK(SP);
			XPUSHs(left);
			PUTBACK;

			call_method("default_format", G_SCALAR);

			SPAGAIN;

			format = POPs;

			PUSHMARK(SP);
			XPUSHs(new_date);
			XPUSHs(format);
			PUTBACK;

			call_method("default_format", G_DISCARD);

			RETVAL = new_date;
		}
	}
#line 866 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple__compare); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__compare)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "left, right, reverse");
    {
	SV*	left = ST(0)
;
	SV*	right = ST(1)
;
	bool	reverse = (bool)SvTRUE(ST(2))
;
	IV	RETVAL;
	dXSTARG;
#line 523 "Simple.xs"
	{
		IV diff;

		if (! is_object (left))
			XSRETURN_UNDEF;

		if (! is_object (right))
			right = new_for_cmp (left, right, 1);

		diff = SvIV (SvRV (left)) - SvIV (SvRV (right));
		RETVAL = diff > 0 ? 1 : (diff < 0 ? -1 : 0);

		if (reverse)
			RETVAL = -RETVAL;
	}
#line 905 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple__eq); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__eq)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "left, right, reverse");
    {
	SV*	left = ST(0)
;
	SV*	right = ST(1)
;
	bool	reverse = (bool)SvTRUE(ST(2))
;
	SV *	RETVAL;
#line 547 "Simple.xs"
	{
		if (! is_object (left))
			XSRETURN_UNDEF;

		if (! is_object (right))
			right = new_for_cmp (left, right, 0);

		if (! is_object (right))
			XSRETURN_NO;

		if (SvIV (SvRV (left)) == SvIV (SvRV (right)))
			XSRETURN_YES;
		else
			XSRETURN_NO;
	}
#line 942 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple__ne); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple__ne)
{
    dVAR; dXSARGS;
    if (items != 3)
       croak_xs_usage(cv,  "left, right, reverse");
    {
	SV*	left = ST(0)
;
	SV*	right = ST(1)
;
	bool	reverse = (bool)SvTRUE(ST(2))
;
	SV *	RETVAL;
#line 571 "Simple.xs"
	{
		if (! is_object (left))
			XSRETURN_UNDEF;

		if (! is_object (right))
			right = new_for_cmp (left, right, 0);

		if (! is_object (right))
			XSRETURN_YES;

		if (SvIV (SvRV (left)) == SvIV (SvRV (right)))
			XSRETURN_NO;
		else
			XSRETURN_YES;
	}
#line 980 "Simple.c"
	RETVAL = sv_2mortal(RETVAL);
	ST(0) = RETVAL;
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Date__Simple_day_of_week); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Date__Simple_day_of_week)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "date");
    {
	SV*	date = ST(0)
;
	IV	RETVAL;
	dXSTARG;
#line 593 "Simple.xs"
	{
		IV days;
		if (! SvROK (date))
			XSRETURN_UNDEF;

		RETVAL = (SvIV (SvRV (date)) + 4) % 7;
		if (RETVAL < 0)
			RETVAL += 7;
	}
#line 1009 "Simple.c"
	XSprePUSH; PUSHi((IV)RETVAL);
    }
    XSRETURN(1);
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Date__Simple); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Date__Simple)
{
#if PERL_VERSION_LE(5, 21, 5)
    dVAR; dXSARGS;
#else
    dVAR; dXSBOOTARGSXSAPIVERCHK;
#endif
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(file);

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#if PERL_VERSION_LE(5, 21, 5)
    XS_VERSION_BOOTCHECK;
#  ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#  endif
#endif

        newXS_deffile("Date::Simple::_ymd", XS_Date__Simple__ymd);
        newXS_deffile("Date::Simple::_d8", XS_Date__Simple__d8);
        newXS_deffile("Date::Simple::leap_year", XS_Date__Simple_leap_year);
        newXS_deffile("Date::Simple::days_in_month", XS_Date__Simple_days_in_month);
        newXS_deffile("Date::Simple::validate", XS_Date__Simple_validate);
        newXS_deffile("Date::Simple::ymd_to_days", XS_Date__Simple_ymd_to_days);
        newXS_deffile("Date::Simple::days_since_1970", XS_Date__Simple_days_since_1970);
        newXS_deffile("Date::Simple::days_to_ymd", XS_Date__Simple_days_to_ymd);
        newXS_deffile("Date::Simple::year", XS_Date__Simple_year);
        newXS_deffile("Date::Simple::month", XS_Date__Simple_month);
        newXS_deffile("Date::Simple::day", XS_Date__Simple_day);
        newXS_deffile("Date::Simple::as_iso", XS_Date__Simple_as_iso);
        newXS_deffile("Date::Simple::as_d8", XS_Date__Simple_as_d8);
        newXS_deffile("Date::Simple::as_ymd", XS_Date__Simple_as_ymd);
        newXS_deffile("Date::Simple::_add", XS_Date__Simple__add);
        newXS_deffile("Date::Simple::_subtract", XS_Date__Simple__subtract);
        newXS_deffile("Date::Simple::_compare", XS_Date__Simple__compare);
        newXS_deffile("Date::Simple::_eq", XS_Date__Simple__eq);
        newXS_deffile("Date::Simple::_ne", XS_Date__Simple__ne);
        newXS_deffile("Date::Simple::day_of_week", XS_Date__Simple_day_of_week);
#if PERL_VERSION_LE(5, 21, 5)
#  if PERL_VERSION_GE(5, 9, 0)
    if (PL_unitcheckav)
        call_list(PL_scopestack_ix, PL_unitcheckav);
#  endif
    XSRETURN_YES;
#else
    Perl_xs_boot_epilog(aTHX_ ax);
#endif
}

