Commit d1c84d88 authored by Andi Vajda's avatar Andi Vajda
Browse files

added wrappers for TimeZoneRule, TimeZoneTransition

added wrapper for TimeZoneRule.isEquivalentTo
added wrapper for TimeZoneTransition.getTime, getFrom, getTo
added wrapper for BasicTimeZone.getNextTransition, getPreviousTransition
parent 8e16b6b3
......@@ -8,6 +8,10 @@ Version 2.6 ->
- added wrapper for BasicTimeZone.getOffsetFromLocal
- added wrappers for VTimeZone creation methods
- added wrappers for VTimeZone.write, writeSimple, getTZURL, getLastModified
- added wrappers for TimeZoneRule.getName, getRawOffset, getDSTSavings
- added wrapper for TimeZoneRule.isEquivalentTo
- added wrapper for TimeZoneTransition.getTime, getFrom, getTo
- added wrapper for BasicTimeZone.getNextTransition, getPreviousTransition
-
Version 2.5 -> 2.6
......
......@@ -44,6 +44,51 @@ DECLARE_CONSTANTS_TYPE(UTimeZoneLocalOption)
#endif
/* TimeZoneRule */
class t_timezonerule : public _wrapper {
public:
TimeZoneRule *object;
};
static PyObject *t_timezonerule_getName(t_timezonerule *self);
static PyObject *t_timezonerule_getRawOffset(t_timezonerule *self);
static PyObject *t_timezonerule_getDSTSavings(t_timezonerule *self);
static PyObject *t_timezonerule_isEquivalentTo(t_timezonerule *self, PyObject *arg);
static PyMethodDef t_timezonerule_methods[] = {
DECLARE_METHOD(t_timezonerule, getName, METH_NOARGS),
DECLARE_METHOD(t_timezonerule, getRawOffset, METH_NOARGS),
DECLARE_METHOD(t_timezonerule, getDSTSavings, METH_NOARGS),
DECLARE_METHOD(t_timezonerule, isEquivalentTo, METH_O),
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(TimeZoneRule, t_timezonerule, UObject, TimeZoneRule,
abstract_init, NULL)
/* TimeZoneTransition */
class t_timezonetransition : public _wrapper {
public:
TimeZoneTransition *object;
};
static PyObject *t_timezonetransition_getTime(t_timezonetransition *self);
static PyObject *t_timezonetransition_getFrom(t_timezonetransition *self);
static PyObject *t_timezonetransition_getTo(t_timezonetransition *self);
static PyMethodDef t_timezonetransition_methods[] = {
DECLARE_METHOD(t_timezonetransition, getTime, METH_NOARGS),
DECLARE_METHOD(t_timezonetransition, getFrom, METH_NOARGS),
DECLARE_METHOD(t_timezonetransition, getTo, METH_NOARGS),
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(TimeZoneTransition,
t_timezonetransition, UObject, TimeZoneTransition,
abstract_init, NULL)
/* TimeZone */
static PyObject *t_timezone_getOffset(t_timezone *self, PyObject *args);
......@@ -104,12 +149,17 @@ public:
BasicTimeZone *object;
};
static PyObject *t_basictimezone_getNextTransition(t_basictimezone *self, PyObject *args);
static PyObject *t_basictimezone_getPreviousTransition(t_basictimezone *self, PyObject *args);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_basictimezone_getOffsetFromLocal(t_basictimezone *self,
PyObject *args);
#endif
static PyMethodDef t_basictimezone_methods[] = {
DECLARE_METHOD(t_basictimezone, getNextTransition, METH_VARARGS),
DECLARE_METHOD(t_basictimezone, getPreviousTransition, METH_VARARGS),
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_METHOD(t_basictimezone, getOffsetFromLocal, METH_VARARGS),
#endif
......@@ -315,6 +365,78 @@ DECLARE_TYPE(GregorianCalendar, t_gregoriancalendar, Calendar,
GregorianCalendar, t_gregoriancalendar_init, NULL)
/* TimeZoneRule */
static PyObject *t_timezonerule_getName(t_timezonerule *self)
{
UnicodeString u;
self->object->getName(u);
return PyUnicode_FromUnicodeString(&u);
}
static PyObject *t_timezonerule_getRawOffset(t_timezonerule *self)
{
return PyInt_FromLong(self->object->getRawOffset());
}
static PyObject *t_timezonerule_getDSTSavings(t_timezonerule *self)
{
return PyInt_FromLong(self->object->getDSTSavings());
}
static PyObject *t_timezonerule_isEquivalentTo(t_timezonerule *self,
PyObject *arg)
{
TimeZoneRule *tzr;
if (!parseArg(arg, "P", TYPE_CLASSID(TimeZoneRule), &tzr))
{
UBool result = self->object->isEquivalentTo(*tzr);
Py_RETURN_BOOL(result);
}
return PyErr_SetArgsError((PyObject *) self, "isEquivalentTo", arg);
}
static PyObject *t_timezonerule_str(t_timezonerule *self)
{
UnicodeString u;
self->object->getName(u);
return PyUnicode_FromUnicodeString(&u);
}
DEFINE_RICHCMP(TimeZoneRule, t_timezonerule)
/* TimeZoneTransition */
static PyObject *t_timezonetransition_getTime(t_timezonetransition *self)
{
return PyFloat_FromDouble(self->object->getTime() / 1000.0);
}
static PyObject *t_timezonetransition_getFrom(t_timezonetransition *self)
{
const TimeZoneRule *tzr = self->object->getFrom();
if (tzr != NULL)
return wrap_TimeZoneRule((TimeZoneRule *) (tzr->clone()), T_OWNED);
Py_RETURN_NONE;
}
static PyObject *t_timezonetransition_getTo(t_timezonetransition *self)
{
const TimeZoneRule *tzr = self->object->getTo();
if (tzr != NULL)
return wrap_TimeZoneRule((TimeZoneRule *) (tzr->clone()), T_OWNED);
Py_RETURN_NONE;
}
/* TimeZone */
PyObject *wrap_TimeZone(TimeZone *tz)
......@@ -705,6 +827,86 @@ DEFINE_RICHCMP(TimeZone, t_timezone)
/* BasicTimeZone */
static PyObject *t_basictimezone_getNextTransition(t_basictimezone *self,
PyObject *args)
{
UDate base;
UBool inclusive;
switch (PyTuple_Size(args)) {
case 1:
if (!parseArgs(args, "D", &base))
{
TimeZoneTransition tzt;
UBool found = self->object->getNextTransition(base, false, tzt);
if (found)
return wrap_TimeZoneTransition(
(TimeZoneTransition *) (tzt.clone()), T_OWNED);
Py_RETURN_FALSE;
}
break;
case 2:
if (!parseArgs(args, "Db", &base, &inclusive))
{
TimeZoneTransition tzt;
UBool found = self->object->getNextTransition(base, inclusive, tzt);
if (found)
return wrap_TimeZoneTransition(
(TimeZoneTransition *) (tzt.clone()), T_OWNED);
Py_RETURN_FALSE;
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getNextTransition", args);
}
static PyObject *t_basictimezone_getPreviousTransition(t_basictimezone *self,
PyObject *args)
{
UDate base;
UBool inclusive;
switch (PyTuple_Size(args)) {
case 1:
if (!parseArgs(args, "D", &base))
{
TimeZoneTransition tzt;
UBool found = self->object->getPreviousTransition(base, false, tzt);
if (found)
return wrap_TimeZoneTransition(
(TimeZoneTransition *) (tzt.clone()), T_OWNED);
Py_RETURN_FALSE;
}
break;
case 2:
if (!parseArgs(args, "Db", &base, &inclusive))
{
TimeZoneTransition tzt;
UBool found = self->object->getPreviousTransition(
base, inclusive, tzt);
if (found)
return wrap_TimeZoneTransition(
(TimeZoneTransition *) (tzt.clone()), T_OWNED);
Py_RETURN_FALSE;
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getPreviousTransition", args);
}
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_basictimezone_getOffsetFromLocal(t_basictimezone *self,
......@@ -1008,6 +1210,7 @@ static PyObject *t_vtimezone_write(t_vtimezone *self, PyObject *args)
STATUS_CALL(self->object->writeSimple(start, data, status));
return PyUnicode_FromUnicodeString(&data);
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "write", args);
......@@ -1722,6 +1925,8 @@ static PyObject *t_gregoriancalendar_isLeapYear(t_gregoriancalendar *self, PyObj
void _init_calendar(PyObject *m)
{
TimeZoneRuleType_.tp_str = (reprfunc) t_timezonerule_str;
TimeZoneRuleType_.tp_richcompare = (richcmpfunc) t_timezonerule_richcmp;
TimeZoneType_.tp_str = (reprfunc) t_timezone_str;
TimeZoneType_.tp_richcompare = (richcmpfunc) t_timezone_richcmp;
CalendarType_.tp_str = (reprfunc) t_calendar_str;
......@@ -1734,6 +1939,8 @@ void _init_calendar(PyObject *m)
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_CONSTANTS_TYPE(UTimeZoneLocalOption, m);
#endif
REGISTER_TYPE(TimeZoneRule, m);
REGISTER_TYPE(TimeZoneTransition, m);
REGISTER_TYPE(TimeZone, m);
REGISTER_TYPE(BasicTimeZone, m);
REGISTER_TYPE(RuleBasedTimeZone, m);
......
......@@ -131,6 +131,8 @@ typedef intintobjargproc ssizessizeobjargproc;
#include <unicode/rbtz.h>
#include <unicode/simpletz.h>
#include <unicode/vtzone.h>
#include <unicode/tzrule.h>
#include <unicode/tztrans.h>
#include <unicode/dtfmtsym.h>
#include <unicode/dcfmtsym.h>
#include <unicode/strenum.h>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment