Commit 8e16b6b3 authored by Andi Vajda's avatar Andi Vajda
Browse files

- added wrappers for RuleBasedTimeZone, VTimeZone, BasicTimeZone

  - added wrapper for BasicTimeZone.getOffsetFromLocal
  - added wrappers for VTimeZone creation methods
  - added wrappers for VTimeZone.write, writeSimple, getTZURL, getLastModified
parent 98ebfbe3
......@@ -4,6 +4,10 @@ Version 2.6 ->
- added wrappers for MeasureUnit.product(), reciprocal(), getDimensionality()
- added wrapper for MeasureUnit.forIdentifier()
- implemented *, /, **, 1/m for MeasureUnit in terms of product and reciprocal
- added wrappers for RuleBasedTimeZone, VTimeZone, BasicTimeZone
- added wrapper for BasicTimeZone.getOffsetFromLocal
- added wrappers for VTimeZone creation methods
- added wrappers for VTimeZone.write, writeSimple, getTZURL, getLastModified
-
Version 2.5 -> 2.6
......
......@@ -26,7 +26,7 @@ involves more than just a ``pip`` call. Many operating systems distribute
pre-built binary packages of ICU and PyICU, see below.
- Mac OS X
- Ensure ICU is installed and can be found by `pkg-config` (as `icu-config` was [deprecated](http://userguide.icu-project.org/howtouseicu#TOC-C-Makefiles) as of ICU 63.1), either by following [ICU build instructions](https://htmlpreview.github.io/?https://github.com/unicode-org/icu/blob/maint/maint-68/icu4c/readme.html#HowToBuild), or by using Homebrew:
- Ensure ICU is installed and can be found by `pkg-config` (as `icu-config` was [deprecated](http://userguide.icu-project.org/howtouseicu#TOC-C-Makefiles) as of ICU 63.1), either by following [ICU build instructions](https://unicode-org.github.io/icu/userguide/icu4c/build.html), or by using Homebrew:
```sh
# install libicu (keg-only)
brew install pkg-config icu4c
......@@ -77,7 +77,7 @@ pre-built binary packages of ICU and PyICU, see below.
## Building PyICU
Before building PyICU the ICU libraries must be built and installed. Refer
to each system's instructions for more information.
to each system's [instructions](https://unicode-org.github.io/icu/userguide/icu4c/build.html) for more information.
PyICU is built with setuptools:
......@@ -132,7 +132,7 @@ corresponding Python APIs.
The ICU string type, [UnicodeString](https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1UnicodeString.html), is a type pointing at a mutable array of [UChar](https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/umachine_8h.html#a6bb9fad572d65b305324ef288165e2ac) Unicode 16-bit wide characters and is described [here](https://unicode-org.github.io/icu-docs/apidoc/dev/icu4c/classicu_1_1UnicodeString.html#details). The Python 3 [str](https://docs.python.org/3/library/stdtypes.html#str) type is described [here](https://docs.python.org/3/library/stdtypes.html#index-26) and [here](https://docs.python.org/3/howto/unicode.html). The Python 2 [unicode](https://docs.python.org/2.7/reference/datamodel.html#index-23) type is described [here](https://docs.python.org/2.7/library/stdtypes.html#sequence-types-str-unicode-list-tuple-bytearray-buffer-xrange).
Because of their differences, ICU's and Python's string types are not merged
Because of their differences, ICU's and Python's string objects are not merged
into the same type when crossing the C++ boundary but converted.
ICU APIs taking ``UnicodeString`` arguments have been overloaded to also
......
......@@ -39,6 +39,11 @@ DECLARE_CONSTANTS_TYPE(UCalendarDaysOfWeek)
DECLARE_CONSTANTS_TYPE(UCalendarMonths)
DECLARE_CONSTANTS_TYPE(UCalendarAMPMs)
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_CONSTANTS_TYPE(UTimeZoneLocalOption)
#endif
/* TimeZone */
static PyObject *t_timezone_getOffset(t_timezone *self, PyObject *args);
......@@ -92,6 +97,45 @@ static PyMethodDef t_timezone_methods[] = {
DECLARE_TYPE(TimeZone, t_timezone, UObject, TimeZone, abstract_init, NULL)
/* BasicTimeZone */
class t_basictimezone : public _wrapper {
public:
BasicTimeZone *object;
};
#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[] = {
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
DECLARE_METHOD(t_basictimezone, getOffsetFromLocal, METH_VARARGS),
#endif
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(BasicTimeZone, t_basictimezone, TimeZone, BasicTimeZone,
abstract_init, NULL)
/* RuleBasedTimeZone */
class t_rulebasedtimezone : public _wrapper {
public:
RuleBasedTimeZone *object;
};
static PyMethodDef t_rulebasedtimezone_methods[] = {
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(RuleBasedTimeZone,
t_rulebasedtimezone, BasicTimeZone, RuleBasedTimeZone,
abstract_init, NULL)
/* SimpleTimeZone */
class t_simpletimezone : public _wrapper {
......@@ -121,10 +165,44 @@ static PyMethodDef t_simpletimezone_methods[] = {
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(SimpleTimeZone, t_simpletimezone, TimeZone, SimpleTimeZone,
DECLARE_TYPE(SimpleTimeZone, t_simpletimezone, BasicTimeZone, SimpleTimeZone,
t_simpletimezone_init, NULL)
/* VTimeZone */
class t_vtimezone : public _wrapper {
public:
VTimeZone *object;
};
static PyObject *t_vtimezone_getTZURL(t_vtimezone *self);
static PyObject *t_vtimezone_getLastModified(t_vtimezone *self);
static PyObject *t_vtimezone_write(t_vtimezone *self, PyObject *args);
static PyObject *t_vtimezone_writeSimple(t_vtimezone *self, PyObject *arg);
static PyObject *t_vtimezone_createVTimeZone(PyTypeObject *type, PyObject *arg);
static PyObject *t_vtimezone_createVTimeZoneByID(PyTypeObject *type, PyObject *arg);
#if U_ICU_VERSION_HEX >= 0x04060000
static PyObject *t_vtimezone_createVTimeZoneFromBasicTimeZone(PyTypeObject *type, PyObject *arg);
#endif
static PyMethodDef t_vtimezone_methods[] = {
DECLARE_METHOD(t_vtimezone, getTZURL, METH_NOARGS),
DECLARE_METHOD(t_vtimezone, getLastModified, METH_NOARGS),
DECLARE_METHOD(t_vtimezone, write, METH_VARARGS),
DECLARE_METHOD(t_vtimezone, writeSimple, METH_O),
DECLARE_METHOD(t_vtimezone, createVTimeZone, METH_O | METH_CLASS),
DECLARE_METHOD(t_vtimezone, createVTimeZoneByID, METH_O | METH_CLASS),
#if U_ICU_VERSION_HEX >= 0x04060000
DECLARE_METHOD(t_vtimezone, createVTimeZoneFromBasicTimeZone, METH_O | METH_CLASS),
#endif
{ NULL, NULL, 0, NULL }
};
DECLARE_TYPE(VTimeZone, t_vtimezone, BasicTimeZone, VTimeZone,
abstract_init, NULL)
/* Calendar */
class t_calendar : public _wrapper {
......@@ -241,7 +319,10 @@ DECLARE_TYPE(GregorianCalendar, t_gregoriancalendar, Calendar,
PyObject *wrap_TimeZone(TimeZone *tz)
{
RETURN_WRAPPED_IF_ISINSTANCE(tz, RuleBasedTimeZone);
RETURN_WRAPPED_IF_ISINSTANCE(tz, SimpleTimeZone);
RETURN_WRAPPED_IF_ISINSTANCE(tz, VTimeZone);
RETURN_WRAPPED_IF_ISINSTANCE(tz, BasicTimeZone);
return wrap_TimeZone(tz, T_OWNED);
}
......@@ -282,7 +363,7 @@ static PyObject *t_timezone_getOffset(t_timezone *self, PyObject *args)
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getOffset", args);
}
......@@ -306,8 +387,7 @@ static PyObject *t_timezone_setRawOffset(t_timezone *self, PyObject *arg)
static PyObject *t_timezone_getID(t_timezone *self, PyObject *args)
{
UnicodeString *u;
UnicodeString _u;
UnicodeString *u, _u;
switch (PyTuple_Size(args)) {
case 0:
......@@ -571,8 +651,7 @@ static PyObject *t_timezone_getIDForWindowsID(PyTypeObject *type,
static PyObject *t_timezone_getWindowsID(PyTypeObject *type, PyObject *arg)
{
UnicodeString *id;
UnicodeString _id;
UnicodeString *id, _id;
if (!parseArg(arg, "S", &id, &_id))
{
......@@ -624,6 +703,37 @@ static PyObject *t_timezone_str(t_timezone *self)
DEFINE_RICHCMP(TimeZone, t_timezone)
/* BasicTimeZone */
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
static PyObject *t_basictimezone_getOffsetFromLocal(t_basictimezone *self,
PyObject *args)
{
UDate date;
UTimeZoneLocalOption nonExistingOpt, duplicateOpt;
switch (PyTuple_Size(args)) {
case 3:
if (!parseArgs(args, "Dii", &date, &nonExistingOpt, &duplicateOpt))
{
int32_t rawOffset, dstOffset;
STATUS_CALL(self->object->getOffsetFromLocal(
date, nonExistingOpt, duplicateOpt,
rawOffset, dstOffset, status));
return Py_BuildValue("(ii)", (int) rawOffset, (int) dstOffset);
}
break;
}
return PyErr_SetArgsError((PyObject *) self, "getOffsetFromLocal", args);
}
#endif // ICU 69
/* SimpleTimeZone */
static int t_simpletimezone_init(t_simpletimezone *self,
......@@ -858,6 +968,119 @@ static PyObject *t_simpletimezone_setDSTSavings(t_simpletimezone *self,
}
/* VTimeZone */
static PyObject *t_vtimezone_getTZURL(t_vtimezone *self)
{
UnicodeString url;
UBool result = self->object->getTZURL(url);
if (result)
return PyUnicode_FromUnicodeString(&url);
Py_RETURN_NONE;
}
static PyObject *t_vtimezone_getLastModified(t_vtimezone *self)
{
UDate date;
UBool result = self->object->getLastModified(date);
if (result)
return PyFloat_FromDouble(date / 1000.0);
Py_RETURN_NONE;
}
static PyObject *t_vtimezone_write(t_vtimezone *self, PyObject *args)
{
UDate start;
UnicodeString data;
switch (PyTuple_Size(args)) {
case 0:
STATUS_CALL(self->object->write(data, status));
return PyUnicode_FromUnicodeString(&data);
case 1:
if (!parseArgs(args, "D", &start))
{
STATUS_CALL(self->object->writeSimple(start, data, status));
return PyUnicode_FromUnicodeString(&data);
}
}
return PyErr_SetArgsError((PyObject *) self, "write", args);
}
static PyObject *t_vtimezone_writeSimple(t_vtimezone *self, PyObject *arg)
{
UDate date;
if (!parseArg(arg, "D", &date))
{
UnicodeString data;
STATUS_CALL(self->object->writeSimple(date, data, status));
return PyUnicode_FromUnicodeString(&data);
}
return PyErr_SetArgsError((PyObject *) self, "writeSimple", arg);
}
static PyObject *t_vtimezone_createVTimeZone(PyTypeObject *type, PyObject *arg)
{
UnicodeString *u, _u;
if (!parseArg(arg, "S", &u, &_u))
{
VTimeZone *vtz;
STATUS_CALL(vtz = VTimeZone::createVTimeZone(*u, status));
return wrap_VTimeZone(vtz, T_OWNED);
}
return PyErr_SetArgsError(type, "createVTimeZone", arg);
}
static PyObject *t_vtimezone_createVTimeZoneByID(
PyTypeObject *type, PyObject *arg)
{
UnicodeString *id, _id;
if (!parseArg(arg, "S", &id, &_id))
{
VTimeZone *vtz = VTimeZone::createVTimeZoneByID(*id);
if (vtz != NULL)
return wrap_VTimeZone(vtz, T_OWNED);
Py_RETURN_NONE;
}
return PyErr_SetArgsError(type, "createVTimeZoneByID", arg);
}
#if U_ICU_VERSION_HEX >= 0x04060000
static PyObject *t_vtimezone_createVTimeZoneFromBasicTimeZone(
PyTypeObject *type, PyObject *arg)
{
BasicTimeZone *tz;
if (!parseArg(arg, "P", TYPE_CLASSID(BasicTimeZone), &tz))
{
VTimeZone *vtz;
STATUS_CALL(vtz = VTimeZone::createVTimeZoneFromBasicTimeZone(
*tz, status));
return wrap_VTimeZone(vtz, T_OWNED);
}
return PyErr_SetArgsError(type, "createVTimeZoneFromBasicTimeZone", arg);
}
#endif
/* Calendar */
PyObject *wrap_Calendar(Calendar *calendar)
......@@ -1508,8 +1731,14 @@ void _init_calendar(PyObject *m)
INSTALL_CONSTANTS_TYPE(UCalendarDaysOfWeek, m);
INSTALL_CONSTANTS_TYPE(UCalendarMonths, m);
INSTALL_CONSTANTS_TYPE(UCalendarAMPMs, m);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_CONSTANTS_TYPE(UTimeZoneLocalOption, m);
#endif
REGISTER_TYPE(TimeZone, m);
REGISTER_TYPE(BasicTimeZone, m);
REGISTER_TYPE(RuleBasedTimeZone, m);
REGISTER_TYPE(SimpleTimeZone, m);
REGISTER_TYPE(VTimeZone, m);
INSTALL_TYPE(Calendar, m);
REGISTER_TYPE(GregorianCalendar, m);
......@@ -1562,6 +1791,15 @@ void _init_calendar(PyObject *m)
INSTALL_ENUM(UCalendarAMPMs, "AM", UCAL_AM);
INSTALL_ENUM(UCalendarAMPMs, "PM", UCAL_PM);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_ENUM(UTimeZoneLocalOption, "FORMER", UCAL_TZ_LOCAL_FORMER);
INSTALL_ENUM(UTimeZoneLocalOption, "LATTER", UCAL_TZ_LOCAL_LATTER);
INSTALL_ENUM(UTimeZoneLocalOption, "STANDARD_FORMER", UCAL_TZ_LOCAL_STANDARD_FORMER);
INSTALL_ENUM(UTimeZoneLocalOption, "STANDARD_LATTER", UCAL_TZ_LOCAL_STANDARD_LATTER);
INSTALL_ENUM(UTimeZoneLocalOption, "DAYLIGHT_FORMER", UCAL_TZ_LOCAL_DAYLIGHT_FORMER);
INSTALL_ENUM(UTimeZoneLocalOption, "DAYLIGHT_LATTER", UCAL_TZ_LOCAL_DAYLIGHT_LATTER);
#endif
INSTALL_STATIC_INT(TimeZone, SHORT);
INSTALL_STATIC_INT(TimeZone, LONG);
......
......@@ -127,7 +127,10 @@ typedef intintobjargproc ssizessizeobjargproc;
#include <unicode/currunit.h>
#include <unicode/curramt.h>
#include <unicode/timezone.h>
#include <unicode/basictz.h>
#include <unicode/rbtz.h>
#include <unicode/simpletz.h>
#include <unicode/vtzone.h>
#include <unicode/dtfmtsym.h>
#include <unicode/dcfmtsym.h>
#include <unicode/strenum.h>
......
......@@ -2362,4 +2362,7 @@ void _init_format(PyObject *m)
INSTALL_ENUM(UFieldCategory, "LIST_SPAN", UFIELD_CATEGORY_LIST_SPAN);
INSTALL_ENUM(UFieldCategory, "DATE_INTERVAL_SPAN", UFIELD_CATEGORY_DATE_INTERVAL_SPAN);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_ENUM(UFieldCategory, "NUMBER_RANGE_SPAN", UFIELD_CATEGORY_NUMBER_RANGE_SPAN);
#endif
}
......@@ -5414,6 +5414,11 @@ void _init_numberformat(PyObject *m)
#if U_ICU_VERSION_HEX >= 0x04080000
INSTALL_ENUM(UNumberFormatRoundingMode, "UNNECESSARY", UNUM_ROUND_UNNECESSARY);
#endif
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_ENUM(UNumberFormatRoundingMode, "HALF_CEILING", UNUM_ROUND_HALF_CEILING);
INSTALL_ENUM(UNumberFormatRoundingMode, "HALF_FLOOR", UNUM_ROUND_HALF_FLOOR);
INSTALL_ENUM(UNumberFormatRoundingMode, "HALF_ODD", UNUM_ROUND_HALF_ODD);
#endif
INSTALL_CONSTANTS_TYPE(UNumberFormatStyle, m);
INSTALL_ENUM(UNumberFormatStyle, "PATTERN_DECIMAL", UNUM_PATTERN_DECIMAL);
......@@ -5490,6 +5495,10 @@ void _init_numberformat(PyObject *m)
INSTALL_ENUM(UNumberSignDisplay, "NEVER", UNUM_SIGN_NEVER);
INSTALL_ENUM(UNumberSignDisplay, "ACCOUNTING", UNUM_SIGN_ACCOUNTING);
INSTALL_ENUM(UNumberSignDisplay, "ACCOUNTING_ALWAYS", UNUM_SIGN_ACCOUNTING_ALWAYS);
#if U_ICU_VERSION_HEX >= VERSION_HEX(69, 0, 0)
INSTALL_ENUM(UNumberSignDisplay, "ACCOUNTING_NEGATIVE", UNUM_SIGN_ACCOUNTING_NEGATIVE);
INSTALL_ENUM(UNumberSignDisplay, "NEGATIVE", UNUM_SIGN_NEGATIVE);
#endif
INSTALL_CONSTANTS_TYPE(UNumberDecimalSeparatorDisplay, m);
INSTALL_ENUM(UNumberDecimalSeparatorDisplay, "AUTO", UNUM_DECIMAL_SEPARATOR_AUTO);
......
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