Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Functions | Variables
_datetimemodule.c File Reference
#include "Python.h"
#include "structmember.h"
#include <time.h>
#include "_time.h"
#include "datetime.h"

Go to the source code of this file.

Classes

struct  PyDateTime_TimeZone

Defines

#define MINYEAR   1
#define MAXYEAR   9999
#define MAXORDINAL   3652059 /* date(9999,12,31).toordinal() */
#define MAX_DELTA_DAYS   999999999
#define GET_YEAR   PyDateTime_GET_YEAR
#define GET_MONTH   PyDateTime_GET_MONTH
#define GET_DAY   PyDateTime_GET_DAY
#define DATE_GET_HOUR   PyDateTime_DATE_GET_HOUR
#define DATE_GET_MINUTE   PyDateTime_DATE_GET_MINUTE
#define DATE_GET_SECOND   PyDateTime_DATE_GET_SECOND
#define DATE_GET_MICROSECOND   PyDateTime_DATE_GET_MICROSECOND
#define SET_YEAR(o, v)
#define SET_MONTH(o, v)   (PyDateTime_GET_MONTH(o) = (v))
#define SET_DAY(o, v)   (PyDateTime_GET_DAY(o) = (v))
#define DATE_SET_HOUR(o, v)   (PyDateTime_DATE_GET_HOUR(o) = (v))
#define DATE_SET_MINUTE(o, v)   (PyDateTime_DATE_GET_MINUTE(o) = (v))
#define DATE_SET_SECOND(o, v)   (PyDateTime_DATE_GET_SECOND(o) = (v))
#define DATE_SET_MICROSECOND(o, v)
#define TIME_GET_HOUR   PyDateTime_TIME_GET_HOUR
#define TIME_GET_MINUTE   PyDateTime_TIME_GET_MINUTE
#define TIME_GET_SECOND   PyDateTime_TIME_GET_SECOND
#define TIME_GET_MICROSECOND   PyDateTime_TIME_GET_MICROSECOND
#define TIME_SET_HOUR(o, v)   (PyDateTime_TIME_GET_HOUR(o) = (v))
#define TIME_SET_MINUTE(o, v)   (PyDateTime_TIME_GET_MINUTE(o) = (v))
#define TIME_SET_SECOND(o, v)   (PyDateTime_TIME_GET_SECOND(o) = (v))
#define TIME_SET_MICROSECOND(o, v)
#define GET_TD_DAYS(o)   (((PyDateTime_Delta *)(o))->days)
#define GET_TD_SECONDS(o)   (((PyDateTime_Delta *)(o))->seconds)
#define GET_TD_MICROSECONDS(o)   (((PyDateTime_Delta *)(o))->microseconds)
#define SET_TD_DAYS(o, v)   ((o)->days = (v))
#define SET_TD_SECONDS(o, v)   ((o)->seconds = (v))
#define SET_TD_MICROSECONDS(o, v)   ((o)->microseconds = (v))
#define HASTZINFO(p)   (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
#define GET_TIME_TZINFO(p)
#define GET_DT_TZINFO(p)
#define MONTH_IS_SANE(M)   ((unsigned int)(M) - 1 < 12)
#define SIGNED_ADD_OVERFLOWED(RESULT, I, J)   ((((RESULT) ^ (I)) & ((RESULT) ^ (J))) < 0)
#define DI4Y   1461 /* days_before_year(5); days in 4 years */
#define DI100Y   36524 /* days_before_year(101); days in 100 years */
#define DI400Y   146097 /* days_before_year(401); days in 400 years */
#define new_date(year, month, day)   new_date_ex(year, month, day, &PyDateTime_DateType)
#define new_datetime(y, m, d, hh, mm, ss, us, tzinfo)
#define new_time(hh, mm, ss, us, tzinfo)   new_time_ex(hh, mm, ss, us, tzinfo, &PyDateTime_TimeType)
#define new_delta(d, s, us, normalize)   new_delta_ex(d, s, us, normalize, &PyDateTime_DeltaType)
#define microseconds_to_delta(pymicros)   microseconds_to_delta_ex(pymicros, &PyDateTime_DeltaType)
#define CLEANUP
#define OFFSET(field)   offsetof(PyDateTime_Delta, field)

Typedefs

typedef struct tm *(* TM_FUNC )(const time_t *timer)

Functions

static int divmod (int x, int y, int *r)
static long round_to_long (double x)
static PyObjectdivide_nearest (PyObject *m, PyObject *n)
static int is_leap (int year)
static int days_in_month (int year, int month)
static int days_before_month (int year, int month)
static int days_before_year (int year)
static void ord_to_ymd (int ordinal, int *year, int *month, int *day)
static int ymd_to_ord (int year, int month, int day)
static int weekday (int year, int month, int day)
static int iso_week1_monday (int year)
static int check_delta_day_range (int days)
static int check_date_args (int year, int month, int day)
static int check_time_args (int h, int m, int s, int us)
static void normalize_pair (int *hi, int *lo, int factor)
static void normalize_d_s_us (int *d, int *s, int *us)
static int normalize_y_m_d (int *y, int *m, int *d)
static int normalize_date (int *year, int *month, int *day)
static int normalize_datetime (int *year, int *month, int *day, int *hour, int *minute, int *second, int *microsecond)
static PyObjecttime_alloc (PyTypeObject *type, Py_ssize_t aware)
static PyObjectdatetime_alloc (PyTypeObject *type, Py_ssize_t aware)
static void set_date_fields (PyDateTime_Date *self, int y, int m, int d)
static PyObjectnew_date_ex (int year, int month, int day, PyTypeObject *type)
static PyObjectnew_datetime_ex (int year, int month, int day, int hour, int minute, int second, int usecond, PyObject *tzinfo, PyTypeObject *type)
static PyObjectnew_time_ex (int hour, int minute, int second, int usecond, PyObject *tzinfo, PyTypeObject *type)
static PyObjectnew_delta_ex (int days, int seconds, int microseconds, int normalize, PyTypeObject *type)
static PyObjectcreate_timezone (PyObject *offset, PyObject *name)
static int delta_bool (PyDateTime_Delta *self)
static PyObjectnew_timezone (PyObject *offset, PyObject *name)
static int check_tzinfo_subclass (PyObject *p)
static PyObjectget_tzinfo_member (PyObject *self)
static PyObjectcall_tzinfo_method (PyObject *tzinfo, char *name, PyObject *tzinfoarg)
static PyObjectcall_utcoffset (PyObject *tzinfo, PyObject *tzinfoarg)
static PyObjectcall_dst (PyObject *tzinfo, PyObject *tzinfoarg)
static PyObjectcall_tzname (PyObject *tzinfo, PyObject *tzinfoarg)
static PyObjectappend_keyword_tzinfo (PyObject *repr, PyObject *tzinfo)
static PyObjectformat_ctime (PyDateTime_Date *date, int hours, int minutes, int seconds)
static PyObjectdelta_negative (PyDateTime_Delta *self)
static int format_utcoffset (char *buf, size_t buflen, const char *sep, PyObject *tzinfo, PyObject *tzinfoarg)
static PyObjectmake_Zreplacement (PyObject *object, PyObject *tzinfoarg)
static PyObjectmake_freplacement (PyObject *object)
static PyObjectwrap_strftime (PyObject *object, PyObject *format, PyObject *timetuple, PyObject *tzinfoarg)
static PyObjecttime_time (void)
static PyObjectbuild_struct_time (int y, int m, int d, int hh, int mm, int ss, int dstflag)
static PyObjectdiff_to_bool (int diff, int op)
static PyObjectcmperror (PyObject *a, PyObject *b)
static PyObjectdelta_to_microseconds (PyDateTime_Delta *self)
static PyObjectmicroseconds_to_delta_ex (PyObject *pyus, PyTypeObject *type)
static PyObjectmultiply_int_timedelta (PyObject *intobj, PyDateTime_Delta *delta)
static PyObjectmultiply_float_timedelta (PyObject *floatobj, PyDateTime_Delta *delta)
static PyObjectdivide_timedelta_int (PyDateTime_Delta *delta, PyObject *intobj)
static PyObjectdivide_timedelta_timedelta (PyDateTime_Delta *left, PyDateTime_Delta *right)
static PyObjecttruedivide_timedelta_timedelta (PyDateTime_Delta *left, PyDateTime_Delta *right)
static PyObjecttruedivide_timedelta_float (PyDateTime_Delta *delta, PyObject *f)
static PyObjecttruedivide_timedelta_int (PyDateTime_Delta *delta, PyObject *i)
static PyObjectdelta_add (PyObject *left, PyObject *right)
static PyObjectdelta_positive (PyDateTime_Delta *self)
static PyObjectdelta_abs (PyDateTime_Delta *self)
static PyObjectdelta_subtract (PyObject *left, PyObject *right)
static int delta_cmp (PyObject *self, PyObject *other)
static PyObjectdelta_richcompare (PyObject *self, PyObject *other, int op)
static PyObjectdelta_getstate (PyDateTime_Delta *self)
static Py_hash_t delta_hash (PyDateTime_Delta *self)
static PyObjectdelta_multiply (PyObject *left, PyObject *right)
static PyObjectdelta_divide (PyObject *left, PyObject *right)
static PyObjectdelta_truedivide (PyObject *left, PyObject *right)
static PyObjectdelta_remainder (PyObject *left, PyObject *right)
static PyObjectdelta_divmod (PyObject *left, PyObject *right)
static PyObjectaccum (const char *tag, PyObject *sofar, PyObject *num, PyObject *factor, double *leftover)
static PyObjectdelta_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static PyObjectdelta_repr (PyDateTime_Delta *self)
static PyObjectdelta_str (PyDateTime_Delta *self)
static PyObjectdelta_total_seconds (PyObject *self)
static PyObjectdelta_reduce (PyDateTime_Delta *self)
static PyObjectdate_year (PyDateTime_Date *self, void *unused)
static PyObjectdate_month (PyDateTime_Date *self, void *unused)
static PyObjectdate_day (PyDateTime_Date *self, void *unused)
static PyObjectdate_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static PyObjectdate_local_from_time_t (PyObject *cls, double ts)
static PyObjectdate_today (PyObject *cls, PyObject *dummy)
static PyObjectdate_fromtimestamp (PyObject *cls, PyObject *args)
static PyObjectdate_fromordinal (PyObject *cls, PyObject *args)
static PyObjectadd_date_timedelta (PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
static PyObjectdate_add (PyObject *left, PyObject *right)
static PyObjectdate_subtract (PyObject *left, PyObject *right)
static PyObjectdate_repr (PyDateTime_Date *self)
static PyObjectdate_isoformat (PyDateTime_Date *self)
static PyObjectdate_str (PyDateTime_Date *self)
static PyObjectdate_ctime (PyDateTime_Date *self)
static PyObjectdate_strftime (PyDateTime_Date *self, PyObject *args, PyObject *kw)
static PyObjectdate_format (PyDateTime_Date *self, PyObject *args)
static PyObjectdate_isoweekday (PyDateTime_Date *self)
static PyObjectdate_isocalendar (PyDateTime_Date *self)
static PyObjectdate_richcompare (PyObject *self, PyObject *other, int op)
static PyObjectdate_timetuple (PyDateTime_Date *self)
static PyObjectdate_replace (PyDateTime_Date *self, PyObject *args, PyObject *kw)
static Py_hash_t generic_hash (unsigned char *data, int len)
static PyObjectdate_getstate (PyDateTime_Date *self)
static Py_hash_t date_hash (PyDateTime_Date *self)
static PyObjectdate_toordinal (PyDateTime_Date *self)
static PyObjectdate_weekday (PyDateTime_Date *self)
static PyObjectdate_reduce (PyDateTime_Date *self, PyObject *arg)
static PyObjecttzinfo_nogo (const char *methodname)
static PyObjecttzinfo_tzname (PyDateTime_TZInfo *self, PyObject *dt)
static PyObjecttzinfo_utcoffset (PyDateTime_TZInfo *self, PyObject *dt)
static PyObjecttzinfo_dst (PyDateTime_TZInfo *self, PyObject *dt)
static PyObjectadd_datetime_timedelta (PyDateTime_DateTime *date, PyDateTime_Delta *delta, int factor)
static PyObjectdatetime_utcoffset (PyObject *self, PyObject *)
static PyObjectdatetime_dst (PyObject *self, PyObject *)
static PyObjecttzinfo_fromutc (PyDateTime_TZInfo *self, PyObject *dt)
static PyObjecttzinfo_reduce (PyObject *self)
static PyObjecttimezone_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static void timezone_dealloc (PyDateTime_TimeZone *self)
static PyObjecttimezone_richcompare (PyDateTime_TimeZone *self, PyDateTime_TimeZone *other, int op)
static Py_hash_t timezone_hash (PyDateTime_TimeZone *self)
static int _timezone_check_argument (PyObject *dt, const char *meth)
static PyObjecttimezone_repr (PyDateTime_TimeZone *self)
static PyObjecttimezone_str (PyDateTime_TimeZone *self)
static PyObjecttimezone_tzname (PyDateTime_TimeZone *self, PyObject *dt)
static PyObjecttimezone_utcoffset (PyDateTime_TimeZone *self, PyObject *dt)
static PyObjecttimezone_dst (PyObject *self, PyObject *dt)
static PyObjecttimezone_fromutc (PyDateTime_TimeZone *self, PyDateTime_DateTime *dt)
static PyObjecttimezone_getinitargs (PyDateTime_TimeZone *self)
static PyObjecttime_hour (PyDateTime_Time *self, void *unused)
static PyObjecttime_minute (PyDateTime_Time *self, void *unused)
static PyObjectpy_time_second (PyDateTime_Time *self, void *unused)
static PyObjecttime_microsecond (PyDateTime_Time *self, void *unused)
static PyObjecttime_tzinfo (PyDateTime_Time *self, void *unused)
static PyObjecttime_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static void time_dealloc (PyDateTime_Time *self)
static PyObjecttime_utcoffset (PyObject *self, PyObject *unused)
static PyObjecttime_dst (PyObject *self, PyObject *unused)
static PyObjecttime_tzname (PyDateTime_Time *self, PyObject *unused)
static PyObjecttime_repr (PyDateTime_Time *self)
static PyObjecttime_str (PyDateTime_Time *self)
static PyObjecttime_isoformat (PyDateTime_Time *self, PyObject *unused)
static PyObjecttime_strftime (PyDateTime_Time *self, PyObject *args, PyObject *kw)
static PyObjecttime_richcompare (PyObject *self, PyObject *other, int op)
static Py_hash_t time_hash (PyDateTime_Time *self)
static PyObjecttime_replace (PyDateTime_Time *self, PyObject *args, PyObject *kw)
static int time_bool (PyObject *self)
static PyObjecttime_getstate (PyDateTime_Time *self)
static PyObjecttime_reduce (PyDateTime_Time *self, PyObject *arg)
static PyObjectdatetime_hour (PyDateTime_DateTime *self, void *unused)
static PyObjectdatetime_minute (PyDateTime_DateTime *self, void *unused)
static PyObjectdatetime_second (PyDateTime_DateTime *self, void *unused)
static PyObjectdatetime_microsecond (PyDateTime_DateTime *self, void *unused)
static PyObjectdatetime_tzinfo (PyDateTime_DateTime *self, void *unused)
static PyObjectdatetime_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static PyObjectdatetime_from_timet_and_us (PyObject *cls, TM_FUNC f, time_t timet, int us, PyObject *tzinfo)
static PyObjectdatetime_from_timestamp (PyObject *cls, TM_FUNC f, double timestamp, PyObject *tzinfo)
static PyObjectdatetime_best_possible (PyObject *cls, TM_FUNC f, PyObject *tzinfo)
static PyObjectdatetime_now (PyObject *cls, PyObject *args, PyObject *kw)
static PyObjectdatetime_utcnow (PyObject *cls, PyObject *dummy)
static PyObjectdatetime_fromtimestamp (PyObject *cls, PyObject *args, PyObject *kw)
static PyObjectdatetime_utcfromtimestamp (PyObject *cls, PyObject *args)
static PyObjectdatetime_strptime (PyObject *cls, PyObject *args)
static PyObjectdatetime_combine (PyObject *cls, PyObject *args, PyObject *kw)
static void datetime_dealloc (PyDateTime_DateTime *self)
static PyObjectdatetime_tzname (PyObject *self, PyObject *unused)
static PyObjectdatetime_add (PyObject *left, PyObject *right)
static PyObjectdatetime_subtract (PyObject *left, PyObject *right)
static PyObjectdatetime_repr (PyDateTime_DateTime *self)
static PyObjectdatetime_str (PyDateTime_DateTime *self)
static PyObjectdatetime_isoformat (PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
static PyObjectdatetime_ctime (PyDateTime_DateTime *self)
static PyObjectdatetime_richcompare (PyObject *self, PyObject *other, int op)
static Py_hash_t datetime_hash (PyDateTime_DateTime *self)
static PyObjectdatetime_replace (PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
static PyObjectdatetime_astimezone (PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
static PyObjectdatetime_timetuple (PyDateTime_DateTime *self)
static PyObjectdatetime_getdate (PyDateTime_DateTime *self)
static PyObjectdatetime_gettime (PyDateTime_DateTime *self)
static PyObjectdatetime_gettimetz (PyDateTime_DateTime *self)
static PyObjectdatetime_utctimetuple (PyDateTime_DateTime *self)
static PyObjectdatetime_getstate (PyDateTime_DateTime *self)
static PyObjectdatetime_reduce (PyDateTime_DateTime *self, PyObject *arg)
PyMODINIT_FUNC PyInit__datetime (void)

Variables

static PyTypeObject PyDateTime_DateType
static PyTypeObject PyDateTime_DateTimeType
static PyTypeObject PyDateTime_DeltaType
static PyTypeObject PyDateTime_TimeType
static PyTypeObject PyDateTime_TZInfoType
static PyTypeObject PyDateTime_TimeZoneType
static int _days_in_month []
static int _days_before_month []
static PyObjectPyDateTime_TimeZone_UTC
static PyObjectus_per_us = NULL
static PyObjectus_per_ms = NULL
static PyObjectus_per_second = NULL
static PyObjectus_per_minute = NULL
static PyObjectus_per_hour = NULL
static PyObjectus_per_day = NULL
static PyObjectus_per_week = NULL
static PyObjectseconds_per_day = NULL
static PyMemberDef delta_members []
static PyMethodDef delta_methods []
static char delta_doc []
static PyNumberMethods delta_as_number
static PyGetSetDef date_getset []
static char * date_kws [] = {"year", "month", "day", NULL}
static PyMethodDef date_methods []
static char date_doc []
static PyNumberMethods date_as_number
static PyMethodDef tzinfo_methods []
static char tzinfo_doc []
static char * timezone_kws [] = {"offset", "name", NULL}
static PyMethodDef timezone_methods []
static char timezone_doc []
static PyGetSetDef time_getset []
static char * time_kws []
static PyMethodDef time_methods []
static char time_doc []
static PyNumberMethods time_as_number
static PyGetSetDef datetime_getset []
static char * datetime_kws []
static PyMethodDef datetime_methods []
static char datetime_doc []
static PyNumberMethods datetime_as_number
static PyMethodDef module_methods []
static PyDateTime_CAPI CAPI
static struct PyModuleDef

Class Documentation

struct PyDateTime_TimeZone

Definition at line 762 of file _datetimemodule.c.

Collaboration diagram for PyDateTime_TimeZone:
Class Members
PyObject * name
PyObject_HEAD PyObject * offset

Define Documentation

#define CLEANUP
Value:
Py_DECREF(x);       \
    x = y;              \
    if (x == NULL)      \
        goto Done

Definition at line 45 of file _datetimemodule.c.

Definition at line 48 of file _datetimemodule.c.

Definition at line 46 of file _datetimemodule.c.

Definition at line 47 of file _datetimemodule.c.

#define DATE_SET_HOUR (   o,
  v 
)    (PyDateTime_DATE_GET_HOUR(o) = (v))

Definition at line 57 of file _datetimemodule.c.

#define DATE_SET_MICROSECOND (   o,
  v 
)
Value:
(((o)->data[7] = ((v) & 0xff0000) >> 16), \
     ((o)->data[8] = ((v) & 0x00ff00) >> 8), \
     ((o)->data[9] = ((v) & 0x0000ff)))

Definition at line 60 of file _datetimemodule.c.

#define DATE_SET_MINUTE (   o,
  v 
)    (PyDateTime_DATE_GET_MINUTE(o) = (v))

Definition at line 58 of file _datetimemodule.c.

#define DATE_SET_SECOND (   o,
  v 
)    (PyDateTime_DATE_GET_SECOND(o) = (v))

Definition at line 59 of file _datetimemodule.c.

#define DI100Y   36524 /* days_before_year(101); days in 100 years */

Definition at line 253 of file _datetimemodule.c.

#define DI400Y   146097 /* days_before_year(401); days in 400 years */

Definition at line 254 of file _datetimemodule.c.

#define DI4Y   1461 /* days_before_year(5); days in 4 years */

Definition at line 252 of file _datetimemodule.c.

Definition at line 44 of file _datetimemodule.c.

#define GET_DT_TZINFO (   p)
Value:
(HASTZINFO(p) ? \
                          ((PyDateTime_DateTime *)(p))->tzinfo : Py_None)

Definition at line 93 of file _datetimemodule.c.

Definition at line 43 of file _datetimemodule.c.

#define GET_TD_DAYS (   o)    (((PyDateTime_Delta *)(o))->days)

Definition at line 79 of file _datetimemodule.c.

#define GET_TD_MICROSECONDS (   o)    (((PyDateTime_Delta *)(o))->microseconds)

Definition at line 81 of file _datetimemodule.c.

#define GET_TD_SECONDS (   o)    (((PyDateTime_Delta *)(o))->seconds)

Definition at line 80 of file _datetimemodule.c.

#define GET_TIME_TZINFO (   p)
Value:
(HASTZINFO(p) ? \
                            ((PyDateTime_Time *)(p))->tzinfo : Py_None)

Definition at line 91 of file _datetimemodule.c.

Definition at line 42 of file _datetimemodule.c.

#define HASTZINFO (   p)    (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)

Definition at line 90 of file _datetimemodule.c.

#define MAX_DELTA_DAYS   999999999

Definition at line 39 of file _datetimemodule.c.

#define MAXORDINAL   3652059 /* date(9999,12,31).toordinal() */

Definition at line 32 of file _datetimemodule.c.

#define MAXYEAR   9999

Definition at line 31 of file _datetimemodule.c.

#define microseconds_to_delta (   pymicros)    microseconds_to_delta_ex(pymicros, &PyDateTime_DeltaType)

Definition at line 1567 of file _datetimemodule.c.

#define MINYEAR   1

Definition at line 30 of file _datetimemodule.c.

#define MONTH_IS_SANE (   M)    ((unsigned int)(M) - 1 < 12)

Definition at line 99 of file _datetimemodule.c.

#define new_date (   year,
  month,
  day 
)    new_date_ex(year, month, day, &PyDateTime_DateType)

Definition at line 670 of file _datetimemodule.c.

#define new_datetime (   y,
  m,
  d,
  hh,
  mm,
  ss,
  us,
  tzinfo 
)
Value:
new_datetime_ex(y, m, d, hh, mm, ss, us, tzinfo,            \
                    &PyDateTime_DateTimeType)

Definition at line 697 of file _datetimemodule.c.

#define new_delta (   d,
  s,
  us,
  normalize 
)    new_delta_ex(d, s, us, normalize, &PyDateTime_DeltaType)

Definition at line 758 of file _datetimemodule.c.

#define new_time (   hh,
  mm,
  ss,
  us,
  tzinfo 
)    new_time_ex(hh, mm, ss, us, tzinfo, &PyDateTime_TimeType)

Definition at line 725 of file _datetimemodule.c.

#define OFFSET (   field)    offsetof(PyDateTime_Delta, field)

Definition at line 2285 of file _datetimemodule.c.

#define SET_DAY (   o,
  v 
)    (PyDateTime_GET_DAY(o) = (v))

Definition at line 54 of file _datetimemodule.c.

#define SET_MONTH (   o,
  v 
)    (PyDateTime_GET_MONTH(o) = (v))

Definition at line 53 of file _datetimemodule.c.

#define SET_TD_DAYS (   o,
  v 
)    ((o)->days = (v))

Definition at line 83 of file _datetimemodule.c.

#define SET_TD_MICROSECONDS (   o,
  v 
)    ((o)->microseconds = (v))

Definition at line 85 of file _datetimemodule.c.

#define SET_TD_SECONDS (   o,
  v 
)    ((o)->seconds = (v))

Definition at line 84 of file _datetimemodule.c.

#define SET_YEAR (   o,
  v 
)
Value:
(((o)->data[0] = ((v) & 0xff00) >> 8), \
                 ((o)->data[1] = ((v) & 0x00ff)))

Definition at line 51 of file _datetimemodule.c.

#define SIGNED_ADD_OVERFLOWED (   RESULT,
  I,
 
)    ((((RESULT) ^ (I)) & ((RESULT) ^ (J))) < 0)

Definition at line 117 of file _datetimemodule.c.

Definition at line 66 of file _datetimemodule.c.

Definition at line 69 of file _datetimemodule.c.

Definition at line 67 of file _datetimemodule.c.

Definition at line 68 of file _datetimemodule.c.

#define TIME_SET_HOUR (   o,
  v 
)    (PyDateTime_TIME_GET_HOUR(o) = (v))

Definition at line 70 of file _datetimemodule.c.

#define TIME_SET_MICROSECOND (   o,
  v 
)
Value:
(((o)->data[3] = ((v) & 0xff0000) >> 16), \
     ((o)->data[4] = ((v) & 0x00ff00) >> 8), \
     ((o)->data[5] = ((v) & 0x0000ff)))

Definition at line 73 of file _datetimemodule.c.

#define TIME_SET_MINUTE (   o,
  v 
)    (PyDateTime_TIME_GET_MINUTE(o) = (v))

Definition at line 71 of file _datetimemodule.c.

#define TIME_SET_SECOND (   o,
  v 
)    (PyDateTime_TIME_GET_SECOND(o) = (v))

Definition at line 72 of file _datetimemodule.c.


Typedef Documentation

typedef struct tm*(* TM_FUNC)(const time_t *timer)

Definition at line 4088 of file _datetimemodule.c.


Function Documentation

static int _timezone_check_argument ( PyObject dt,
const char *  meth 
) [static]

Definition at line 3261 of file _datetimemodule.c.

