Lines Matching defs:tzinfo
658 * We abuse the tp_alloc "nitems" argument to communicate whether a tzinfo
661 * struct that has room for the tzinfo member, so subclasses in Python will
662 * allocate enough space for a tzinfo member whether or not one is actually
989 int second, int usecond, PyObject *tzinfo, int fold, PyTypeObject *type)
992 char aware = tzinfo != Py_None;
1000 if (check_tzinfo_subclass(tzinfo) < 0) {
1013 Py_INCREF(tzinfo);
1014 self->tzinfo = tzinfo;
1023 int second, int usecond, PyObject *tzinfo, PyTypeObject *type)
1026 tzinfo, 0, type);
1029 #define new_datetime(y, m, d, hh, mm, ss, us, tzinfo, fold) \
1030 new_datetime_ex2(y, m, d, hh, mm, ss, us, tzinfo, fold, \
1035 int second, int usecond, PyObject *tzinfo,
1041 tzinfo, fold);
1052 tzinfo);
1060 int second, int usecond, PyObject *tzinfo,
1063 second, usecond, tzinfo, 0,
1070 PyObject *tzinfo, int fold, PyTypeObject *type)
1073 char aware = tzinfo != Py_None;
1078 if (check_tzinfo_subclass(tzinfo) < 0) {
1091 Py_INCREF(tzinfo);
1092 self->tzinfo = tzinfo;
1101 PyObject *tzinfo, PyTypeObject *type)
1103 return new_time_ex2(hour, minute, second, usecond, tzinfo, 0, type);
1106 #define new_time(hh, mm, ss, us, tzinfo, fold) \
1107 new_time_ex2(hh, mm, ss, us, tzinfo, fold, &PyDateTime_TimeType)
1208 * tzinfo helpers.
1211 /* Ensure that p is None or of a tzinfo subclass. Return 0 if OK; if not
1220 "tzinfo argument must be None or of a tzinfo subclass, "
1226 /* If self has a tzinfo member, return a BORROWED reference to it. Else
1233 PyObject *tzinfo = NULL;
1236 tzinfo = ((PyDateTime_DateTime *)self)->tzinfo;
1238 tzinfo = ((PyDateTime_Time *)self)->tzinfo;
1240 return tzinfo;
1243 /* Call getattr(tzinfo, name)(tzinfoarg), and check the result. tzinfo must
1244 * be an instance of the tzinfo class. If the method returns None, this
1251 call_tzinfo_method(PyObject *tzinfo, const char *name, PyObject *tzinfoarg)
1255 assert(tzinfo != NULL);
1256 assert(PyTZInfo_Check(tzinfo) || tzinfo == Py_None);
1259 if (tzinfo == Py_None)
1261 offset = PyObject_CallMethod(tzinfo, name, "O", tzinfoarg);
1278 "tzinfo.%s() must return None or "
1288 /* Call tzinfo.utcoffset(tzinfoarg), and extract an integer from the
1289 * result. tzinfo must be an instance of the tzinfo class. If utcoffset()
1297 call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
1299 return call_tzinfo_method(tzinfo, "utcoffset", tzinfoarg);
1302 /* Call tzinfo.dst(tzinfoarg), and extract an integer from the
1303 * result. tzinfo must be an instance of the tzinfo class. If dst()
1311 call_dst(PyObject *tzinfo, PyObject *tzinfoarg)
1313 return call_tzinfo_method(tzinfo, "dst", tzinfoarg);
1316 /* Call tzinfo.tzname(tzinfoarg), and return the result. tzinfo must be
1317 * an instance of the tzinfo class or None. If tzinfo isn't None, and
1323 call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
1328 assert(tzinfo != NULL);
1329 assert(check_tzinfo_subclass(tzinfo) >= 0);
1332 if (tzinfo == Py_None)
1335 result = _PyObject_CallMethodIdOneArg(tzinfo, &PyId_tzname, tzinfoarg);
1341 PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
1351 /* repr is like "someclass(arg1, arg2)". If tzinfo isn't None,
1353 * ", tzinfo=" + repr(tzinfo)
1357 append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
1362 assert(tzinfo);
1363 if (tzinfo == Py_None)
1371 repr = PyUnicode_FromFormat("%U, tzinfo=%R)", temp, tzinfo);
1378 * ", fold=" + repr(tzinfo)
1403 PyObject *tzinfo;
1415 tzinfo = new_timezone(delta, NULL);
1419 tzinfo = Py_None;
1423 return tzinfo;
1453 * tzinfo.uctoffset(tzinfoarg). If that returns None, \0 is stored into
1463 PyObject *tzinfo, PyObject *tzinfoarg)
1471 offset = call_utcoffset(tzinfo, tzinfoarg);
1513 PyObject *tzinfo = get_tzinfo_member(object);
1519 if (tzinfo == Py_None || tzinfo == NULL)
1523 temp = call_tzname(tzinfo, tzinfoarg);
1571 * tzinfoarg is the argument to pass to the object's tzinfo method, if
1638 PyObject *tzinfo = get_tzinfo_member(object);
1641 if (tzinfo != Py_None && tzinfo != NULL) {
1646 tzinfo,
3685 * raising NotImplemented exceptions. Real tzinfo classes need
3687 * datetime and time constructors (their tzinfo arguments need to
3688 * be subclasses of this tzinfo class, which is easy and quick to check).
3691 * to allow tzinfo objects to be instantiated. This wasn't an issue
3701 "a tzinfo subclass must implement %s()",
3746 PyErr_SetString(PyExc_ValueError, "fromutc: dt.tzinfo "
3807 * Pickle support. This is solely so that tzinfo subclasses can use
3808 * pickling -- tzinfo itself is supposed to be uninstantiable.
3867 "datetime.tzinfo", /* tp_name */
4061 if (!HASTZINFO(dt) || dt->tzinfo != (PyObject *)self) {
4062 PyErr_SetString(PyExc_ValueError, "fromutc: dt.tzinfo "
4099 PyDoc_STR("Fixed offset from UTC implementation of tzinfo.");
4177 PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
4193 {"tzinfo", (getter)time_tzinfo},
4203 "tzinfo", "fold", NULL};
4206 time_from_pickle(PyTypeObject *type, PyObject *state, PyObject *tzinfo)
4209 char aware = (char)(tzinfo != Py_None);
4211 if (aware && check_tzinfo_subclass(tzinfo) < 0) {
4212 PyErr_SetString(PyExc_TypeError, "bad tzinfo state arg");
4224 Py_INCREF(tzinfo);
4225 me->tzinfo = tzinfo;
4246 PyObject *tzinfo = Py_None;
4253 tzinfo = PyTuple_GET_ITEM(args, 1);
4259 return time_from_pickle(type, state, tzinfo);
4280 self = time_from_pickle(type, state, tzinfo);
4285 tzinfo = Py_None;
4290 &tzinfo, &fold)) {
4291 self = new_time_ex2(hour, minute, second, usecond, tzinfo, fold,
4305 Py_XDECREF(self->tzinfo);
4311 * Indirect access to tzinfo methods.
4354 result = append_keyword_tzinfo(result, self->tzinfo);
4418 if (result == NULL || !HASTZINFO(self) || self->tzinfo == Py_None)
4422 if (format_utcoffset(buf, sizeof(buf), ":", self->tzinfo,
4549 HASTZINFO(self) ? self->tzinfo : Py_None,
4604 PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
4609 &hh, &mm, &ss, &us, &tzinfo, &fold))
4616 tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
4661 PyObject *tzinfo = tzinfo_from_isoformat_results(rv, tzoffset,
4664 if (tzinfo == NULL) {
4670 t = new_time(hour, minute, second, microsecond, tzinfo, 0);
4673 hour, minute, second, microsecond, tzinfo);
4676 Py_DECREF(tzinfo);
4687 /* Let basestate be the non-tzinfo data string.
4688 * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
4704 if (! HASTZINFO(self) || self->tzinfo == Py_None)
4707 result = PyTuple_Pack(2, basestate, self->tzinfo);
4746 PyDoc_STR("Return self.tzinfo.utcoffset(self).")},
4749 PyDoc_STR("Return self.tzinfo.tzname(self).")},
4752 PyDoc_STR("Return self.tzinfo.dst(self).")},
4770 PyDoc_STR("time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object\n\
4772 All arguments are optional. tzinfo may be None, or an instance of\n\
4773 a tzinfo subclass. The remaining arguments may be ints.\n");
4852 PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
4868 {"tzinfo", (getter)datetime_tzinfo},
4879 "microsecond", "tzinfo", "fold", NULL
4883 datetime_from_pickle(PyTypeObject *type, PyObject *state, PyObject *tzinfo)
4886 char aware = (char)(tzinfo != Py_None);
4888 if (aware && check_tzinfo_subclass(tzinfo) < 0) {
4889 PyErr_SetString(PyExc_TypeError, "bad tzinfo state arg");
4901 Py_INCREF(tzinfo);
4902 me->tzinfo = tzinfo;
4927 PyObject *tzinfo = Py_None;
4933 tzinfo = PyTuple_GET_ITEM(args, 1);
4939 return datetime_from_pickle(type, state, tzinfo);
4960 self = datetime_from_pickle(type, state, tzinfo);
4965 tzinfo = Py_None;
4970 &second, &usecond, &tzinfo, &fold)) {
4973 tzinfo, fold, type);
5032 PyObject *tzinfo)
5054 if (tzinfo == Py_None && f == _PyTime_localtime
5092 second, us, tzinfo, fold, cls);
5104 PyObject *tzinfo)
5113 return datetime_from_timet_and_us(cls, f, timet, (int)us, tzinfo);
5121 datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
5131 return datetime_from_timet_and_us(cls, f, secs, us, tzinfo);
5164 /* Convert UTC to tzinfo's zone. */
5185 PyObject *tzinfo = Py_None;
5189 keywords, ×tamp, &tzinfo))
5191 if (check_tzinfo_subclass(tzinfo) < 0)
5195 tzinfo == Py_None ? _PyTime_localtime :
5198 tzinfo);
5199 if (self != NULL && tzinfo != Py_None) {
5200 /* Convert UTC to tzinfo's zone. */
5201 self = _PyObject_CallMethodId(tzinfo, &PyId_fromutc, "N", self);
5243 static char *keywords[] = {"date", "time", "tzinfo", NULL};
5246 PyObject *tzinfo = NULL;
5251 &PyDateTime_TimeType, &time, &tzinfo)) {
5252 if (tzinfo == NULL) {
5254 tzinfo = ((PyDateTime_Time *)time)->tzinfo;
5256 tzinfo = Py_None;
5265 tzinfo,
5503 PyObject *tzinfo = tzinfo_from_isoformat_results(rv, tzoffset, tzusec);
5504 if (tzinfo == NULL) {
5509 second, microsecond, tzinfo, cls);
5511 Py_DECREF(tzinfo);
5532 Py_XDECREF(self->tzinfo);
5538 * Indirect access to tzinfo methods.
5562 * the tzinfo state of date.
5588 HASTZINFO(date) ? date->tzinfo : Py_None,
5736 return append_keyword_tzinfo(baserepr, self->tzinfo);
5803 if (format_utcoffset(buffer, sizeof(buffer), ":", self->tzinfo,
5834 ((PyDateTime_DateTime *)dt)->tzinfo : Py_None,
5997 HASTZINFO(self) ? self->tzinfo : Py_None,
6060 PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
6066 &tzinfo, &fold))
6073 tuple = Py_BuildValue("iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo);
6205 PyObject *tzinfo = Py_None;
6209 &tzinfo))
6212 if (check_tzinfo_subclass(tzinfo) == -1)
6215 if (!HASTZINFO(self) || self->tzinfo == Py_None) {
6221 self_tzinfo = self->tzinfo;
6226 if (self_tzinfo == tzinfo) {
6273 /* Result is already aware - just replace tzinfo. */
6274 temp = result->tzinfo;
6275 result->tzinfo = PyDateTime_TimeZone_UTC;
6276 Py_INCREF(result->tzinfo);
6280 /* Attach new tzinfo and let fromutc() do the rest. */
6281 temp = result->tzinfo;
6282 if (tzinfo == Py_None) {
6283 tzinfo = local_timezone(result);
6284 if (tzinfo == NULL) {
6290 Py_INCREF(tzinfo);
6291 result->tzinfo = tzinfo;
6296 _PyObject_CallMethodIdOneArg(tzinfo, &PyId_fromutc, temp);
6307 if (HASTZINFO(self) && self->tzinfo != Py_None) {
6310 dst = call_dst(self->tzinfo, (PyObject *)self);
6382 if (HASTZINFO(self) && self->tzinfo != Py_None) {
6441 PyObject *tzinfo;
6444 tzinfo = GET_DT_TZINFO(self);
6445 if (tzinfo == Py_None) {
6451 offset = call_utcoffset(tzinfo, (PyObject *)self);
6480 /* Let basestate be the non-tzinfo data string.
6481 * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
6497 if (! HASTZINFO(self) || self->tzinfo == Py_None)
6500 result = PyTuple_Pack(2, basestate, self->tzinfo);
6559 PyDoc_STR("Return time object with same time but with tzinfo=None.")},
6562 PyDoc_STR("Return time object with same time and tzinfo.")},
6587 PyDoc_STR("Return self.tzinfo.utcoffset(self).")},
6590 PyDoc_STR("Return self.tzinfo.tzname(self).")},
6593 PyDoc_STR("Return self.tzinfo.dst(self).")},
6611 PyDoc_STR("datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n\
6613 The year, month and day arguments are required. tzinfo may be None, or an\n\
6614 instance of a tzinfo subclass. The remaining arguments may be ints.\n");
6938 2. If x and y have the same tzinfo member, x.s = y.s.
6940 sane tzinfo classes.
6943 This is again a requirement for a sane tzinfo class.
6946 This follows from #2, and that datimetimetz+timedelta preserves tzinfo.
6952 (meaning that the various tzinfo methods exist, and don't blow up or return
7000 sense then. The docs ask that an Eastern tzinfo class consider such a time to
7015 x.n + y.s = since z and y are have the same tzinfo member,
7045 If so, we're done. If not, the tzinfo class is insane, according to the
7057 -z.s - z.d + z'.s + z'.d = z and z' have same tzinfo
7071 tzinfo class. In US Eastern, that's 5:MM UTC = 0:MM EST = 1:MM EDT. During
7093 Note again that z' is not UTC-equivalent as far as the hybrid tzinfo class is
7119 pretty bizarre, and a tzinfo subclass can override fromutc() if it is.