{
    if (dt == Py_None || PyDateTime_Check(dt))
        return 0;
    PyErr_Format(PyExc_TypeError, "%s(dt) argument must be a datetime instance"
                 " or None, not %.200s", meth, Py_TYPE(dt)->tp_name);
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* accum ( const char *  tag,
PyObject sofar,
PyObject num,
PyObject factor,
double *  leftover 
) [static]

Definition at line 2020 of file _datetimemodule.c.

{
    PyObject *prod;
    PyObject *sum;

    assert(num != NULL);

    if (PyLong_Check(num)) {
        prod = PyNumber_Multiply(num, factor);
        if (prod == NULL)
            return NULL;
        sum = PyNumber_Add(sofar, prod);
        Py_DECREF(prod);
        return sum;
    }

    if (PyFloat_Check(num)) {
        double dnum;
        double fracpart;
        double intpart;
        PyObject *x;
        PyObject *y;

        /* The Plan:  decompose num into an integer part and a
         * fractional part, num = intpart + fracpart.
         * Then num * factor ==
         *      intpart * factor + fracpart * factor
         * and the LHS can be computed exactly in long arithmetic.
         * The RHS is again broken into an int part and frac part.
         * and the frac part is added into *leftover.
         */
        dnum = PyFloat_AsDouble(num);
        if (dnum == -1.0 && PyErr_Occurred())
            return NULL;
        fracpart = modf(dnum, &intpart);
        x = PyLong_FromDouble(intpart);
        if (x == NULL)
            return NULL;

        prod = PyNumber_Multiply(x, factor);
        Py_DECREF(x);
        if (prod == NULL)
            return NULL;

        sum = PyNumber_Add(sofar, prod);
        Py_DECREF(prod);
        if (sum == NULL)
            return NULL;

        if (fracpart == 0.0)
            return sum;
        /* So far we've lost no information.  Dealing with the
         * fractional part requires float arithmetic, and may
         * lose a little info.
         */
        assert(PyLong_Check(factor));
        dnum = PyLong_AsDouble(factor);

        dnum *= fracpart;
        fracpart = modf(dnum, &intpart);
        x = PyLong_FromDouble(intpart);
        if (x == NULL) {
            Py_DECREF(sum);
            return NULL;
        }

        y = PyNumber_Add(sum, x);
        Py_DECREF(sum);
        Py_DECREF(x);
        *leftover += fracpart;
        return y;
    }

    PyErr_Format(PyExc_TypeError,
                 "unsupported type for timedelta %s component: %s",
                 tag, Py_TYPE(num)->tp_name);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* add_date_timedelta ( PyDateTime_Date date,
PyDateTime_Delta delta,
int  negate 
) [static]

Definition at line 2557 of file _datetimemodule.c.

{
    PyObject *result = NULL;
    int year = GET_YEAR(date);
    int month = GET_MONTH(date);
    int deltadays = GET_TD_DAYS(delta);
    /* C-level overflow is impossible because |deltadays| < 1e9. */
    int day = GET_DAY(date) + (negate ? -deltadays : deltadays);

    if (normalize_date(&year, &month, &day) >= 0)
        result = new_date(year, month, day);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * add_datetime_timedelta ( PyDateTime_DateTime date,
PyDateTime_Delta delta,
int  factor 
) [static]

Definition at line 4344 of file _datetimemodule.c.

{
    /* Note that the C-level additions can't overflow, because of
     * invariant bounds on the member values.
     */
    int year = GET_YEAR(date);
    int month = GET_MONTH(date);
    int day = GET_DAY(date) + GET_TD_DAYS(delta) * factor;
    int hour = DATE_GET_HOUR(date);
    int minute = DATE_GET_MINUTE(date);
    int second = DATE_GET_SECOND(date) + GET_TD_SECONDS(delta) * factor;
    int microsecond = DATE_GET_MICROSECOND(date) +
                      GET_TD_MICROSECONDS(delta) * factor;

    assert(factor == 1 || factor == -1);
    if (normalize_datetime(&year, &month, &day,
                           &hour, &minute, &second, &microsecond) < 0)
        return NULL;
    else
        return new_datetime(year, month, day,
                            hour, minute, second, microsecond,
                            HASTZINFO(date) ? date->tzinfo : Py_None);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* append_keyword_tzinfo ( PyObject repr,
PyObject tzinfo 
) [static]

Definition at line 979 of file _datetimemodule.c.

{
    PyObject *temp;

    assert(PyUnicode_Check(repr));
    assert(tzinfo);
    if (tzinfo == Py_None)
        return repr;
    /* Get rid of the trailing ')'. */
    assert(PyUnicode_AS_UNICODE(repr)[PyUnicode_GET_SIZE(repr)-1] == ')');
    temp = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(repr),
                                      PyUnicode_GET_SIZE(repr) - 1);
    Py_DECREF(repr);
    if (temp == NULL)
        return NULL;
    repr = PyUnicode_FromFormat("%U, tzinfo=%R)", temp, tzinfo);
    Py_DECREF(temp);
    return repr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* build_struct_time ( int  y,
int  m,
int  d,
int  hh,
int  mm,
int  ss,
int  dstflag 
) [static]

Definition at line 1351 of file _datetimemodule.c.

{
    PyObject *time;
    PyObject *result = NULL;

    time = PyImport_ImportModuleNoBlock("time");
    if (time != NULL) {
        result = PyObject_CallMethod(time, "struct_time",
                                     "((iiiiiiiii))",
                                     y, m, d,
                                     hh, mm, ss,
                                     weekday(y, m, d),
                                     days_before_month(y, m) + d,
                                     dstflag);
        Py_DECREF(time);
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_dst ( PyObject tzinfo,
PyObject tzinfoarg 
) [static]

Definition at line 934 of file _datetimemodule.c.

{
    return call_tzinfo_method(tzinfo, "dst", tzinfoarg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_tzinfo_method ( PyObject tzinfo,
char *  name,
PyObject tzinfoarg 
) [static]

Definition at line 870 of file _datetimemodule.c.

{
    PyObject *offset;

    assert(tzinfo != NULL);
    assert(PyTZInfo_Check(tzinfo) || tzinfo == Py_None);
    assert(tzinfoarg != NULL);

    if (tzinfo == Py_None)
        Py_RETURN_NONE;
    offset = PyObject_CallMethod(tzinfo, name, "O", tzinfoarg);
    if (offset == Py_None || offset == NULL)
        return offset;
    if (PyDelta_Check(offset)) {
        if (GET_TD_MICROSECONDS(offset) != 0 || GET_TD_SECONDS(offset) % 60 != 0) {
            Py_DECREF(offset);
            PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
                         " representing a whole number of minutes");
            return NULL;
        }
        if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) ||
            GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) {
            Py_DECREF(offset);
            PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
                         " strictly between -timedelta(hours=24) and"
                         " timedelta(hours=24).");
            return NULL;
        }
    }
    else {
        Py_DECREF(offset);
        PyErr_Format(PyExc_TypeError,
                     "tzinfo.%s() must return None or "
                     "timedelta, not '%.200s'",
                     name, Py_TYPE(offset)->tp_name);
        return NULL;
    }

    return offset;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_tzname ( PyObject tzinfo,
PyObject tzinfoarg 
) [static]

Definition at line 946 of file _datetimemodule.c.

{
    PyObject *result;

    assert(tzinfo != NULL);
    assert(check_tzinfo_subclass(tzinfo) >= 0);
    assert(tzinfoarg != NULL);

    if (tzinfo == Py_None)
        Py_RETURN_NONE;

    result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);

    if (result == NULL || result == Py_None)
        return result;

    if (!PyUnicode_Check(result)) {
        PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
                     "return None or a string, not '%s'",
                     Py_TYPE(result)->tp_name);
        Py_DECREF(result);
        result = NULL;
    }

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_utcoffset ( PyObject tzinfo,
PyObject tzinfoarg 
) [static]

Definition at line 920 of file _datetimemodule.c.

{
    return call_tzinfo_method(tzinfo, "utcoffset", tzinfoarg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_date_args ( int  year,
int  month,
int  day 
) [static]

Definition at line 393 of file _datetimemodule.c.

{

    if (year < MINYEAR || year > MAXYEAR) {
        PyErr_SetString(PyExc_ValueError,
                        "year is out of range");
        return -1;
    }
    if (month < 1 || month > 12) {
        PyErr_SetString(PyExc_ValueError,
                        "month must be in 1..12");
        return -1;
    }
    if (day < 1 || day > days_in_month(year, month)) {
        PyErr_SetString(PyExc_ValueError,
                        "day is out of range for month");
        return -1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_delta_day_range ( int  days) [static]

Definition at line 379 of file _datetimemodule.c.

{
    if (-MAX_DELTA_DAYS <= days && days <= MAX_DELTA_DAYS)
        return 0;
    PyErr_Format(PyExc_OverflowError,
                 "days=%d; must have magnitude <= %d",
                 days, MAX_DELTA_DAYS);
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_time_args ( int  h,
int  m,
int  s,
int  us 
) [static]

Definition at line 418 of file _datetimemodule.c.

{
    if (h < 0 || h > 23) {
        PyErr_SetString(PyExc_ValueError,
                        "hour must be in 0..23");
        return -1;
    }
    if (m < 0 || m > 59) {
        PyErr_SetString(PyExc_ValueError,
                        "minute must be in 0..59");
        return -1;
    }
    if (s < 0 || s > 59) {
        PyErr_SetString(PyExc_ValueError,
                        "second must be in 0..59");
        return -1;
    }
    if (us < 0 || us > 999999) {
        PyErr_SetString(PyExc_ValueError,
                        "microsecond must be in 0..999999");
        return -1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_tzinfo_subclass ( PyObject p) [static]

Definition at line 834 of file _datetimemodule.c.

{
    if (p == Py_None || PyTZInfo_Check(p))
        return 0;
    PyErr_Format(PyExc_TypeError,
                 "tzinfo argument must be None or of a tzinfo subclass, "
                 "not type '%s'",
                 Py_TYPE(p)->tp_name);
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* cmperror ( PyObject a,
PyObject b 
) [static]

Definition at line 1402 of file _datetimemodule.c.

{
    PyErr_Format(PyExc_TypeError,
                 "can't compare %s to %s",
                 Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* create_timezone ( PyObject offset,
PyObject name 
) [static]

Definition at line 777 of file _datetimemodule.c.

{
    PyDateTime_TimeZone *self;
    PyTypeObject *type = &PyDateTime_TimeZoneType;

    assert(offset != NULL);
    assert(PyDelta_Check(offset));
    assert(name == NULL || PyUnicode_Check(name));

    self = (PyDateTime_TimeZone *)(type->tp_alloc(type, 0));
    if (self == NULL) {
        return NULL;
    }
    Py_INCREF(offset);
    self->offset = offset;
    Py_XINCREF(name);
    self->name = name;
    return (PyObject *)self;
}

Here is the caller graph for this function:

static PyObject* date_add ( PyObject left,
PyObject right 
) [static]

Definition at line 2572 of file _datetimemodule.c.

{
    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    if (PyDate_Check(left)) {
        /* date + ??? */
        if (PyDelta_Check(right))
            /* date + delta */
            return add_date_timedelta((PyDateTime_Date *) left,
                                      (PyDateTime_Delta *) right,
                                      0);
    }
    else {
        /* ??? + date
         * 'right' must be one of us, or we wouldn't have been called
         */
        if (PyDelta_Check(left))
            /* delta + date */
            return add_date_timedelta((PyDateTime_Date *) right,
                                      (PyDateTime_Delta *) left,
                                      0);
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

static PyObject* date_ctime ( PyDateTime_Date self) [static]

Definition at line 2656 of file _datetimemodule.c.

{
    return format_ctime(self, 0, 0, 0);
}

Here is the call graph for this function:

static PyObject* date_day ( PyDateTime_Date self,
void unused 
) [static]

Definition at line 2410 of file _datetimemodule.c.

{
    return PyLong_FromLong(GET_DAY(self));
}

Here is the call graph for this function:

static PyObject* date_format ( PyDateTime_Date self,
PyObject args 
) [static]

Definition at line 2686 of file _datetimemodule.c.

{
    PyObject *format;

    if (!PyArg_ParseTuple(args, "U:__format__", &format))
        return NULL;

    /* if the format is zero length, return str(self) */
    if (PyUnicode_GetSize(format) == 0)
        return PyObject_Str((PyObject *)self);

    return PyObject_CallMethod((PyObject *)self, "strftime", "O", format);
}

Here is the call graph for this function:

static PyObject* date_fromordinal ( PyObject cls,
PyObject args 
) [static]

Definition at line 2527 of file _datetimemodule.c.

{
    PyObject *result = NULL;
    int ordinal;

    if (PyArg_ParseTuple(args, "i:fromordinal", &ordinal)) {
        int year;
        int month;
        int day;

        if (ordinal < 1)
            PyErr_SetString(PyExc_ValueError, "ordinal must be "
                                              ">= 1");
        else {
            ord_to_ymd(ordinal, &year, &month, &day);
            result = PyObject_CallFunction(cls, "iii",
                                           year, month, day);
        }
    }
    return result;
}

Here is the call graph for this function:

static PyObject* date_fromtimestamp ( PyObject cls,
PyObject args 
) [static]

Definition at line 2513 of file _datetimemodule.c.

{
    double timestamp;
    PyObject *result = NULL;

    if (PyArg_ParseTuple(args, "d:fromtimestamp", &timestamp))
        result = date_local_from_time_t(cls, timestamp);
    return result;
}

Here is the call graph for this function:

static PyObject * date_getstate ( PyDateTime_Date self) [static]

Definition at line 2830 of file _datetimemodule.c.

{
    PyObject* field;
    field = PyBytes_FromStringAndSize((char*)self->data,
                                       _PyDateTime_DATE_DATASIZE);
    return Py_BuildValue("(N)", field);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_hash_t date_hash ( PyDateTime_Date self) [static]

Definition at line 2802 of file _datetimemodule.c.

{
    if (self->hashcode == -1)
        self->hashcode = generic_hash(
            (unsigned char *)self->data, _PyDateTime_DATE_DATASIZE);

    return self->hashcode;
}

Here is the call graph for this function:

static PyObject* date_isocalendar ( PyDateTime_Date self) [static]

Definition at line 2711 of file _datetimemodule.c.

{
    int  year         = GET_YEAR(self);
    int  week1_monday = iso_week1_monday(year);
    int today         = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
    int  week;
    int  day;

    week = divmod(today - week1_monday, 7, &day);
    if (week < 0) {
        --year;
        week1_monday = iso_week1_monday(year);
        week = divmod(today - week1_monday, 7, &day);
    }
    else if (week >= 52 && today >= iso_week1_monday(year + 1)) {
        ++year;
        week = 0;
    }
    return Py_BuildValue("iii", year, week + 1, day + 1);
}

Here is the call graph for this function:

static PyObject* date_isoformat ( PyDateTime_Date self) [static]

Definition at line 2641 of file _datetimemodule.c.

{
    return PyUnicode_FromFormat("%04d-%02d-%02d",
                                GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
}
static PyObject* date_isoweekday ( PyDateTime_Date self) [static]

Definition at line 2703 of file _datetimemodule.c.

{
    int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));

    return PyLong_FromLong(dow + 1);
}

Here is the call graph for this function:

static PyObject* date_local_from_time_t ( PyObject cls,
double  ts 
) [static]

Definition at line 2463 of file _datetimemodule.c.

{
    struct tm *tm;
    time_t t;
    PyObject *result = NULL;

    t = _PyTime_DoubleToTimet(ts);
    if (t == (time_t)-1 && PyErr_Occurred())
        return NULL;
    tm = localtime(&t);
    if (tm)
        result = PyObject_CallFunction(cls, "iii",
                                       tm->tm_year + 1900,
                                       tm->tm_mon + 1,
                                       tm->tm_mday);
    else
        PyErr_SetString(PyExc_ValueError,
                        "timestamp out of range for "
                        "platform localtime() function");
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* date_month ( PyDateTime_Date self,
void unused 
) [static]

Definition at line 2404 of file _datetimemodule.c.

{
    return PyLong_FromLong(GET_MONTH(self));
}

Here is the call graph for this function:

static PyObject* date_new ( PyTypeObject type,
PyObject args,
PyObject kw 
) [static]

Definition at line 2427 of file _datetimemodule.c.

{
    PyObject *self = NULL;
    PyObject *state;
    int year;
    int month;
    int day;

    /* Check for invocation from pickle with __getstate__ state */
    if (PyTuple_GET_SIZE(args) == 1 &&
        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
        PyBytes_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
        MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
    {
        PyDateTime_Date *me;

        me = (PyDateTime_Date *) (type->tp_alloc(type, 0));
        if (me != NULL) {
            char *pdata = PyBytes_AS_STRING(state);
            memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
            me->hashcode = -1;
        }
        return (PyObject *)me;
    }

    if (PyArg_ParseTupleAndKeywords(args, kw, "iii", date_kws,
                                    &year, &month, &day)) {
        if (check_date_args(year, month, day) < 0)
            return NULL;
        self = new_date_ex(year, month, day, type);
    }
    return self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* date_reduce ( PyDateTime_Date self,
PyObject arg 
) [static]

Definition at line 2839 of file _datetimemodule.c.

{
    return Py_BuildValue("(ON)", Py_TYPE(self), date_getstate(self));
}

Here is the call graph for this function:

static PyObject* date_replace ( PyDateTime_Date self,
PyObject args,
PyObject kw 
) [static]

Definition at line 2759 of file _datetimemodule.c.

{
    PyObject *clone;
    PyObject *tuple;
    int year = GET_YEAR(self);
    int month = GET_MONTH(self);
    int day = GET_DAY(self);

    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iii:replace", date_kws,
                                      &year, &month, &day))
        return NULL;
    tuple = Py_BuildValue("iii", year, month, day);
    if (tuple == NULL)
        return NULL;
    clone = date_new(Py_TYPE(self), tuple, NULL);
    Py_DECREF(tuple);
    return clone;
}

Here is the call graph for this function:

static PyObject* date_repr ( PyDateTime_Date self) [static]

Definition at line 2633 of file _datetimemodule.c.

{
    return PyUnicode_FromFormat("%s(%d, %d, %d)",
                                Py_TYPE(self)->tp_name,
                                GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
}
static PyObject* date_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 2735 of file _datetimemodule.c.

{
    if (PyDate_Check(other)) {
        int diff = memcmp(((PyDateTime_Date *)self)->data,
                          ((PyDateTime_Date *)other)->data,
                          _PyDateTime_DATE_DATASIZE);
        return diff_to_bool(diff, op);
    }
    else {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
}

Here is the call graph for this function:

static PyObject* date_str ( PyDateTime_Date self) [static]

Definition at line 2649 of file _datetimemodule.c.

{
    return PyObject_CallMethod((PyObject *)self, "isoformat", "()");
}

Here is the call graph for this function:

static PyObject* date_strftime ( PyDateTime_Date self,
PyObject args,
PyObject kw 
) [static]

Definition at line 2662 of file _datetimemodule.c.

{
    /* This method can be inherited, and needs to call the
     * timetuple() method appropriate to self's class.
     */
    PyObject *result;
    PyObject *tuple;
    PyObject *format;
    static char *keywords[] = {"format", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
                                      &format))
        return NULL;

    tuple = PyObject_CallMethod((PyObject *)self, "timetuple", "()");
    if (tuple == NULL)
        return NULL;
    result = wrap_strftime((PyObject *)self, format, tuple,
                           (PyObject *)self);
    Py_DECREF(tuple);
    return result;
}

Here is the call graph for this function:

static PyObject* date_subtract ( PyObject left,
PyObject right 
) [static]

Definition at line 2601 of file _datetimemodule.c.

{
    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    if (PyDate_Check(left)) {
        if (PyDate_Check(right)) {
            /* date - date */
            int left_ord = ymd_to_ord(GET_YEAR(left),
                                      GET_MONTH(left),
                                      GET_DAY(left));
            int right_ord = ymd_to_ord(GET_YEAR(right),
                                       GET_MONTH(right),
                                       GET_DAY(right));
            return new_delta(left_ord - right_ord, 0, 0, 0);
        }
        if (PyDelta_Check(right)) {
            /* date - delta */
            return add_date_timedelta((PyDateTime_Date *) left,
                                      (PyDateTime_Delta *) right,
                                      1);
        }
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

static PyObject* date_timetuple ( PyDateTime_Date self) [static]

Definition at line 2750 of file _datetimemodule.c.

{
    return build_struct_time(GET_YEAR(self),
                             GET_MONTH(self),
                             GET_DAY(self),
                             0, 0, 0, -1);
}

Here is the call graph for this function:

static PyObject* date_today ( PyObject cls,
PyObject dummy 
) [static]

Definition at line 2491 of file _datetimemodule.c.

{
    PyObject *time;
    PyObject *result;

    time = time_time();
    if (time == NULL)
        return NULL;

    /* Note well:  today() is a class method, so this may not call
     * date.fromtimestamp.  For example, it may call
     * datetime.fromtimestamp.  That's why we need all the accuracy
     * time.time() delivers; if someone were gonzo about optimization,
     * date.today() could get away with plain C time().
     */
    result = PyObject_CallMethod(cls, "fromtimestamp", "O", time);
    Py_DECREF(time);
    return result;
}

Here is the call graph for this function:

static PyObject* date_toordinal ( PyDateTime_Date self) [static]

Definition at line 2812 of file _datetimemodule.c.

{
    return PyLong_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
                                     GET_DAY(self)));
}

Here is the call graph for this function:

static PyObject* date_weekday ( PyDateTime_Date self) [static]

Definition at line 2819 of file _datetimemodule.c.

{
    int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));

    return PyLong_FromLong(dow);
}

Here is the call graph for this function:

static PyObject* date_year ( PyDateTime_Date self,
void unused 
) [static]

Definition at line 2398 of file _datetimemodule.c.

{
    return PyLong_FromLong(GET_YEAR(self));
}

Here is the call graph for this function:

static PyObject* datetime_add ( PyObject left,
PyObject right 
) [static]

Definition at line 4370 of file _datetimemodule.c.

{
    if (PyDateTime_Check(left)) {
        /* datetime + ??? */
        if (PyDelta_Check(right))
            /* datetime + delta */
            return add_datetime_timedelta(
                            (PyDateTime_DateTime *)left,
                            (PyDateTime_Delta *)right,
                            1);
    }
    else if (PyDelta_Check(left)) {
        /* delta + datetime */
        return add_datetime_timedelta((PyDateTime_DateTime *) right,
                                      (PyDateTime_Delta *) left,
                                      1);
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

static PyObject* datetime_alloc ( PyTypeObject type,
Py_ssize_t  aware 
) [static]

Definition at line 625 of file _datetimemodule.c.

{
    PyObject *self;

    self = (PyObject *)
        PyObject_MALLOC(aware ?
                        sizeof(PyDateTime_DateTime) :
                sizeof(_PyDateTime_BaseDateTime));
    if (self == NULL)
        return (PyObject *)PyErr_NoMemory();
    PyObject_INIT(self, type);
    return self;
}

Here is the call graph for this function:

static PyObject* datetime_astimezone ( PyDateTime_DateTime self,
PyObject args,
PyObject kw 
) [static]

Definition at line 4719 of file _datetimemodule.c.

{
    PyObject *result;
    PyObject *offset;
    PyObject *temp;
    PyObject *tzinfo;
    static char *keywords[] = {"tz", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:astimezone", keywords,
                                      &PyDateTime_TZInfoType, &tzinfo))
        return NULL;

    if (!HASTZINFO(self) || self->tzinfo == Py_None)
        goto NeedAware;

    /* Conversion to self's own time zone is a NOP. */
    if (self->tzinfo == tzinfo) {
        Py_INCREF(self);
        return (PyObject *)self;
    }

    /* Convert self to UTC. */
    offset = datetime_utcoffset((PyObject *)self, NULL);
    if (offset == NULL)
        return NULL;
    if (offset == Py_None) {
        Py_DECREF(offset);
      NeedAware:
        PyErr_SetString(PyExc_ValueError, "astimezone() cannot be applied to "
                        "a naive datetime");
        return NULL;
    }

    /* result = self - offset */
    result = add_datetime_timedelta(self,
                (PyDateTime_Delta *)offset, -1);
    Py_DECREF(offset);
    if (result == NULL)
        return NULL;

    /* Attach new tzinfo and let fromutc() do the rest. */
    temp = ((PyDateTime_DateTime *)result)->tzinfo;
    ((PyDateTime_DateTime *)result)->tzinfo = tzinfo;
    Py_INCREF(tzinfo);
    Py_DECREF(temp);

    temp = result;
    result = PyObject_CallMethod(tzinfo, "fromutc", "O", temp);
    Py_DECREF(temp);

    return result;
}

Here is the call graph for this function:

static PyObject* datetime_best_possible ( PyObject cls,
TM_FUNC  f,
PyObject tzinfo 
) [static]

Definition at line 4169 of file _datetimemodule.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_combine ( PyObject cls,
PyObject args,
PyObject kw 
) [static]

Definition at line 4276 of file _datetimemodule.c.

{
    static char *keywords[] = {"date", "time", NULL};
    PyObject *date;
    PyObject *time;
    PyObject *result = NULL;

    if (PyArg_ParseTupleAndKeywords(args, kw, "O!O!:combine", keywords,
                                    &PyDateTime_DateType, &date,
                                    &PyDateTime_TimeType, &time)) {
        PyObject *tzinfo = Py_None;

        if (HASTZINFO(time))
            tzinfo = ((PyDateTime_Time *)time)->tzinfo;
        result = PyObject_CallFunction(cls, "iiiiiiiO",
                                        GET_YEAR(date),
                                        GET_MONTH(date),
                                        GET_DAY(date),
                                        TIME_GET_HOUR(time),
                                        TIME_GET_MINUTE(time),
                                        TIME_GET_SECOND(time),
                                        TIME_GET_MICROSECOND(time),
                                        tzinfo);
    }
    return result;
}

Here is the call graph for this function:

static PyObject* datetime_ctime ( PyDateTime_DateTime self) [static]

Definition at line 4558 of file _datetimemodule.c.

{
    return format_ctime((PyDateTime_Date *)self,
                        DATE_GET_HOUR(self),
                        DATE_GET_MINUTE(self),
                        DATE_GET_SECOND(self));
}

Here is the call graph for this function:

static void datetime_dealloc ( PyDateTime_DateTime self) [static]

Definition at line 4308 of file _datetimemodule.c.

{
    if (HASTZINFO(self)) {
        Py_XDECREF(self->tzinfo);
    }
    Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyObject * datetime_dst ( PyObject self,
PyObject unused 
) [static]

Definition at line 4327 of file _datetimemodule.c.

                                               {
    return call_dst(GET_DT_TZINFO(self), self);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_from_timestamp ( PyObject cls,
TM_FUNC  f,
double  timestamp,
PyObject tzinfo 
) [static]

Definition at line 4136 of file _datetimemodule.c.

{
    time_t timet;
    double fraction;
    int us;

    timet = _PyTime_DoubleToTimet(timestamp);
    if (timet == (time_t)-1 && PyErr_Occurred())
        return NULL;
    fraction = timestamp - (double)timet;
    us = (int)round_to_long(fraction * 1e6);
    if (us < 0) {
        /* Truncation towards zero is not what we wanted
           for negative numbers (Python's mod semantics) */
        timet -= 1;
        us += 1000000;
    }
    /* If timestamp is less than one microsecond smaller than a
     * full second, round up. Otherwise, ValueErrors are raised
     * for some floats. */
    if (us == 1000000) {
        timet += 1;
        us = 0;
    }
    return datetime_from_timet_and_us(cls, f, timet, us, tzinfo);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_from_timet_and_us ( PyObject cls,
TM_FUNC  f,
time_t  timet,
int  us,
PyObject tzinfo 
) [static]

Definition at line 4095 of file _datetimemodule.c.

{
    struct tm *tm;
    PyObject *result = NULL;

    tm = f(&timet);
    if (tm) {
        /* The platform localtime/gmtime may insert leap seconds,
         * indicated by tm->tm_sec > 59.  We don't care about them,
         * except to the extent that passing them on to the datetime
         * constructor would raise ValueError for a reason that
         * made no sense to the user.
         */
        if (tm->tm_sec > 59)
            tm->tm_sec = 59;
        result = PyObject_CallFunction(cls, "iiiiiiiO",
                                       tm->tm_year + 1900,
                                       tm->tm_mon + 1,
                                       tm->tm_mday,
                                       tm->tm_hour,
                                       tm->tm_min,
                                       tm->tm_sec,
                                       us,
                                       tzinfo);
    }
    else
        PyErr_SetString(PyExc_ValueError,
                        "timestamp out of range for "
                        "platform localtime()/gmtime() function");
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_fromtimestamp ( PyObject cls,
PyObject args,
PyObject kw 
) [static]

Definition at line 4216 of file _datetimemodule.c.

{
    PyObject *self;
    double timestamp;
    PyObject *tzinfo = Py_None;
    static char *keywords[] = {"timestamp", "tz", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kw, "d|O:fromtimestamp",
                                      keywords, &timestamp, &tzinfo))
        return NULL;
    if (check_tzinfo_subclass(tzinfo) < 0)
        return NULL;

    self = datetime_from_timestamp(cls,
                                   tzinfo == Py_None ? localtime : gmtime,
                                   timestamp,
                                   tzinfo);
    if (self != NULL && tzinfo != Py_None) {
        /* Convert UTC to tzinfo's zone. */
        PyObject *temp = self;
        self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
        Py_DECREF(temp);
    }
    return self;
}

Here is the call graph for this function:

static PyObject* datetime_getdate ( PyDateTime_DateTime self) [static]

Definition at line 4798 of file _datetimemodule.c.

{
    return new_date(GET_YEAR(self),
                    GET_MONTH(self),
                    GET_DAY(self));
}
static PyObject* datetime_getstate ( PyDateTime_DateTime self) [static]

Definition at line 4874 of file _datetimemodule.c.

{
    PyObject *basestate;
    PyObject *result = NULL;

    basestate = PyBytes_FromStringAndSize((char *)self->data,
                                           _PyDateTime_DATETIME_DATASIZE);
    if (basestate != NULL) {
        if (! HASTZINFO(self) || self->tzinfo == Py_None)
            result = PyTuple_Pack(1, basestate);
        else
            result = PyTuple_Pack(2, basestate, self->tzinfo);
        Py_DECREF(basestate);
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_gettime ( PyDateTime_DateTime self) [static]

Definition at line 4806 of file _datetimemodule.c.

static PyObject* datetime_gettimetz ( PyDateTime_DateTime self) [static]

Definition at line 4816 of file _datetimemodule.c.

static Py_hash_t datetime_hash ( PyDateTime_DateTime self) [static]

Definition at line 4645 of file _datetimemodule.c.

{
    if (self->hashcode == -1) {
        PyObject *offset;

        offset = datetime_utcoffset((PyObject *)self, NULL);

        if (offset == NULL)
            return -1;

        /* Reduce this to a hash of another object. */
        if (offset == Py_None)
            self->hashcode = generic_hash(
                (unsigned char *)self->data, _PyDateTime_DATETIME_DATASIZE);
        else {
            PyObject *temp1, *temp2;
            int days, seconds;

            assert(HASTZINFO(self));
            days = ymd_to_ord(GET_YEAR(self),
                              GET_MONTH(self),
                              GET_DAY(self));
            seconds = DATE_GET_HOUR(self) * 3600 +
                      DATE_GET_MINUTE(self) * 60 +
                      DATE_GET_SECOND(self);
            temp1 = new_delta(days, seconds,
                              DATE_GET_MICROSECOND(self),
                              1);
            if (temp1 == NULL) {
                Py_DECREF(offset);
                return -1;
            }
            temp2 = delta_subtract(temp1, offset);
            Py_DECREF(temp1);
            if (temp2 == NULL) {
                Py_DECREF(offset);
                return -1;
            }
            self->hashcode = PyObject_Hash(temp2);
            Py_DECREF(temp2);
        }
        Py_DECREF(offset);
    }
    return self->hashcode;
}

Here is the call graph for this function:

static PyObject* datetime_hour ( PyDateTime_DateTime self,
void unused 
) [static]

Definition at line 3974 of file _datetimemodule.c.

{
    return PyLong_FromLong(DATE_GET_HOUR(self));
}

Here is the call graph for this function:

static PyObject* datetime_isoformat ( PyDateTime_DateTime self,
PyObject args,
PyObject kw 
) [static]

Definition at line 4521 of file _datetimemodule.c.

{
    int sep = 'T';
    static char *keywords[] = {"sep", NULL};
    char buffer[100];
    PyObject *result;
    int us = DATE_GET_MICROSECOND(self);

    if (!PyArg_ParseTupleAndKeywords(args, kw, "|C:isoformat", keywords, &sep))
        return NULL;
    if (us)
        result = PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d.%06d",
                                      GET_YEAR(self), GET_MONTH(self),
                                      GET_DAY(self), (int)sep,
                                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
                                      DATE_GET_SECOND(self), us);
    else
        result = PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d",
                                      GET_YEAR(self), GET_MONTH(self),
                                      GET_DAY(self), (int)sep,
                                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
                                      DATE_GET_SECOND(self));

    if (!result || !HASTZINFO(self))
        return result;

    /* We need to append the UTC offset. */
    if (format_utcoffset(buffer, sizeof(buffer), ":", self->tzinfo,
                         (PyObject *)self) < 0) {
        Py_DECREF(result);
        return NULL;
    }
    PyUnicode_AppendAndDel(&result, PyUnicode_FromString(buffer));
    return result;
}

Here is the call graph for this function:

static PyObject* datetime_microsecond ( PyDateTime_DateTime self,
void unused 
) [static]

Definition at line 3992 of file _datetimemodule.c.

Here is the call graph for this function:

static PyObject* datetime_minute ( PyDateTime_DateTime self,
void unused 
) [static]

Definition at line 3980 of file _datetimemodule.c.

{
    return PyLong_FromLong(DATE_GET_MINUTE(self));
}

Here is the call graph for this function:

static PyObject* datetime_new ( PyTypeObject type,
PyObject args,
PyObject kw 
) [static]

Definition at line 4024 of file _datetimemodule.c.

{
    PyObject *self = NULL;
    PyObject *state;
    int year;
    int month;
    int day;
    int hour = 0;
    int minute = 0;
    int second = 0;
    int usecond = 0;
    PyObject *tzinfo = Py_None;

    /* Check for invocation from pickle with __getstate__ state */
    if (PyTuple_GET_SIZE(args) >= 1 &&
        PyTuple_GET_SIZE(args) <= 2 &&
        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
        PyBytes_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
        MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
    {
        PyDateTime_DateTime *me;
        char aware;

        if (PyTuple_GET_SIZE(args) == 2) {
            tzinfo = PyTuple_GET_ITEM(args, 1);
            if (check_tzinfo_subclass(tzinfo) < 0) {
                PyErr_SetString(PyExc_TypeError, "bad "
                    "tzinfo state arg");
                return NULL;
            }
        }
        aware = (char)(tzinfo != Py_None);
        me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware));
        if (me != NULL) {
            char *pdata = PyBytes_AS_STRING(state);

            memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE);
            me->hashcode = -1;
            me->hastzinfo = aware;
            if (aware) {
                Py_INCREF(tzinfo);
                me->tzinfo = tzinfo;
            }
        }
        return (PyObject *)me;
    }

    if (PyArg_ParseTupleAndKeywords(args, kw, "iii|iiiiO", datetime_kws,
                                    &year, &month, &day, &hour, &minute,
                                    &second, &usecond, &tzinfo)) {
        if (check_date_args(year, month, day) < 0)
            return NULL;
        if (check_time_args(hour, minute, second, usecond) < 0)
            return NULL;
        if (check_tzinfo_subclass(tzinfo) < 0)
            return NULL;
        self = new_datetime_ex(year, month, day,
                                hour, minute, second, usecond,
                                tzinfo, type);
    }
    return self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_now ( PyObject cls,
PyObject args,
PyObject kw 
) [static]

Definition at line 4181 of file _datetimemodule.c.

{
    PyObject *self;
    PyObject *tzinfo = Py_None;
    static char *keywords[] = {"tz", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:now", keywords,
                                      &tzinfo))
        return NULL;
    if (check_tzinfo_subclass(tzinfo) < 0)
        return NULL;

    self = datetime_best_possible(cls,
                                  tzinfo == Py_None ? localtime : gmtime,
                                  tzinfo);
    if (self != NULL && tzinfo != Py_None) {
        /* Convert UTC to tzinfo's zone. */
        PyObject *temp = self;
        self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
        Py_DECREF(temp);
    }
    return self;
}

Here is the call graph for this function:

static PyObject* datetime_reduce ( PyDateTime_DateTime self,
PyObject arg 
) [static]

Definition at line 4892 of file _datetimemodule.c.

{
    return Py_BuildValue("(ON)", Py_TYPE(self), datetime_getstate(self));
}

Here is the call graph for this function:

static PyObject* datetime_replace ( PyDateTime_DateTime self,
PyObject args,
PyObject kw 
) [static]

Definition at line 4692 of file _datetimemodule.c.

{
    PyObject *clone;
    PyObject *tuple;
    int y = GET_YEAR(self);
    int m = GET_MONTH(self);
    int d = GET_DAY(self);
    int hh = DATE_GET_HOUR(self);
    int mm = DATE_GET_MINUTE(self);
    int ss = DATE_GET_SECOND(self);
    int us = DATE_GET_MICROSECOND(self);
    PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;

    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iiiiiiiO:replace",
                                      datetime_kws,
                                      &y, &m, &d, &hh, &mm, &ss, &us,
                                      &tzinfo))
        return NULL;
    tuple = Py_BuildValue("iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo);
    if (tuple == NULL)
        return NULL;
    clone = datetime_new(Py_TYPE(self), tuple, NULL);
    Py_DECREF(tuple);
    return clone;
}

Here is the call graph for this function:

static PyObject* datetime_repr ( PyDateTime_DateTime self) [static]

Definition at line 4480 of file _datetimemodule.c.

{
    const char *type_name = Py_TYPE(self)->tp_name;
    PyObject *baserepr;

    if (DATE_GET_MICROSECOND(self)) {
        baserepr = PyUnicode_FromFormat(
                      "%s(%d, %d, %d, %d, %d, %d, %d)",
                      type_name,
                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
                      DATE_GET_SECOND(self),
                      DATE_GET_MICROSECOND(self));
    }
    else if (DATE_GET_SECOND(self)) {
        baserepr = PyUnicode_FromFormat(
                      "%s(%d, %d, %d, %d, %d, %d)",
                      type_name,
                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
                      DATE_GET_SECOND(self));
    }
    else {
        baserepr = PyUnicode_FromFormat(
                      "%s(%d, %d, %d, %d, %d)",
                      type_name,
                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
    }
    if (baserepr == NULL || ! HASTZINFO(self))
        return baserepr;
    return append_keyword_tzinfo(baserepr, self->tzinfo);
}

Here is the call graph for this function:

static PyObject* datetime_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 4569 of file _datetimemodule.c.

{
    PyObject *result = NULL;
    PyObject *offset1, *offset2;
    int diff;

    if (! PyDateTime_Check(other)) {
        if (PyDate_Check(other)) {
            /* Prevent invocation of date_richcompare.  We want to
               return NotImplemented here to give the other object
               a chance.  But since DateTime is a subclass of
               Date, if the other object is a Date, it would
               compute an ordering based on the date part alone,
               and we don't want that.  So force unequal or
               uncomparable here in that case. */
            if (op == Py_EQ)
                Py_RETURN_FALSE;
            if (op == Py_NE)
                Py_RETURN_TRUE;
            return cmperror(self, other);
        }
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) {
        diff = memcmp(((PyDateTime_DateTime *)self)->data,
                      ((PyDateTime_DateTime *)other)->data,
                      _PyDateTime_DATETIME_DATASIZE);
        return diff_to_bool(diff, op);
    }
    offset1 = datetime_utcoffset(self, NULL);
    if (offset1 == NULL)
        return NULL;
    offset2 = datetime_utcoffset(other, NULL);
    if (offset2 == NULL)
        goto done;
    /* If they're both naive, or both aware and have the same offsets,
     * we get off cheap.  Note that if they're both naive, offset1 ==
     * offset2 == Py_None at this point.
     */
    if ((offset1 == offset2) ||
        (PyDelta_Check(offset1) && PyDelta_Check(offset2) &&
         delta_cmp(offset1, offset2) == 0)) {
        diff = memcmp(((PyDateTime_DateTime *)self)->data,
                      ((PyDateTime_DateTime *)other)->data,
                      _PyDateTime_DATETIME_DATASIZE);
        result = diff_to_bool(diff, op);
    }
    else if (offset1 != Py_None && offset2 != Py_None) {
        PyDateTime_Delta *delta;

        assert(offset1 != offset2); /* else last "if" handled it */
        delta = (PyDateTime_Delta *)datetime_subtract((PyObject *)self,
                                                       other);
        if (delta == NULL)
            goto done;
        diff = GET_TD_DAYS(delta);
        if (diff == 0)
            diff = GET_TD_SECONDS(delta) |
                   GET_TD_MICROSECONDS(delta);
        Py_DECREF(delta);
        result = diff_to_bool(diff, op);
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "can't compare offset-naive and "
                        "offset-aware datetimes");
    }
 done:
    Py_DECREF(offset1);
    Py_XDECREF(offset2);
    return result;
}

Here is the call graph for this function:

static PyObject* datetime_second ( PyDateTime_DateTime self,
void unused 
) [static]

Definition at line 3986 of file _datetimemodule.c.

{
    return PyLong_FromLong(DATE_GET_SECOND(self));
}

Here is the call graph for this function:

static PyObject* datetime_str ( PyDateTime_DateTime self) [static]

Definition at line 4515 of file _datetimemodule.c.

{
    return PyObject_CallMethod((PyObject *)self, "isoformat", "(s)", " ");
}

Here is the call graph for this function:

static PyObject* datetime_strptime ( PyObject cls,
PyObject args 
) [static]

Definition at line 4257 of file _datetimemodule.c.

{
    static PyObject *module = NULL;
    const Py_UNICODE *string, *format;

    if (!PyArg_ParseTuple(args, "uu:strptime", &string, &format))
        return NULL;

    if (module == NULL) {
        module = PyImport_ImportModuleNoBlock("_strptime");
        if (module == NULL)
            return NULL;
    }
    return PyObject_CallMethod(module, "_strptime_datetime", "Ouu",
                               cls, string, format);
}

Here is the call graph for this function:

static PyObject* datetime_subtract ( PyObject left,
PyObject right 
) [static]

Definition at line 4392 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDateTime_Check(left)) {
        /* datetime - ??? */
        if (PyDateTime_Check(right)) {
            /* datetime - datetime */
            PyObject *offset1, *offset2, *offdiff = NULL;
            int delta_d, delta_s, delta_us;

            if (GET_DT_TZINFO(left) == GET_DT_TZINFO(right)) {
                offset2 = offset1 = Py_None;
                Py_INCREF(offset1);
                Py_INCREF(offset2);
            }
            else {
                offset1 = datetime_utcoffset(left, NULL);
                if (offset1 == NULL)
                    return NULL;
                offset2 = datetime_utcoffset(right, NULL);
                if (offset2 == NULL) {
                    Py_DECREF(offset1);
                    return NULL;
                }
                if ((offset1 != Py_None) != (offset2 != Py_None)) {
                    PyErr_SetString(PyExc_TypeError,
                                    "can't subtract offset-naive and "
                                    "offset-aware datetimes");
                    Py_DECREF(offset1);
                    Py_DECREF(offset2);
                    return NULL;
                }
            }
            if ((offset1 != offset2) &&
                delta_cmp(offset1, offset2) != 0) {
                offdiff = delta_subtract(offset1, offset2);
                if (offdiff == NULL) {
                    Py_DECREF(offset1);
                    Py_DECREF(offset2);
                    return NULL;
                }
            }
            Py_DECREF(offset1);
            Py_DECREF(offset2);
            delta_d = ymd_to_ord(GET_YEAR(left),
                                 GET_MONTH(left),
                                 GET_DAY(left)) -
                      ymd_to_ord(GET_YEAR(right),
                                 GET_MONTH(right),
                                 GET_DAY(right));
            /* These can't overflow, since the values are
             * normalized.  At most this gives the number of
             * seconds in one day.
             */
            delta_s = (DATE_GET_HOUR(left) -
                       DATE_GET_HOUR(right)) * 3600 +
                      (DATE_GET_MINUTE(left) -
                       DATE_GET_MINUTE(right)) * 60 +
                      (DATE_GET_SECOND(left) -
                       DATE_GET_SECOND(right));
            delta_us = DATE_GET_MICROSECOND(left) -
                       DATE_GET_MICROSECOND(right);
            result = new_delta(delta_d, delta_s, delta_us, 1);
            if (offdiff != NULL) {
                PyObject *temp = result;
                result = delta_subtract(result, offdiff);
                Py_DECREF(temp);
                Py_DECREF(offdiff);
            }
        }
        else if (PyDelta_Check(right)) {
            /* datetime - delta */
            result = add_datetime_timedelta(
                            (PyDateTime_DateTime *)left,
                            (PyDateTime_Delta *)right,
                            -1);
        }
    }

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_timetuple ( PyDateTime_DateTime self) [static]

Definition at line 4773 of file _datetimemodule.c.

{
    int dstflag = -1;

    if (HASTZINFO(self) && self->tzinfo != Py_None) {
        PyObject * dst;

        dst = call_dst(self->tzinfo, (PyObject *)self);
        if (dst == NULL)
            return NULL;

        if (dst != Py_None)
            dstflag = delta_bool((PyDateTime_Delta *)dst);
        Py_DECREF(dst);
    }
    return build_struct_time(GET_YEAR(self),
                             GET_MONTH(self),
                             GET_DAY(self),
                             DATE_GET_HOUR(self),
                             DATE_GET_MINUTE(self),
                             DATE_GET_SECOND(self),
                             dstflag);
}

Here is the call graph for this function:

static PyObject* datetime_tzinfo ( PyDateTime_DateTime self,
void unused 
) [static]

Definition at line 3998 of file _datetimemodule.c.

{
    PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
    Py_INCREF(result);
    return result;
}
static PyObject* datetime_tzname ( PyObject self,
PyObject unused 
) [static]

Definition at line 4332 of file _datetimemodule.c.

                                                  {
    return call_tzname(GET_DT_TZINFO(self), self);
}

Here is the call graph for this function:

static PyObject* datetime_utcfromtimestamp ( PyObject cls,
PyObject args 
) [static]

Definition at line 4244 of file _datetimemodule.c.

{
    double timestamp;
    PyObject *result = NULL;

    if (PyArg_ParseTuple(args, "d:utcfromtimestamp", &timestamp))
        result = datetime_from_timestamp(cls, gmtime, timestamp,
                                         Py_None);
    return result;
}

Here is the call graph for this function:

static PyObject* datetime_utcnow ( PyObject cls,
PyObject dummy 
) [static]

Definition at line 4209 of file _datetimemodule.c.

{
    return datetime_best_possible(cls, gmtime, Py_None);
}

Here is the call graph for this function:

static PyObject * datetime_utcoffset ( PyObject self,
PyObject unused 
) [static]

Definition at line 4322 of file _datetimemodule.c.

                                                     {
    return call_utcoffset(GET_DT_TZINFO(self), self);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* datetime_utctimetuple ( PyDateTime_DateTime self) [static]

Definition at line 4826 of file _datetimemodule.c.

{
    int y, m, d, hh, mm, ss;
    PyObject *tzinfo;
    PyDateTime_DateTime *utcself;

    tzinfo = GET_DT_TZINFO(self);
    if (tzinfo == Py_None) {
        utcself = self;
        Py_INCREF(utcself);
    }
    else {
        PyObject *offset;
        offset = call_utcoffset(tzinfo, (PyObject *)self);
        if (offset == NULL)
            return NULL;
        if (offset == Py_None) {
            Py_DECREF(offset);
            utcself = self;
            Py_INCREF(utcself);
        }
        else {
            utcself = (PyDateTime_DateTime *)add_datetime_timedelta(self,
                                                (PyDateTime_Delta *)offset, -1);
            Py_DECREF(offset);
            if (utcself == NULL)
                return NULL;
        }
    }
    y = GET_YEAR(utcself);
    m = GET_MONTH(utcself);
    d = GET_DAY(utcself);
    hh = DATE_GET_HOUR(utcself);
    mm = DATE_GET_MINUTE(utcself);
    ss = DATE_GET_SECOND(utcself);

    Py_DECREF(utcself);
    return build_struct_time(y, m, d, hh, mm, ss, 0);
}

Here is the call graph for this function:

static int days_before_month ( int  year,
int  month 
) [static]

Definition at line 222 of file _datetimemodule.c.

{
    int days;

    assert(month >= 1);
    assert(month <= 12);
    days = _days_before_month[month];
    if (month > 2 && is_leap(year))
        ++days;
    return days;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int days_before_year ( int  year) [static]

Definition at line 238 of file _datetimemodule.c.

{
    int y = year - 1;
    /* This is incorrect if year <= 0; we really want the floor
     * here.  But so long as MINYEAR is 1, the smallest year this
     * can see is 1.
     */
    assert (year >= 1);
    return y*365 + y/4 - y/100 + y/400;
}

Here is the caller graph for this function:

static int days_in_month ( int  year,
int  month 
) [static]

Definition at line 210 of file _datetimemodule.c.

{
    assert(month >= 1);
    assert(month <= 12);
    if (month == 2 && is_leap(year))
        return 29;
    else
        return _days_in_month[month];
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* delta_abs ( PyDateTime_Delta self) [static]

Definition at line 1782 of file _datetimemodule.c.

{
    PyObject *result;

    assert(GET_TD_MICROSECONDS(self) >= 0);
    assert(GET_TD_SECONDS(self) >= 0);

    if (GET_TD_DAYS(self) < 0)
        result = delta_negative(self);
    else
        result = delta_positive(self);

    return result;
}

Here is the call graph for this function:

static PyObject* delta_add ( PyObject left,
PyObject right 
) [static]

Definition at line 1739 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDelta_Check(left) && PyDelta_Check(right)) {
        /* delta + delta */
        /* The C-level additions can't overflow because of the
         * invariant bounds.
         */
        int days = GET_TD_DAYS(left) + GET_TD_DAYS(right);
        int seconds = GET_TD_SECONDS(left) + GET_TD_SECONDS(right);
        int microseconds = GET_TD_MICROSECONDS(left) +
                           GET_TD_MICROSECONDS(right);
        result = new_delta(days, seconds, microseconds, 1);
    }

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}
static int delta_bool ( PyDateTime_Delta self) [static]

Definition at line 2188 of file _datetimemodule.c.

{
    return (GET_TD_DAYS(self) != 0
        || GET_TD_SECONDS(self) != 0
        || GET_TD_MICROSECONDS(self) != 0);
}

Here is the caller graph for this function:

static int delta_cmp ( PyObject self,
PyObject other 
) [static]

Definition at line 1820 of file _datetimemodule.c.

{
    int diff = GET_TD_DAYS(self) - GET_TD_DAYS(other);
    if (diff == 0) {
        diff = GET_TD_SECONDS(self) - GET_TD_SECONDS(other);
        if (diff == 0)
            diff = GET_TD_MICROSECONDS(self) -
                GET_TD_MICROSECONDS(other);
    }
    return diff;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* delta_divide ( PyObject left,
PyObject right 
) [static]

Definition at line 1887 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDelta_Check(left)) {
        /* delta * ??? */
        if (PyLong_Check(right))
            result = divide_timedelta_int(
                            (PyDateTime_Delta *)left,
                            right);
        else if (PyDelta_Check(right))
            result = divide_timedelta_timedelta(
                            (PyDateTime_Delta *)left,
                            (PyDateTime_Delta *)right);
    }

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}

Here is the call graph for this function:

static PyObject* delta_divmod ( PyObject left,
PyObject right 
) [static]

Definition at line 1969 of file _datetimemodule.c.

{
    PyObject *pyus_left;
    PyObject *pyus_right;
    PyObject *divmod;
    PyObject *delta;
    PyObject *result;

    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
    if (pyus_left == NULL)
        return NULL;

    pyus_right = delta_to_microseconds((PyDateTime_Delta *)right);
    if (pyus_right == NULL) {
        Py_DECREF(pyus_left);
        return NULL;
    }

    divmod = PyNumber_Divmod(pyus_left, pyus_right);
    Py_DECREF(pyus_left);
    Py_DECREF(pyus_right);
    if (divmod == NULL)
        return NULL;

    assert(PyTuple_Size(divmod) == 2);
    delta = microseconds_to_delta(PyTuple_GET_ITEM(divmod, 1));
    if (delta == NULL) {
        Py_DECREF(divmod);
        return NULL;
    }
    result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
    Py_DECREF(delta);
    Py_DECREF(divmod);
    return result;
}

Here is the call graph for this function:

static PyObject * delta_getstate ( PyDateTime_Delta self) [static]

Definition at line 2248 of file _datetimemodule.c.

{
    return Py_BuildValue("iii", GET_TD_DAYS(self),
                                GET_TD_SECONDS(self),
                                GET_TD_MICROSECONDS(self));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_hash_t delta_hash ( PyDateTime_Delta self) [static]

Definition at line 1848 of file _datetimemodule.c.

{
    if (self->hashcode == -1) {
        PyObject *temp = delta_getstate(self);
        if (temp != NULL) {
            self->hashcode = PyObject_Hash(temp);
            Py_DECREF(temp);
        }
    }
    return self->hashcode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* delta_multiply ( PyObject left,
PyObject right 
) [static]

Definition at line 1861 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDelta_Check(left)) {
        /* delta * ??? */
        if (PyLong_Check(right))
            result = multiply_int_timedelta(right,
                            (PyDateTime_Delta *) left);
        else if (PyFloat_Check(right))
            result = multiply_float_timedelta(right,
                            (PyDateTime_Delta *) left);
    }
    else if (PyLong_Check(left))
        result = multiply_int_timedelta(left,
                        (PyDateTime_Delta *) right);
    else if (PyFloat_Check(left))
        result = multiply_float_timedelta(left,
                        (PyDateTime_Delta *) right);

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}

Here is the call graph for this function:

static PyObject * delta_negative ( PyDateTime_Delta self) [static]

Definition at line 1761 of file _datetimemodule.c.

{
    return new_delta(-GET_TD_DAYS(self),
                     -GET_TD_SECONDS(self),
                     -GET_TD_MICROSECONDS(self),
                     1);
}

Here is the caller graph for this function:

static PyObject* delta_new ( PyTypeObject type,
PyObject args,
PyObject kw 
) [static]

Definition at line 2101 of file _datetimemodule.c.

{
    PyObject *self = NULL;

    /* Argument objects. */
    PyObject *day = NULL;
    PyObject *second = NULL;
    PyObject *us = NULL;
    PyObject *ms = NULL;
    PyObject *minute = NULL;
    PyObject *hour = NULL;
    PyObject *week = NULL;

    PyObject *x = NULL;         /* running sum of microseconds */
    PyObject *y = NULL;         /* temp sum of microseconds */
    double leftover_us = 0.0;

    static char *keywords[] = {
        "days", "seconds", "microseconds", "milliseconds",
        "minutes", "hours", "weeks", NULL
    };

    if (PyArg_ParseTupleAndKeywords(args, kw, "|OOOOOOO:__new__",
                                    keywords,
                                    &day, &second, &us,
                                    &ms, &minute, &hour, &week) == 0)
        goto Done;

    x = PyLong_FromLong(0);
    if (x == NULL)
        goto Done;

#define CLEANUP         \
    Py_DECREF(x);       \
    x = y;              \
    if (x == NULL)      \
        goto Done

    if (us) {
        y = accum("microseconds", x, us, us_per_us, &leftover_us);
        CLEANUP;
    }
    if (ms) {
        y = accum("milliseconds", x, ms, us_per_ms, &leftover_us);
        CLEANUP;
    }
    if (second) {
        y = accum("seconds", x, second, us_per_second, &leftover_us);
        CLEANUP;
    }
    if (minute) {
        y = accum("minutes", x, minute, us_per_minute, &leftover_us);
        CLEANUP;
    }
    if (hour) {
        y = accum("hours", x, hour, us_per_hour, &leftover_us);
        CLEANUP;
    }
    if (day) {
        y = accum("days", x, day, us_per_day, &leftover_us);
        CLEANUP;
    }
    if (week) {
        y = accum("weeks", x, week, us_per_week, &leftover_us);
        CLEANUP;
    }
    if (leftover_us) {
        /* Round to nearest whole # of us, and add into x. */
        PyObject *temp = PyLong_FromLong(round_to_long(leftover_us));
        if (temp == NULL) {
            Py_DECREF(x);
            goto Done;
        }
        y = PyNumber_Add(x, temp);
        Py_DECREF(temp);
        CLEANUP;
    }

    self = microseconds_to_delta_ex(x, type);
    Py_DECREF(x);
Done:
    return self;

#undef CLEANUP
}

Here is the call graph for this function:

static PyObject* delta_positive ( PyDateTime_Delta self) [static]

Definition at line 1770 of file _datetimemodule.c.

{
    /* Could optimize this (by returning self) if this isn't a
     * subclass -- but who uses unary + ?  Approximately nobody.
     */
    return new_delta(GET_TD_DAYS(self),
                     GET_TD_SECONDS(self),
                     GET_TD_MICROSECONDS(self),
                     0);
}

Here is the caller graph for this function:

static PyObject* delta_reduce ( PyDateTime_Delta self) [static]

Definition at line 2280 of file _datetimemodule.c.

{
    return Py_BuildValue("ON", Py_TYPE(self), delta_getstate(self));
}

Here is the call graph for this function:

static PyObject* delta_remainder ( PyObject left,
PyObject right 
) [static]

Definition at line 1932 of file _datetimemodule.c.

{
    PyObject *pyus_left;
    PyObject *pyus_right;
    PyObject *pyus_remainder;
    PyObject *remainder;

    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
    if (pyus_left == NULL)
        return NULL;

    pyus_right = delta_to_microseconds((PyDateTime_Delta *)right);
    if (pyus_right == NULL) {
        Py_DECREF(pyus_left);
        return NULL;
    }

    pyus_remainder = PyNumber_Remainder(pyus_left, pyus_right);
    Py_DECREF(pyus_left);
    Py_DECREF(pyus_right);
    if (pyus_remainder == NULL)
        return NULL;

    remainder = microseconds_to_delta(pyus_remainder);
    Py_DECREF(pyus_remainder);
    if (remainder == NULL)
        return NULL;

    return remainder;
}

Here is the call graph for this function:

static PyObject* delta_repr ( PyDateTime_Delta self) [static]

Definition at line 2196 of file _datetimemodule.c.

{
    if (GET_TD_MICROSECONDS(self) != 0)
        return PyUnicode_FromFormat("%s(%d, %d, %d)",
                                    Py_TYPE(self)->tp_name,
                                    GET_TD_DAYS(self),
                                    GET_TD_SECONDS(self),
                                    GET_TD_MICROSECONDS(self));
    if (GET_TD_SECONDS(self) != 0)
        return PyUnicode_FromFormat("%s(%d, %d)",
                                    Py_TYPE(self)->tp_name,
                                    GET_TD_DAYS(self),
                                    GET_TD_SECONDS(self));

    return PyUnicode_FromFormat("%s(%d)",
                                Py_TYPE(self)->tp_name,
                                GET_TD_DAYS(self));
}
static PyObject* delta_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 1833 of file _datetimemodule.c.

{
    if (PyDelta_Check(other)) {
        int diff = delta_cmp(self, other);
        return diff_to_bool(diff, op);
    }
    else {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* delta_str ( PyDateTime_Delta self) [static]

Definition at line 2216 of file _datetimemodule.c.

{
    int us = GET_TD_MICROSECONDS(self);
    int seconds = GET_TD_SECONDS(self);
    int minutes = divmod(seconds, 60, &seconds);
    int hours = divmod(minutes, 60, &minutes);
    int days = GET_TD_DAYS(self);

    if (days) {
        if (us)
            return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d.%06d",
                                        days, (days == 1 || days == -1) ? "" : "s",
                                        hours, minutes, seconds, us);
        else
            return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d",
                                        days, (days == 1 || days == -1) ? "" : "s",
                                        hours, minutes, seconds);
    } else {
        if (us)
            return PyUnicode_FromFormat("%d:%02d:%02d.%06d",
                                        hours, minutes, seconds, us);
        else
            return PyUnicode_FromFormat("%d:%02d:%02d",
                                        hours, minutes, seconds);
    }

}

Here is the call graph for this function:

static PyObject* delta_subtract ( PyObject left,
PyObject right 
) [static]

Definition at line 1798 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDelta_Check(left) && PyDelta_Check(right)) {
        /* delta - delta */
        /* The C-level additions can't overflow because of the
         * invariant bounds.
         */
        int days = GET_TD_DAYS(left) - GET_TD_DAYS(right);
        int seconds = GET_TD_SECONDS(left) - GET_TD_SECONDS(right);
        int microseconds = GET_TD_MICROSECONDS(left) -
                           GET_TD_MICROSECONDS(right);
        result = new_delta(days, seconds, microseconds, 1);
    }

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}

Here is the caller graph for this function:

static PyObject* delta_to_microseconds ( PyDateTime_Delta self) [static]

Definition at line 1439 of file _datetimemodule.c.

{
    PyObject *x1 = NULL;
    PyObject *x2 = NULL;
    PyObject *x3 = NULL;
    PyObject *result = NULL;

    x1 = PyLong_FromLong(GET_TD_DAYS(self));
    if (x1 == NULL)
        goto Done;
    x2 = PyNumber_Multiply(x1, seconds_per_day);        /* days in seconds */
    if (x2 == NULL)
        goto Done;
    Py_DECREF(x1);
    x1 = NULL;

    /* x2 has days in seconds */
    x1 = PyLong_FromLong(GET_TD_SECONDS(self));         /* seconds */
    if (x1 == NULL)
        goto Done;
    x3 = PyNumber_Add(x1, x2);          /* days and seconds in seconds */
    if (x3 == NULL)
        goto Done;
    Py_DECREF(x1);
    Py_DECREF(x2);
    x1 = x2 = NULL;

    /* x3 has days+seconds in seconds */
    x1 = PyNumber_Multiply(x3, us_per_second);          /* us */
    if (x1 == NULL)
        goto Done;
    Py_DECREF(x3);
    x3 = NULL;

    /* x1 has days+seconds in us */
    x2 = PyLong_FromLong(GET_TD_MICROSECONDS(self));
    if (x2 == NULL)
        goto Done;
    result = PyNumber_Add(x1, x2);

Done:
    Py_XDECREF(x1);
    Py_XDECREF(x2);
    Py_XDECREF(x3);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* delta_total_seconds ( PyObject self) [static]

Definition at line 2256 of file _datetimemodule.c.

{
    PyObject *total_seconds;
    PyObject *total_microseconds;
    PyObject *one_million;

    total_microseconds = delta_to_microseconds((PyDateTime_Delta *)self);
    if (total_microseconds == NULL)
        return NULL;

    one_million = PyLong_FromLong(1000000L);
    if (one_million == NULL) {
        Py_DECREF(total_microseconds);
        return NULL;
    }

    total_seconds = PyNumber_TrueDivide(total_microseconds, one_million);

    Py_DECREF(total_microseconds);
    Py_DECREF(one_million);
    return total_seconds;
}

Here is the call graph for this function:

static PyObject* delta_truedivide ( PyObject left,
PyObject right 
) [static]

Definition at line 1909 of file _datetimemodule.c.

{
    PyObject *result = Py_NotImplemented;

    if (PyDelta_Check(left)) {
        if (PyDelta_Check(right))
            result = truedivide_timedelta_timedelta(
                            (PyDateTime_Delta *)left,
                            (PyDateTime_Delta *)right);
        else if (PyFloat_Check(right))
            result = truedivide_timedelta_float(
                            (PyDateTime_Delta *)left, right);
        else if (PyLong_Check(right))
            result = truedivide_timedelta_int(
                            (PyDateTime_Delta *)left, right);
    }

    if (result == Py_NotImplemented)
        Py_INCREF(result);
    return result;
}

Here is the call graph for this function:

static PyObject* diff_to_bool ( int  diff,
int  op 
) [static]

Definition at line 1379 of file _datetimemodule.c.

{
    PyObject *result;
    int istrue;

    switch (op) {
        case Py_EQ: istrue = diff == 0; break;
        case Py_NE: istrue = diff != 0; break;
        case Py_LE: istrue = diff <= 0; break;
        case Py_GE: istrue = diff >= 0; break;
        case Py_LT: istrue = diff < 0; break;
        case Py_GT: istrue = diff > 0; break;
        default:
            assert(! "op unknown");
            istrue = 0; /* To shut up compiler */
    }
    result = istrue ? Py_True : Py_False;
    Py_INCREF(result);
    return result;
}

Here is the caller graph for this function:

static PyObject* divide_nearest ( PyObject m,
PyObject n 
) [static]

Definition at line 162 of file _datetimemodule.c.

{
    PyObject *result;
    PyObject *temp;

    temp = _PyLong_DivmodNear(m, n);
    if (temp == NULL)
        return NULL;
    result = PyTuple_GET_ITEM(temp, 0);
    Py_INCREF(result);
    Py_DECREF(temp);

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* divide_timedelta_int ( PyDateTime_Delta delta,
PyObject intobj 
) [static]

Definition at line 1623 of file _datetimemodule.c.

{
    PyObject *pyus_in;
    PyObject *pyus_out;
    PyObject *result;

    pyus_in = delta_to_microseconds(delta);
    if (pyus_in == NULL)
        return NULL;

    pyus_out = PyNumber_FloorDivide(pyus_in, intobj);
    Py_DECREF(pyus_in);
    if (pyus_out == NULL)
        return NULL;

    result = microseconds_to_delta(pyus_out);
    Py_DECREF(pyus_out);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* divide_timedelta_timedelta ( PyDateTime_Delta left,
PyDateTime_Delta right 
) [static]

Definition at line 1644 of file _datetimemodule.c.

{
    PyObject *pyus_left;
    PyObject *pyus_right;
    PyObject *result;

    pyus_left = delta_to_microseconds(left);
    if (pyus_left == NULL)
        return NULL;

    pyus_right = delta_to_microseconds(right);
    if (pyus_right == NULL)     {
        Py_DECREF(pyus_left);
        return NULL;
    }

    result = PyNumber_FloorDivide(pyus_left, pyus_right);
    Py_DECREF(pyus_left);
    Py_DECREF(pyus_right);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int divmod ( int  x,
int  y,
int r 
) [static]

Definition at line 130 of file _datetimemodule.c.

{
    int quo;

    assert(y > 0);
    quo = x / y;
    *r = x - quo * y;
    if (*r < 0) {
        --quo;
        *r += y;
    }
    assert(0 <= *r && *r < y);
    return quo;
}
static PyObject* format_ctime ( PyDateTime_Date date,
int  hours,
int  minutes,
int  seconds 
) [static]

Definition at line 1004 of file _datetimemodule.c.

{
    static const char *DayNames[] = {
        "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
    };
    static const char *MonthNames[] = {
        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };

    int wday = weekday(GET_YEAR(date), GET_MONTH(date), GET_DAY(date));

    return PyUnicode_FromFormat("%s %s %2d %02d:%02d:%02d %04d",
                                DayNames[wday], MonthNames[GET_MONTH(date)-1],
                                GET_DAY(date), hours, minutes, seconds,
                                GET_YEAR(date));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int format_utcoffset ( char *  buf,
size_t  buflen,
const char *  sep,
PyObject tzinfo,
PyObject tzinfoarg 
) [static]

Definition at line 1035 of file _datetimemodule.c.

{
    PyObject *offset;
    int hours, minutes, seconds;
    char sign;

    assert(buflen >= 1);

    offset = call_utcoffset(tzinfo, tzinfoarg);
    if (offset == NULL)
        return -1;
    if (offset == Py_None) {
        Py_DECREF(offset);
        *buf = '\0';
        return 0;
    }
    /* Offset is normalized, so it is negative if days < 0 */
    if (GET_TD_DAYS(offset) < 0) {
        PyObject *temp = offset;
        sign = '-';
        offset = delta_negative((PyDateTime_Delta *)offset);
        Py_DECREF(temp);
        if (offset == NULL)
            return -1;
    }
    else {
        sign = '+';
    }
    /* Offset is not negative here. */
    seconds = GET_TD_SECONDS(offset);
    Py_DECREF(offset);
    minutes = divmod(seconds, 60, &seconds);
    hours = divmod(minutes, 60, &minutes);
    assert(seconds == 0);
    /* XXX ignore sub-minute data, curently not allowed. */
    PyOS_snprintf(buf, buflen, "%c%02d%s%02d", sign, hours, sep, minutes);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_hash_t generic_hash ( unsigned char *  data,
int  len 
) [static]

Definition at line 2782 of file _datetimemodule.c.

{
    register unsigned char *p;
    register Py_hash_t x;

    p = (unsigned char *) data;
    x = *p << 7;
    while (--len >= 0)
        x = (1000003*x) ^ *p++;
    x ^= len;
    if (x == -1)
        x = -2;

    return x;
}

Here is the caller graph for this function:

static PyObject* get_tzinfo_member ( PyObject self) [static]

Definition at line 850 of file _datetimemodule.c.

{
    PyObject *tzinfo = NULL;

    if (PyDateTime_Check(self) && HASTZINFO(self))
        tzinfo = ((PyDateTime_DateTime *)self)->tzinfo;
    else if (PyTime_Check(self) && HASTZINFO(self))
        tzinfo = ((PyDateTime_Time *)self)->tzinfo;

    return tzinfo;
}

Here is the caller graph for this function:

static int is_leap ( int  year) [static]

Definition at line 197 of file _datetimemodule.c.

{
    /* Cast year to unsigned.  The result is the same either way, but
     * C can generate faster code for unsigned mod than for signed
     * mod (especially for % 4 -- a good compiler should just grab
     * the last 2 bits when the LHS is unsigned).
     */
    const unsigned int ayear = (unsigned int)year;
    return ayear % 4 == 0 && (ayear % 100 != 0 || ayear % 400 == 0);
}

Here is the caller graph for this function:

static int iso_week1_monday ( int  year) [static]

Definition at line 358 of file _datetimemodule.c.

{
    int first_day = ymd_to_ord(year, 1, 1);     /* ord of 1/1 */
    /* 0 if 1/1 is a Monday, 1 if a Tue, etc. */
    int first_weekday = (first_day + 6) % 7;
    /* ordinal of closest Monday at or before 1/1 */
    int week1_monday  = first_day - first_weekday;

    if (first_weekday > 3)      /* if 1/1 was Fri, Sat, Sun */
        week1_monday += 7;
    return week1_monday;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* make_freplacement ( PyObject object) [static]

Definition at line 1119 of file _datetimemodule.c.

{
    char freplacement[64];
    if (PyTime_Check(object))
        sprintf(freplacement, "%06d", TIME_GET_MICROSECOND(object));
    else if (PyDateTime_Check(object))
        sprintf(freplacement, "%06d", DATE_GET_MICROSECOND(object));
    else
        sprintf(freplacement, "%06d", 0);

    return PyBytes_FromStringAndSize(freplacement, strlen(freplacement));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* make_Zreplacement ( PyObject object,
PyObject tzinfoarg 
) [static]

Definition at line 1077 of file _datetimemodule.c.

{
    PyObject *temp;
    PyObject *tzinfo = get_tzinfo_member(object);
    PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
    if (Zreplacement == NULL)
        return NULL;
    if (tzinfo == Py_None || tzinfo == NULL)
        return Zreplacement;

    assert(tzinfoarg != NULL);
    temp = call_tzname(tzinfo, tzinfoarg);
    if (temp == NULL)
        goto Error;
    if (temp == Py_None) {
        Py_DECREF(temp);
        return Zreplacement;
    }

    assert(PyUnicode_Check(temp));
    /* Since the tzname is getting stuffed into the
     * format, we have to double any % signs so that
     * strftime doesn't treat them as format codes.
     */
    Py_DECREF(Zreplacement);
    Zreplacement = PyObject_CallMethod(temp, "replace", "ss", "%", "%%");
    Py_DECREF(temp);
    if (Zreplacement == NULL)
        return NULL;
    if (!PyUnicode_Check(Zreplacement)) {
        PyErr_SetString(PyExc_TypeError,
                        "tzname.replace() did not return a string");
        goto Error;
    }
    return Zreplacement;

  Error:
    Py_DECREF(Zreplacement);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* microseconds_to_delta_ex ( PyObject pyus,
PyTypeObject type 
) [static]

Definition at line 1489 of file _datetimemodule.c.

{
    int us;
    int s;
    int d;
    long temp;

    PyObject *tuple = NULL;
    PyObject *num = NULL;
    PyObject *result = NULL;

    tuple = PyNumber_Divmod(pyus, us_per_second);
    if (tuple == NULL)
        goto Done;

    num = PyTuple_GetItem(tuple, 1);            /* us */
    if (num == NULL)
        goto Done;
    temp = PyLong_AsLong(num);
    num = NULL;
    if (temp == -1 && PyErr_Occurred())
        goto Done;
    assert(0 <= temp && temp < 1000000);
    us = (int)temp;
    if (us < 0) {
        /* The divisor was positive, so this must be an error. */
        assert(PyErr_Occurred());
        goto Done;
    }

    num = PyTuple_GetItem(tuple, 0);            /* leftover seconds */
    if (num == NULL)
        goto Done;
    Py_INCREF(num);
    Py_DECREF(tuple);

    tuple = PyNumber_Divmod(num, seconds_per_day);
    if (tuple == NULL)
        goto Done;
    Py_DECREF(num);

    num = PyTuple_GetItem(tuple, 1);            /* seconds */
    if (num == NULL)
        goto Done;
    temp = PyLong_AsLong(num);
    num = NULL;
    if (temp == -1 && PyErr_Occurred())
        goto Done;
    assert(0 <= temp && temp < 24*3600);
    s = (int)temp;

    if (s < 0) {
        /* The divisor was positive, so this must be an error. */
        assert(PyErr_Occurred());
        goto Done;
    }

    num = PyTuple_GetItem(tuple, 0);            /* leftover days */
    if (num == NULL)
        goto Done;
    Py_INCREF(num);
    temp = PyLong_AsLong(num);
    if (temp == -1 && PyErr_Occurred())
        goto Done;
    d = (int)temp;
    if ((long)d != temp) {
        PyErr_SetString(PyExc_OverflowError, "normalized days too "
                        "large to fit in a C int");
        goto Done;
    }
    result = new_delta_ex(d, s, us, 0, type);

Done:
    Py_XDECREF(tuple);
    Py_XDECREF(num);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* multiply_float_timedelta ( PyObject floatobj,
PyDateTime_Delta delta 
) [static]

Definition at line 1592 of file _datetimemodule.c.

{
    PyObject *result = NULL;
    PyObject *pyus_in = NULL, *temp, *pyus_out;
    PyObject *ratio = NULL;

    pyus_in = delta_to_microseconds(delta);
    if (pyus_in == NULL)
        return NULL;
    ratio = PyObject_CallMethod(floatobj, "as_integer_ratio", NULL);
    if (ratio == NULL)
        goto error;
    temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0));
    Py_DECREF(pyus_in);
    pyus_in = NULL;
    if (temp == NULL)
        goto error;
    pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, 1));
    Py_DECREF(temp);
    if (pyus_out == NULL)
        goto error;
    result = microseconds_to_delta(pyus_out);
    Py_DECREF(pyus_out);
 error:
    Py_XDECREF(pyus_in);
    Py_XDECREF(ratio);

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* multiply_int_timedelta ( PyObject intobj,
PyDateTime_Delta delta 
) [static]

Definition at line 1571 of file _datetimemodule.c.

{
    PyObject *pyus_in;
    PyObject *pyus_out;
    PyObject *result;

    pyus_in = delta_to_microseconds(delta);
    if (pyus_in == NULL)
        return NULL;

    pyus_out = PyNumber_Multiply(pyus_in, intobj);
    Py_DECREF(pyus_in);
    if (pyus_out == NULL)
        return NULL;

    result = microseconds_to_delta(pyus_out);
    Py_DECREF(pyus_out);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* new_date_ex ( int  year,
int  month,
int  day,
PyTypeObject type 
) [static]

Definition at line 660 of file _datetimemodule.c.

{
    PyDateTime_Date *self;

    self = (PyDateTime_Date *) (type->tp_alloc(type, 0));
    if (self != NULL)
        set_date_fields(self, year, month, day);
    return (PyObject *) self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* new_datetime_ex ( int  year,
int  month,
int  day,
int  hour,
int  minute,
int  second,
int  usecond,
PyObject tzinfo,
PyTypeObject type 
) [static]

Definition at line 675 of file _datetimemodule.c.

{
    PyDateTime_DateTime *self;
    char aware = tzinfo != Py_None;

    self = (PyDateTime_DateTime *) (type->tp_alloc(type, aware));
    if (self != NULL) {
        self->hastzinfo = aware;
        set_date_fields((PyDateTime_Date *)self, year, month, day);
        DATE_SET_HOUR(self, hour);
        DATE_SET_MINUTE(self, minute);
        DATE_SET_SECOND(self, second);
        DATE_SET_MICROSECOND(self, usecond);
        if (aware) {
            Py_INCREF(tzinfo);
            self->tzinfo = tzinfo;
        }
    }
    return (PyObject *)self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* new_delta_ex ( int  days,
int  seconds,
int  microseconds,
int  normalize,
PyTypeObject type 
) [static]

Definition at line 735 of file _datetimemodule.c.

{
    PyDateTime_Delta *self;

    if (normalize)
        normalize_d_s_us(&days, &seconds, &microseconds);
    assert(0 <= seconds && seconds < 24*3600);
    assert(0 <= microseconds && microseconds < 1000000);

    if (check_delta_day_range(days) < 0)
        return NULL;

    self = (PyDateTime_Delta *) (type->tp_alloc(type, 0));
    if (self != NULL) {
        self->hashcode = -1;
        SET_TD_DAYS(self, days);
        SET_TD_SECONDS(self, seconds);
        SET_TD_MICROSECONDS(self, microseconds);
    }
    return (PyObject *) self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* new_time_ex ( int  hour,
int  minute,
int  second,
int  usecond,
PyObject tzinfo,
PyTypeObject type 
) [static]

Definition at line 703 of file _datetimemodule.c.

{
    PyDateTime_Time *self;
    char aware = tzinfo != Py_None;

    self = (PyDateTime_Time *) (type->tp_alloc(type, aware));
    if (self != NULL) {
        self->hastzinfo = aware;
        self->hashcode = -1;
        TIME_SET_HOUR(self, hour);
        TIME_SET_MINUTE(self, minute);
        TIME_SET_SECOND(self, second);
        TIME_SET_MICROSECOND(self, usecond);
        if (aware) {
            Py_INCREF(tzinfo);
            self->tzinfo = tzinfo;
        }
    }
    return (PyObject *)self;
}

Here is the caller graph for this function:

static PyObject* new_timezone ( PyObject offset,
PyObject name 
) [static]

Definition at line 800 of file _datetimemodule.c.

{
    assert(offset != NULL);
    assert(PyDelta_Check(offset));
    assert(name == NULL || PyUnicode_Check(name));

    if (name == NULL && delta_bool((PyDateTime_Delta *)offset) == 0) {
        Py_INCREF(PyDateTime_TimeZone_UTC);
        return PyDateTime_TimeZone_UTC;
    }
    if (GET_TD_MICROSECONDS(offset) != 0 || GET_TD_SECONDS(offset) % 60 != 0) {
        PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
                     " representing a whole number of minutes");
        return NULL;
    }
    if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) ||
        GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) {
        PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
                     " strictly between -timedelta(hours=24) and"
                     " timedelta(hours=24).");
        return NULL;
    }

    return create_timezone(offset, name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void normalize_d_s_us ( int d,
int s,
int us 
) [static]

Definition at line 474 of file _datetimemodule.c.

{
    if (*us < 0 || *us >= 1000000) {
        normalize_pair(s, us, 1000000);
        /* |s| can't be bigger than about
         * |original s| + |original us|/1000000 now.
         */

    }
    if (*s < 0 || *s >= 24*3600) {
        normalize_pair(d, s, 24*3600);
        /* |d| can't be bigger than about
         * |original d| +
         * (|original s| + |original us|/1000000) / (24*3600) now.
         */
    }
    assert(0 <= *s && *s < 24*3600);
    assert(0 <= *us && *us < 1000000);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int normalize_date ( int year,
int month,
int day 
) [static]

Definition at line 568 of file _datetimemodule.c.

{
    return normalize_y_m_d(year, month, day);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int normalize_datetime ( int year,
int month,
int day,
int hour,
int minute,
int second,
int microsecond 
) [static]

Definition at line 577 of file _datetimemodule.c.

{
    normalize_pair(second, microsecond, 1000000);
    normalize_pair(minute, second, 60);
    normalize_pair(hour, minute, 60);
    normalize_pair(day, hour, 24);
    return normalize_date(year, month, day);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void normalize_pair ( int hi,
int lo,
int  factor 
) [static]

Definition at line 454 of file _datetimemodule.c.

{
    assert(factor > 0);
    assert(lo != hi);
    if (*lo < 0 || *lo >= factor) {
        const int num_hi = divmod(*lo, factor, lo);
        const int new_hi = *hi + num_hi;
        assert(! SIGNED_ADD_OVERFLOWED(new_hi, *hi, num_hi));
        *hi = new_hi;
    }
    assert(0 <= *lo && *lo < factor);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int normalize_y_m_d ( int y,
int m,
int d 
) [static]

Definition at line 501 of file _datetimemodule.c.

{
    int dim;            /* # of days in month */

    /* In actual use, m is always the month component extracted from a
     * date/datetime object.  Therefore it is always in [1, 12] range.
     */

    assert(1 <= *m && *m <= 12);

    /* Now only day can be out of bounds (year may also be out of bounds
     * for a datetime object, but we don't care about that here).
     * If day is out of bounds, what to do is arguable, but at least the
     * method here is principled and explainable.
     */
    dim = days_in_month(*y, *m);
    if (*d < 1 || *d > dim) {
        /* Move day-1 days from the first of the month.  First try to
         * get off cheap if we're only one day out of range
         * (adjustments for timezone alone can't be worse than that).
         */
        if (*d == 0) {
            --*m;
            if (*m > 0)
                *d = days_in_month(*y, *m);
            else {
                --*y;
                *m = 12;
                *d = 31;
            }
        }
        else if (*d == dim + 1) {
            /* move forward a day */
            ++*m;
            *d = 1;
            if (*m > 12) {
                *m = 1;
                ++*y;
            }
        }
        else {
            int ordinal = ymd_to_ord(*y, *m, 1) +
                                      *d - 1;
            if (ordinal < 1 || ordinal > MAXORDINAL) {
                goto error;
            } else {
                ord_to_ymd(ordinal, y, m, d);
                return 0;
            }
        }
    }
    assert(*m > 0);
    assert(*d > 0);
    if (MINYEAR <= *y && *y <= MAXYEAR)
        return 0;
 error:
    PyErr_SetString(PyExc_OverflowError,
            "date value out of range");
    return -1;

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ord_to_ymd ( int  ordinal,
int year,
int month,
int day 
) [static]

Definition at line 258 of file _datetimemodule.c.

{
    int n, n1, n4, n100, n400, leapyear, preceding;

    /* ordinal is a 1-based index, starting at 1-Jan-1.  The pattern of
     * leap years repeats exactly every 400 years.  The basic strategy is
     * to find the closest 400-year boundary at or before ordinal, then
     * work with the offset from that boundary to ordinal.  Life is much
     * clearer if we subtract 1 from ordinal first -- then the values
     * of ordinal at 400-year boundaries are exactly those divisible
     * by DI400Y:
     *
     *    D  M   Y            n              n-1
     *    -- --- ----        ----------     ----------------
     *    31 Dec -400        -DI400Y       -DI400Y -1
     *     1 Jan -399         -DI400Y +1   -DI400Y      400-year boundary
     *    ...
     *    30 Dec  000        -1             -2
     *    31 Dec  000         0             -1
     *     1 Jan  001         1              0          400-year boundary
     *     2 Jan  001         2              1
     *     3 Jan  001         3              2
     *    ...
     *    31 Dec  400         DI400Y        DI400Y -1
     *     1 Jan  401         DI400Y +1     DI400Y      400-year boundary
     */
    assert(ordinal >= 1);
    --ordinal;
    n400 = ordinal / DI400Y;
    n = ordinal % DI400Y;
    *year = n400 * 400 + 1;

    /* Now n is the (non-negative) offset, in days, from January 1 of
     * year, to the desired date.  Now compute how many 100-year cycles
     * precede n.
     * Note that it's possible for n100 to equal 4!  In that case 4 full
     * 100-year cycles precede the desired day, which implies the
     * desired day is December 31 at the end of a 400-year cycle.
     */
    n100 = n / DI100Y;
    n = n % DI100Y;

    /* Now compute how many 4-year cycles precede it. */
    n4 = n / DI4Y;
    n = n % DI4Y;

    /* And now how many single years.  Again n1 can be 4, and again
     * meaning that the desired day is December 31 at the end of the
     * 4-year cycle.
     */
    n1 = n / 365;
    n = n % 365;

    *year += n100 * 100 + n4 * 4 + n1;
    if (n1 == 4 || n100 == 4) {
        assert(n == 0);
        *year -= 1;
        *month = 12;
        *day = 31;
        return;
    }

    /* Now the year is correct, and n is the offset from January 1.  We
     * find the month via an estimate that's either exact or one too
     * large.
     */
    leapyear = n1 == 3 && (n4 != 24 || n100 == 3);
    assert(leapyear == is_leap(*year));
    *month = (n + 50) >> 5;
    preceding = (_days_before_month[*month] + (*month > 2 && leapyear));
    if (preceding > n) {
        /* estimate is too large */
        *month -= 1;
        preceding -= days_in_month(*year, *month);
    }
    n -= preceding;
    assert(0 <= n);
    assert(n < days_in_month(*year, *month));

    *day = n + 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* py_time_second ( PyDateTime_Time self,
void unused 
) [static]

Definition at line 3462 of file _datetimemodule.c.

{
    return PyLong_FromLong(TIME_GET_SECOND(self));
}

Here is the call graph for this function:

Definition at line 5075 of file _datetimemodule.c.

{
    PyObject *m;        /* a module object */
    PyObject *d;        /* its dict */
    PyObject *x;
    PyObject *delta;

    m = PyModule_Create(&datetimemodule);
    if (m == NULL)
        return NULL;

    if (PyType_Ready(&PyDateTime_DateType) < 0)
        return NULL;
    if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
        return NULL;
    if (PyType_Ready(&PyDateTime_DeltaType) < 0)
        return NULL;
    if (PyType_Ready(&PyDateTime_TimeType) < 0)
        return NULL;
    if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
        return NULL;
    if (PyType_Ready(&PyDateTime_TimeZoneType) < 0)
        return NULL;

    /* timedelta values */
    d = PyDateTime_DeltaType.tp_dict;

    x = new_delta(0, 0, 1, 0);
    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
        return NULL;
    Py_DECREF(x);

    /* date values */
    d = PyDateTime_DateType.tp_dict;

    x = new_date(1, 1, 1);
    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_date(MAXYEAR, 12, 31);
    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_delta(1, 0, 0, 0);
    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
        return NULL;
    Py_DECREF(x);

    /* time values */
    d = PyDateTime_TimeType.tp_dict;

    x = new_time(0, 0, 0, 0, Py_None);
    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_time(23, 59, 59, 999999, Py_None);
    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_delta(0, 0, 1, 0);
    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
        return NULL;
    Py_DECREF(x);

    /* datetime values */
    d = PyDateTime_DateTimeType.tp_dict;

    x = new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None);
    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, Py_None);
    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
        return NULL;
    Py_DECREF(x);

    x = new_delta(0, 0, 1, 0);
    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
        return NULL;
    Py_DECREF(x);

    /* timezone values */
    d = PyDateTime_TimeZoneType.tp_dict;

    delta = new_delta(0, 0, 0, 0);
    if (delta == NULL)
        return NULL;
    x = create_timezone(delta, NULL);
    Py_DECREF(delta);
    if (x == NULL || PyDict_SetItemString(d, "utc", x) < 0)
        return NULL;
    PyDateTime_TimeZone_UTC = x;

    delta = new_delta(-1, 60, 0, 1); /* -23:59 */
    if (delta == NULL)
        return NULL;
    x = create_timezone(delta, NULL);
    Py_DECREF(delta);
    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
        return NULL;
    Py_DECREF(x);

    delta = new_delta(0, (23 * 60 + 59) * 60, 0, 0); /* +23:59 */
    if (delta == NULL)
        return NULL;
    x = create_timezone(delta, NULL);
    Py_DECREF(delta);
    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
        return NULL;
    Py_DECREF(x);

    /* module initialization */
    PyModule_AddIntConstant(m, "MINYEAR", MINYEAR);
    PyModule_AddIntConstant(m, "MAXYEAR", MAXYEAR);

    Py_INCREF(&PyDateTime_DateType);
    PyModule_AddObject(m, "date", (PyObject *) &PyDateTime_DateType);

    Py_INCREF(&PyDateTime_DateTimeType);
    PyModule_AddObject(m, "datetime",
                       (PyObject *)&PyDateTime_DateTimeType);

    Py_INCREF(&PyDateTime_TimeType);
    PyModule_AddObject(m, "time", (PyObject *) &PyDateTime_TimeType);

    Py_INCREF(&PyDateTime_DeltaType);
    PyModule_AddObject(m, "timedelta", (PyObject *) &PyDateTime_DeltaType);

    Py_INCREF(&PyDateTime_TZInfoType);
    PyModule_AddObject(m, "tzinfo", (PyObject *) &PyDateTime_TZInfoType);

    Py_INCREF(&PyDateTime_TimeZoneType);
    PyModule_AddObject(m, "timezone", (PyObject *) &PyDateTime_TimeZoneType);

    x = PyCapsule_New(&CAPI, PyDateTime_CAPSULE_NAME, NULL);
    if (x == NULL)
        return NULL;
    PyModule_AddObject(m, "datetime_CAPI", x);

    /* A 4-year cycle has an extra leap day over what we'd get from
     * pasting together 4 single years.
     */
    assert(DI4Y == 4 * 365 + 1);
    assert(DI4Y == days_before_year(4+1));

    /* Similarly, a 400-year cycle has an extra leap day over what we'd
     * get from pasting together 4 100-year cycles.
     */
    assert(DI400Y == 4 * DI100Y + 1);
    assert(DI400Y == days_before_year(400+1));

    /* OTOH, a 100-year cycle has one fewer leap day than we'd get from
     * pasting together 25 4-year cycles.
     */
    assert(DI100Y == 25 * DI4Y - 1);
    assert(DI100Y == days_before_year(100+1));

    us_per_us = PyLong_FromLong(1);
    us_per_ms = PyLong_FromLong(1000);
    us_per_second = PyLong_FromLong(1000000);
    us_per_minute = PyLong_FromLong(60000000);
    seconds_per_day = PyLong_FromLong(24 * 3600);
    if (us_per_us == NULL || us_per_ms == NULL || us_per_second == NULL ||
        us_per_minute == NULL || seconds_per_day == NULL)
        return NULL;

    /* The rest are too big for 32-bit ints, but even
     * us_per_week fits in 40 bits, so doubles should be exact.
     */
    us_per_hour = PyLong_FromDouble(3600000000.0);
    us_per_day = PyLong_FromDouble(86400000000.0);
    us_per_week = PyLong_FromDouble(604800000000.0);
    if (us_per_hour == NULL || us_per_day == NULL || us_per_week == NULL)
        return NULL;
    return m;
}

Here is the call graph for this function:

static long round_to_long ( double  x) [static]

Definition at line 149 of file _datetimemodule.c.

{
    if (x >= 0.0)
        x = floor(x + 0.5);
    else
        x = ceil(x - 0.5);
    return (long)x;
}

Here is the caller graph for this function:

static void set_date_fields ( PyDateTime_Date self,
int  y,
int  m,
int  d 
) [static]

Definition at line 646 of file _datetimemodule.c.

{
    self->hashcode = -1;
    SET_YEAR(self, y);
    SET_MONTH(self, m);
    SET_DAY(self, d);
}

Here is the caller graph for this function:

static PyObject* time_alloc ( PyTypeObject type,
Py_ssize_t  aware 
) [static]

Definition at line 610 of file _datetimemodule.c.

{
    PyObject *self;

    self = (PyObject *)
        PyObject_MALLOC(aware ?
                        sizeof(PyDateTime_Time) :
                sizeof(_PyDateTime_BaseTime));
    if (self == NULL)
        return (PyObject *)PyErr_NoMemory();
    PyObject_INIT(self, type);
    return self;
}

Here is the call graph for this function:

static int time_bool ( PyObject self) [static]

Definition at line 3821 of file _datetimemodule.c.

{
    PyObject *offset, *tzinfo;
    int offsecs = 0;

    if (TIME_GET_SECOND(self) || TIME_GET_MICROSECOND(self)) {
        /* Since utcoffset is in whole minutes, nothing can
         * alter the conclusion that this is nonzero.
         */
        return 1;
    }
    tzinfo = GET_TIME_TZINFO(self);
    if (tzinfo != Py_None) {
        offset = call_utcoffset(tzinfo, Py_None);
        if (offset == NULL)
            return -1;
        offsecs = GET_TD_DAYS(offset)*86400 + GET_TD_SECONDS(offset);
        Py_DECREF(offset);
    }
    return (TIME_GET_MINUTE(self)*60 - offsecs + TIME_GET_HOUR(self)*3600) != 0;
}

Here is the call graph for this function:

static void time_dealloc ( PyDateTime_Time self) [static]

Definition at line 3560 of file _datetimemodule.c.

{
    if (HASTZINFO(self)) {
        Py_XDECREF(self->tzinfo);
    }
    Py_TYPE(self)->tp_free((PyObject *)self);
}
static PyObject* time_dst ( PyObject self,
PyObject unused 
) [static]

Definition at line 3579 of file _datetimemodule.c.

                                           {
    return call_dst(GET_TIME_TZINFO(self), Py_None);
}

Here is the call graph for this function:

static PyObject* time_getstate ( PyDateTime_Time self) [static]

Definition at line 3851 of file _datetimemodule.c.

{
    PyObject *basestate;
    PyObject *result = NULL;

    basestate =  PyBytes_FromStringAndSize((char *)self->data,
                                            _PyDateTime_TIME_DATASIZE);
    if (basestate != NULL) {
        if (! HASTZINFO(self) || self->tzinfo == Py_None)
            result = PyTuple_Pack(1, basestate);
        else
            result = PyTuple_Pack(2, basestate, self->tzinfo);
        Py_DECREF(basestate);
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_hash_t time_hash ( PyDateTime_Time self) [static]

Definition at line 3756 of file _datetimemodule.c.

{
    if (self->hashcode == -1) {
        PyObject *offset;

        offset = time_utcoffset((PyObject *)self, NULL);

        if (offset == NULL)
            return -1;

        /* Reduce this to a hash of another object. */
        if (offset == Py_None)
            self->hashcode = generic_hash(
                (unsigned char *)self->data, _PyDateTime_TIME_DATASIZE);
        else {
            PyObject *temp1, *temp2;
            int seconds, microseconds;
            assert(HASTZINFO(self));
            seconds = TIME_GET_HOUR(self) * 3600 +
                      TIME_GET_MINUTE(self) * 60 +
                      TIME_GET_SECOND(self);
            microseconds = TIME_GET_MICROSECOND(self);
            temp1 = new_delta(0, seconds, microseconds, 1);
            if (temp1 == NULL) {
                Py_DECREF(offset);
                return -1;
            }
            temp2 = delta_subtract(temp1, offset);
            Py_DECREF(temp1);
            if (temp2 == NULL) {
                Py_DECREF(offset);
                return -1;
            }
            self->hashcode = PyObject_Hash(temp2);
            Py_DECREF(temp2);
        }
        Py_DECREF(offset);
    }
    return self->hashcode;
}

Here is the call graph for this function:

static PyObject* time_hour ( PyDateTime_Time self,
void unused 
) [static]

Definition at line 3449 of file _datetimemodule.c.

{
    return PyLong_FromLong(TIME_GET_HOUR(self));
}

Here is the call graph for this function:

static PyObject* time_isoformat ( PyDateTime_Time self,
PyObject unused 
) [static]

Definition at line 3622 of file _datetimemodule.c.

{
    char buf[100];
    PyObject *result;
    int us = TIME_GET_MICROSECOND(self);;

    if (us)
        result = PyUnicode_FromFormat("%02d:%02d:%02d.%06d",
                                      TIME_GET_HOUR(self),
                                      TIME_GET_MINUTE(self),
                                      TIME_GET_SECOND(self),
                                      us);
    else
        result = PyUnicode_FromFormat("%02d:%02d:%02d",
                                      TIME_GET_HOUR(self),
                                      TIME_GET_MINUTE(self),
                                      TIME_GET_SECOND(self));

    if (result == NULL || !HASTZINFO(self) || self->tzinfo == Py_None)
        return result;

    /* We need to append the UTC offset. */
    if (format_utcoffset(buf, sizeof(buf), ":", self->tzinfo,
                         Py_None) < 0) {
        Py_DECREF(result);
        return NULL;
    }
    PyUnicode_AppendAndDel(&result, PyUnicode_FromString(buf));
    return result;
}

Here is the call graph for this function:

static PyObject* time_microsecond ( PyDateTime_Time self,
void unused 
) [static]

Definition at line 3468 of file _datetimemodule.c.

Here is the call graph for this function:

static PyObject* time_minute ( PyDateTime_Time self,
void unused 
) [static]

Definition at line 3455 of file _datetimemodule.c.

{
    return PyLong_FromLong(TIME_GET_MINUTE(self));
}

Here is the call graph for this function:

static PyObject* time_new ( PyTypeObject type,
PyObject args,
PyObject kw 
) [static]

Definition at line 3498 of file _datetimemodule.c.

{
    PyObject *self = NULL;
    PyObject *state;
    int hour = 0;
    int minute = 0;
    int second = 0;
    int usecond = 0;
    PyObject *tzinfo = Py_None;

    /* Check for invocation from pickle with __getstate__ state */
    if (PyTuple_GET_SIZE(args) >= 1 &&
        PyTuple_GET_SIZE(args) <= 2 &&
        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
        PyBytes_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
        ((unsigned char) (PyBytes_AS_STRING(state)[0])) < 24)
    {
        PyDateTime_Time *me;
        char aware;

        if (PyTuple_GET_SIZE(args) == 2) {
            tzinfo = PyTuple_GET_ITEM(args, 1);
            if (check_tzinfo_subclass(tzinfo) < 0) {
                PyErr_SetString(PyExc_TypeError, "bad "
                    "tzinfo state arg");
                return NULL;
            }
        }
        aware = (char)(tzinfo != Py_None);
        me = (PyDateTime_Time *) (type->tp_alloc(type, aware));
        if (me != NULL) {
            char *pdata = PyBytes_AS_STRING(state);

            memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE);
            me->hashcode = -1;
            me->hastzinfo = aware;
            if (aware) {
                Py_INCREF(tzinfo);
                me->tzinfo = tzinfo;
            }
        }
        return (PyObject *)me;
    }

    if (PyArg_ParseTupleAndKeywords(args, kw, "|iiiiO", time_kws,
                                    &hour, &minute, &second, &usecond,
                                    &tzinfo)) {
        if (check_time_args(hour, minute, second, usecond) < 0)
            return NULL;
        if (check_tzinfo_subclass(tzinfo) < 0)
            return NULL;
        self = new_time_ex(hour, minute, second, usecond, tzinfo,
                           type);
    }
    return self;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* time_reduce ( PyDateTime_Time self,
PyObject arg 
) [static]

Definition at line 3869 of file _datetimemodule.c.

{
    return Py_BuildValue("(ON)", Py_TYPE(self), time_getstate(self));
}

Here is the call graph for this function:

static PyObject* time_replace ( PyDateTime_Time self,
PyObject args,
PyObject kw 
) [static]

Definition at line 3798 of file _datetimemodule.c.

{
    PyObject *clone;
    PyObject *tuple;
    int hh = TIME_GET_HOUR(self);
    int mm = TIME_GET_MINUTE(self);
    int ss = TIME_GET_SECOND(self);
    int us = TIME_GET_MICROSECOND(self);
    PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;

    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iiiiO:replace",
                                      time_kws,
                                      &hh, &mm, &ss, &us, &tzinfo))
        return NULL;
    tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
    if (tuple == NULL)
        return NULL;
    clone = time_new(Py_TYPE(self), tuple, NULL);
    Py_DECREF(tuple);
    return clone;
}

Here is the call graph for this function:

static PyObject* time_repr ( PyDateTime_Time self) [static]

Definition at line 3593 of file _datetimemodule.c.

{
    const char *type_name = Py_TYPE(self)->tp_name;
    int h = TIME_GET_HOUR(self);
    int m = TIME_GET_MINUTE(self);
    int s = TIME_GET_SECOND(self);
    int us = TIME_GET_MICROSECOND(self);
    PyObject *result = NULL;

    if (us)
        result = PyUnicode_FromFormat("%s(%d, %d, %d, %d)",
                                      type_name, h, m, s, us);
    else if (s)
        result = PyUnicode_FromFormat("%s(%d, %d, %d)",
                                      type_name, h, m, s);
    else
        result = PyUnicode_FromFormat("%s(%d, %d)", type_name, h, m);
    if (result != NULL && HASTZINFO(self))
        result = append_keyword_tzinfo(result, self->tzinfo);
    return result;
}

Here is the call graph for this function:

static PyObject* time_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 3689 of file _datetimemodule.c.

{
    PyObject *result = NULL;
    PyObject *offset1, *offset2;
    int diff;

    if (! PyTime_Check(other)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) {
        diff = memcmp(((PyDateTime_Time *)self)->data,
                      ((PyDateTime_Time *)other)->data,
                      _PyDateTime_TIME_DATASIZE);
        return diff_to_bool(diff, op);
    }
    offset1 = time_utcoffset(self, NULL);
    if (offset1 == NULL)
        return NULL;
    offset2 = time_utcoffset(other, NULL);
    if (offset2 == NULL)
        goto done;
    /* If they're both naive, or both aware and have the same offsets,
     * we get off cheap.  Note that if they're both naive, offset1 ==
     * offset2 == Py_None at this point.
     */
    if ((offset1 == offset2) ||
        (PyDelta_Check(offset1) && PyDelta_Check(offset2) &&
         delta_cmp(offset1, offset2) == 0)) {
        diff = memcmp(((PyDateTime_Time *)self)->data,
                      ((PyDateTime_Time *)other)->data,
                      _PyDateTime_TIME_DATASIZE);
        result = diff_to_bool(diff, op);
    }
    /* The hard case: both aware with different UTC offsets */
    else if (offset1 != Py_None && offset2 != Py_None) {
        int offsecs1, offsecs2;
        assert(offset1 != offset2); /* else last "if" handled it */
        offsecs1 = TIME_GET_HOUR(self) * 3600 +
                   TIME_GET_MINUTE(self) * 60 +
                   TIME_GET_SECOND(self) -
                   GET_TD_DAYS(offset1) * 86400 -
                   GET_TD_SECONDS(offset1);
        offsecs2 = TIME_GET_HOUR(other) * 3600 +
                   TIME_GET_MINUTE(other) * 60 +
                   TIME_GET_SECOND(other) -
                   GET_TD_DAYS(offset2) * 86400 -
                   GET_TD_SECONDS(offset2);
        diff = offsecs1 - offsecs2;
        if (diff == 0)
            diff = TIME_GET_MICROSECOND(self) -
                   TIME_GET_MICROSECOND(other);
        result = diff_to_bool(diff, op);
    }
    else {
        PyErr_SetString(PyExc_TypeError,
                        "can't compare offset-naive and "
                        "offset-aware times");
    }
 done:
    Py_DECREF(offset1);
    Py_XDECREF(offset2);
    return result;
}

Here is the call graph for this function:

static PyObject* time_str ( PyDateTime_Time self) [static]

Definition at line 3616 of file _datetimemodule.c.

{
    return PyObject_CallMethod((PyObject *)self, "isoformat", "()");
}

Here is the call graph for this function:

static PyObject* time_strftime ( PyDateTime_Time self,
PyObject args,
PyObject kw 
) [static]

Definition at line 3654 of file _datetimemodule.c.

{
    PyObject *result;
    PyObject *tuple;
    PyObject *format;
    static char *keywords[] = {"format", NULL};

    if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
                                      &format))
        return NULL;

    /* Python's strftime does insane things with the year part of the
     * timetuple.  The year is forced to (the otherwise nonsensical)
     * 1900 to work around that.
     */
    tuple = Py_BuildValue("iiiiiiiii",
                          1900, 1, 1, /* year, month, day */
                  TIME_GET_HOUR(self),
                  TIME_GET_MINUTE(self),
                  TIME_GET_SECOND(self),
                  0, 1, -1); /* weekday, daynum, dst */
    if (tuple == NULL)
        return NULL;
    assert(PyTuple_Size(tuple) == 9);
    result = wrap_strftime((PyObject *)self, format, tuple,
                           Py_None);
    Py_DECREF(tuple);
    return result;
}

Here is the call graph for this function:

static PyObject* time_time ( void  ) [static]

Definition at line 1335 of file _datetimemodule.c.