"Fossies" - the Fresh Open Source Software Archive

Member "chandler-1.0.3/external/PyICU/PyICU-0.8-92/dateformat.cpp" (12 Sep 2007, 34636 Bytes) of archive /windows/misc/Chandler_src_1.0.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* ====================================================================
    2  * Copyright (c) 2004-2006 Open Source Applications Foundation.
    3  *
    4  * Permission is hereby granted, free of charge, to any person obtaining a
    5  * copy of this software and associated documentation files (the "Software"),
    6  * to deal in the Software without restriction, including without limitation
    7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
    8  * and/or sell copies of the Software, and to permit persons to whom the
    9  * Software is furnished to do so, subject to the following conditions: 
   10  *
   11  * The above copyright notice and this permission notice shall be included
   12  * in all copies or substantial portions of the Software. 
   13  *
   14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
   20  * DEALINGS IN THE SOFTWARE.
   21  * ====================================================================
   22  */
   23 
   24 #include "common.h"
   25 #include "structmember.h"
   26 
   27 #include "bases.h"
   28 #include "locale.h"
   29 #include "format.h"
   30 #include "calendar.h"
   31 #include "numberformat.h"
   32 #include "dateformat.h"
   33 #include "macros.h"
   34 
   35 
   36 /* DateFormatSymbols */
   37 
   38 class t_dateformatsymbols : public _wrapper {
   39 public:
   40     DateFormatSymbols *object;
   41 };
   42 
   43 static int t_dateformatsymbols_init(t_dateformatsymbols *self,
   44                                     PyObject *args, PyObject *kwds);
   45 static PyObject *t_dateformatsymbols_getEras(t_dateformatsymbols *self);
   46 static PyObject *t_dateformatsymbols_setEras(t_dateformatsymbols *self, PyObject *arg);
   47 static PyObject *t_dateformatsymbols_getMonths(t_dateformatsymbols *self,
   48                                                PyObject *args);
   49 static PyObject *t_dateformatsymbols_setMonths(t_dateformatsymbols *self,
   50                                                PyObject *arg);
   51 static PyObject *t_dateformatsymbols_getShortMonths(t_dateformatsymbols *self);
   52 static PyObject *t_dateformatsymbols_setShortMonths(t_dateformatsymbols *self,
   53                                                     PyObject *arg);
   54 static PyObject *t_dateformatsymbols_getWeekdays(t_dateformatsymbols *self,
   55                                                  PyObject *args);
   56 static PyObject *t_dateformatsymbols_setWeekdays(t_dateformatsymbols *self,
   57                                                  PyObject *arg);
   58 static PyObject *t_dateformatsymbols_getShortWeekdays(t_dateformatsymbols *self);
   59 static PyObject *t_dateformatsymbols_setShortWeekdays(t_dateformatsymbols *self,
   60                                                       PyObject *arg);
   61 static PyObject *t_dateformatsymbols_getAmPmStrings(t_dateformatsymbols *self);
   62 static PyObject *t_dateformatsymbols_setAmPmStrings(t_dateformatsymbols *self,
   63                                                     PyObject *arg);
   64 static PyObject *t_dateformatsymbols_getLocalPatternChars(t_dateformatsymbols *self, PyObject *args);
   65 static PyObject *t_dateformatsymbols_setLocalPatternChars(t_dateformatsymbols *self, PyObject *arg);
   66 static PyObject *t_dateformatsymbols_getLocale(t_dateformatsymbols *self,
   67                                                PyObject *args);
   68 
   69 static PyMethodDef t_dateformatsymbols_methods[] = {
   70     DECLARE_METHOD(t_dateformatsymbols, getEras, METH_NOARGS),
   71     DECLARE_METHOD(t_dateformatsymbols, setEras, METH_O),
   72     DECLARE_METHOD(t_dateformatsymbols, getMonths, METH_VARARGS),
   73     DECLARE_METHOD(t_dateformatsymbols, setMonths, METH_O),
   74     DECLARE_METHOD(t_dateformatsymbols, getShortMonths, METH_NOARGS),
   75     DECLARE_METHOD(t_dateformatsymbols, setShortMonths, METH_O),
   76     DECLARE_METHOD(t_dateformatsymbols, getWeekdays, METH_VARARGS),
   77     DECLARE_METHOD(t_dateformatsymbols, setWeekdays, METH_O),
   78     DECLARE_METHOD(t_dateformatsymbols, getShortWeekdays, METH_NOARGS),
   79     DECLARE_METHOD(t_dateformatsymbols, setShortWeekdays, METH_O),
   80     DECLARE_METHOD(t_dateformatsymbols, getAmPmStrings, METH_NOARGS),
   81     DECLARE_METHOD(t_dateformatsymbols, setAmPmStrings, METH_O),
   82     DECLARE_METHOD(t_dateformatsymbols, getLocalPatternChars, METH_VARARGS),
   83     DECLARE_METHOD(t_dateformatsymbols, setLocalPatternChars, METH_O),
   84     DECLARE_METHOD(t_dateformatsymbols, getLocale, METH_VARARGS),
   85     { NULL, NULL, 0, NULL }
   86 };
   87 
   88 DECLARE_TYPE(DateFormatSymbols, t_dateformatsymbols, UObject,
   89              DateFormatSymbols, t_dateformatsymbols_init);
   90 
   91 /* DateFormat */
   92 
   93 class t_dateformat : public _wrapper {
   94 public:
   95     DateFormat *object;
   96 };
   97 
   98 static PyObject *t_dateformat_isLenient(t_dateformat *self);
   99 static PyObject *t_dateformat_setLenient(t_dateformat *self, PyObject *arg);
  100 static PyObject *t_dateformat_format(t_dateformat *self, PyObject *args);
  101 static PyObject *t_dateformat_parse(t_dateformat *self, PyObject *args);
  102 static PyObject *t_dateformat_getCalendar(t_dateformat *self);
  103 static PyObject *t_dateformat_setCalendar(t_dateformat *self, PyObject *arg);
  104 static PyObject *t_dateformat_getNumberFormat(t_dateformat *self);
  105 static PyObject *t_dateformat_setNumberFormat(t_dateformat *self, PyObject *arg);
  106 static PyObject *t_dateformat_getTimeZone(t_dateformat *self);
  107 static PyObject *t_dateformat_setTimeZone(t_dateformat *self, PyObject *arg);
  108 static PyObject *t_dateformat_createInstance(PyTypeObject *type);
  109 static PyObject *t_dateformat_createTimeInstance(PyTypeObject *type,
  110                                                  PyObject *args);
  111 static PyObject *t_dateformat_createDateInstance(PyTypeObject *type,
  112                                                  PyObject *args);
  113 static PyObject *t_dateformat_createDateTimeInstance(PyTypeObject *type,
  114                                                      PyObject *args);
  115 static PyObject *t_dateformat_getAvailableLocales(PyTypeObject *type);
  116 
  117 static PyMethodDef t_dateformat_methods[] = {
  118     DECLARE_METHOD(t_dateformat, isLenient, METH_NOARGS),
  119     DECLARE_METHOD(t_dateformat, setLenient, METH_O),
  120     DECLARE_METHOD(t_dateformat, format, METH_VARARGS),
  121     DECLARE_METHOD(t_dateformat, parse, METH_VARARGS),
  122     DECLARE_METHOD(t_dateformat, getCalendar, METH_NOARGS),
  123     DECLARE_METHOD(t_dateformat, setCalendar, METH_O),
  124     DECLARE_METHOD(t_dateformat, getNumberFormat, METH_NOARGS),
  125     DECLARE_METHOD(t_dateformat, setNumberFormat, METH_O),
  126     DECLARE_METHOD(t_dateformat, getTimeZone, METH_NOARGS),
  127     DECLARE_METHOD(t_dateformat, setTimeZone, METH_O),
  128     DECLARE_METHOD(t_dateformat, createInstance, METH_NOARGS | METH_CLASS),
  129     DECLARE_METHOD(t_dateformat, createTimeInstance, METH_VARARGS | METH_CLASS),
  130     DECLARE_METHOD(t_dateformat, createDateInstance, METH_VARARGS | METH_CLASS),
  131     DECLARE_METHOD(t_dateformat, createDateTimeInstance, METH_VARARGS | METH_CLASS),
  132     DECLARE_METHOD(t_dateformat, getAvailableLocales, METH_NOARGS | METH_CLASS),
  133     { NULL, NULL, 0, NULL }
  134 };
  135 
  136 DECLARE_TYPE(DateFormat, t_dateformat, Format, DateFormat, abstract_init);
  137 
  138 /* SimpleDateFormat */
  139 
  140 class t_simpledateformat : public _wrapper {
  141 public:
  142     SimpleDateFormat *object;
  143 };
  144 
  145 static int t_simpledateformat_init(t_simpledateformat *self,
  146                                    PyObject *args, PyObject *kwds);
  147 static PyObject *t_simpledateformat_toPattern(t_simpledateformat *self,
  148                                               PyObject *args);
  149 static PyObject *t_simpledateformat_toLocalizedPattern(t_simpledateformat *self,
  150                                                        PyObject *args);
  151 static PyObject *t_simpledateformat_applyPattern(t_simpledateformat *self,
  152                                                  PyObject *arg);
  153 static PyObject *t_simpledateformat_applyLocalizedPattern(t_simpledateformat *self, PyObject *arg);
  154 static PyObject *t_simpledateformat_get2DigitYearStart(t_simpledateformat *self);
  155 static PyObject *t_simpledateformat_set2DigitYearStart(t_simpledateformat *self,
  156                                                        PyObject *arg);
  157 static PyObject *t_simpledateformat_getDateFormatSymbols(t_simpledateformat *self);
  158 static PyObject *t_simpledateformat_setDateFormatSymbols(t_simpledateformat *self,
  159                                                          PyObject *arg);
  160 
  161 static PyMethodDef t_simpledateformat_methods[] = {
  162     DECLARE_METHOD(t_simpledateformat, toPattern, METH_VARARGS),
  163     DECLARE_METHOD(t_simpledateformat, toLocalizedPattern, METH_VARARGS),
  164     DECLARE_METHOD(t_simpledateformat, applyPattern, METH_O),
  165     DECLARE_METHOD(t_simpledateformat, applyLocalizedPattern, METH_O),
  166     DECLARE_METHOD(t_simpledateformat, get2DigitYearStart, METH_NOARGS),
  167     DECLARE_METHOD(t_simpledateformat, set2DigitYearStart, METH_O),
  168     DECLARE_METHOD(t_simpledateformat, getDateFormatSymbols, METH_NOARGS),
  169     DECLARE_METHOD(t_simpledateformat, setDateFormatSymbols, METH_O),
  170     { NULL, NULL, 0, NULL }
  171 };
  172 
  173 DECLARE_TYPE(SimpleDateFormat, t_simpledateformat, DateFormat,
  174              SimpleDateFormat, t_simpledateformat_init);
  175 
  176 PyObject *wrap_DateFormat(DateFormat *format)
  177 {
  178     if (format->getDynamicClassID() == SimpleDateFormat::getStaticClassID())
  179         return wrap_SimpleDateFormat((SimpleDateFormat *) format, T_OWNED);
  180 
  181     return wrap_DateFormat(format, T_OWNED);
  182 }
  183 
  184 
  185 /* DateFormatSymbols */
  186 
  187 static int t_dateformatsymbols_init(t_dateformatsymbols *self,
  188                                     PyObject *args, PyObject *kwds)
  189 {
  190     UnicodeString _u;
  191     Locale *locale;
  192     DateFormatSymbols *dfs;
  193     char *type;
  194 
  195     switch (PyTuple_Size(args)) {
  196       case 0:
  197         INT_STATUS_CALL(dfs = new DateFormatSymbols(status));
  198         self->object = dfs;
  199         self->flags = T_OWNED;
  200         break;
  201       case 1:
  202         if (!parseArgs(args, "P", TYPE_CLASSID(Locale), &locale))
  203         {
  204             INT_STATUS_CALL(dfs = new DateFormatSymbols(*locale, status));
  205             self->object = dfs;
  206             self->flags = T_OWNED;
  207             break;
  208         }
  209         if (!parseArgs(args, "c", &type))
  210         {
  211             INT_STATUS_CALL(dfs = new DateFormatSymbols(type, status));
  212             self->object = dfs;
  213             self->flags = T_OWNED;
  214             break;
  215         }
  216         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  217         return -1;
  218       case 2:
  219         if (!parseArgs(args, "Pc", TYPE_CLASSID(Locale),
  220                        &locale, &type))
  221         {
  222             INT_STATUS_CALL(dfs = new DateFormatSymbols(*locale, type, status));
  223             self->object = dfs;
  224             self->flags = T_OWNED;
  225             break;
  226         }
  227         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  228         return -1;
  229       default:
  230         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  231         return -1;
  232     }
  233         
  234     if (self->object)
  235         return 0;
  236 
  237     return -1;
  238 }
  239 
  240 static PyObject *fromUnicodeStringArray(const UnicodeString *strings,
  241                                         int len, int dispose)
  242 {
  243     PyObject *list = PyList_New(len);
  244     
  245     for (int i = 0; i < len; i++) {
  246         UnicodeString *u = (UnicodeString *) (strings + i);
  247         PyList_SET_ITEM(list, i, PyUnicode_FromUnicodeString(u));
  248     }
  249 
  250     if (dispose)
  251         delete strings;
  252 
  253     return list;
  254 }
  255 
  256 static PyObject *t_dateformatsymbols_getEras(t_dateformatsymbols *self)
  257 {
  258     int len;
  259     const UnicodeString *eras = self->object->getEras(len);
  260 
  261     return fromUnicodeStringArray(eras, len, 0);
  262 }
  263 
  264 static PyObject *t_dateformatsymbols_setEras(t_dateformatsymbols *self,
  265                                              PyObject *arg)
  266 {
  267     UnicodeString *eras;
  268     int len;
  269 
  270     if (!parseArg(arg, "T", &eras, &len))
  271     {
  272         self->object->setEras(eras, len);
  273         delete[] eras; /* dtfmtsym.cpp code duplicates it */
  274         Py_RETURN_NONE;
  275     }
  276 
  277     return PyErr_SetArgsError((PyObject *) self, "setEras", arg);
  278 }
  279 
  280 static PyObject *t_dateformatsymbols_getMonths(t_dateformatsymbols *self,
  281                                                PyObject *args)
  282 {
  283     int len;
  284     const UnicodeString *months;
  285     DateFormatSymbols::DtContextType context;
  286     DateFormatSymbols::DtWidthType width;
  287 
  288     switch (PyTuple_Size(args)) {
  289       case 0:
  290         months = self->object->getMonths(len);
  291         return fromUnicodeStringArray(months, len, 0);
  292       case 2:
  293         if (!parseArgs(args, "ii", &context, &width))
  294         {
  295             months = self->object->getMonths(len, context, width);
  296             return fromUnicodeStringArray(months, len, 0);
  297         }
  298         break;
  299     }
  300             
  301     return PyErr_SetArgsError((PyObject *) self, "getMonths", args);
  302 }
  303 
  304 static PyObject *t_dateformatsymbols_setMonths(t_dateformatsymbols *self,
  305                                                PyObject *arg)
  306 {
  307     UnicodeString *months;
  308     int len;
  309 
  310     if (!parseArg(arg, "T", &months, &len))
  311     {
  312         self->object->setMonths(months, len);
  313         delete[] months; /* dtfmtsym.cpp code duplicates it */
  314         Py_RETURN_NONE;
  315     }
  316 
  317     return PyErr_SetArgsError((PyObject *) self, "setMonths", arg);
  318 }
  319 
  320 static PyObject *t_dateformatsymbols_getShortMonths(t_dateformatsymbols *self)
  321 {
  322     int len;
  323     const UnicodeString *months = self->object->getShortMonths(len);
  324 
  325     return fromUnicodeStringArray(months, len, 0);
  326 }
  327 
  328 static PyObject *t_dateformatsymbols_setShortMonths(t_dateformatsymbols *self,
  329                                                     PyObject *arg)
  330 {
  331     UnicodeString *months;
  332     int len;
  333 
  334     if (!parseArg(arg, "T", &months, &len))
  335     {
  336         self->object->setShortMonths(months, len);
  337         delete[] months; /* dtfmtsym.cpp code duplicates it */
  338         Py_RETURN_NONE;
  339     }
  340 
  341     return PyErr_SetArgsError((PyObject *) self, "setShortMonths", arg);
  342 }
  343 
  344 static PyObject *t_dateformatsymbols_getWeekdays(t_dateformatsymbols *self,
  345                                                  PyObject *args)
  346 {
  347     int len;
  348     const UnicodeString *weekdays;
  349     DateFormatSymbols::DtContextType context;
  350     DateFormatSymbols::DtWidthType width;
  351 
  352     switch (PyTuple_Size(args)) {
  353       case 0:
  354         weekdays = self->object->getWeekdays(len);
  355         return fromUnicodeStringArray(weekdays, len, 0);
  356       case 2:
  357         if (!parseArgs(args, "ii", &context, &width))
  358         {
  359             weekdays = self->object->getWeekdays(len, context, width);
  360             return fromUnicodeStringArray(weekdays, len, 0);
  361         }
  362         break;
  363     }
  364             
  365     return PyErr_SetArgsError((PyObject *) self, "getWeekdays", args);
  366 }
  367 
  368 static PyObject *t_dateformatsymbols_setWeekdays(t_dateformatsymbols *self,
  369                                                  PyObject *arg)
  370 {
  371     UnicodeString *weekdays;
  372     int len;
  373 
  374     if (!parseArg(arg, "T", &weekdays, &len))
  375     {
  376         self->object->setWeekdays(weekdays, len);
  377         delete[] weekdays; /* dtfmtsym.cpp code duplicates it */
  378         Py_RETURN_NONE;
  379     }
  380 
  381     return PyErr_SetArgsError((PyObject *) self, "setWeekdays", arg);
  382 }
  383 
  384 static PyObject *t_dateformatsymbols_getShortWeekdays(t_dateformatsymbols *self)
  385 {
  386     int len;
  387     const UnicodeString *months = self->object->getShortWeekdays(len);
  388 
  389     return fromUnicodeStringArray(months, len, 0);
  390 }
  391 
  392 static PyObject *t_dateformatsymbols_setShortWeekdays(t_dateformatsymbols *self,
  393                                                       PyObject *arg)
  394 {
  395     UnicodeString *weekdays;
  396     int len;
  397 
  398     if (!parseArg(arg, "T", &weekdays, &len))
  399     {
  400         self->object->setShortWeekdays(weekdays, len);
  401         delete[] weekdays; /* dtfmtsym.cpp code duplicates it */
  402         Py_RETURN_NONE;
  403     }
  404 
  405     return PyErr_SetArgsError((PyObject *) self, "setShortWeekdays", arg);
  406 }
  407 
  408 static PyObject *t_dateformatsymbols_getAmPmStrings(t_dateformatsymbols *self)
  409 {
  410     int len;
  411     const UnicodeString *strings = self->object->getAmPmStrings(len);
  412 
  413     return fromUnicodeStringArray(strings, len, 0);
  414 }
  415 
  416 static PyObject *t_dateformatsymbols_setAmPmStrings(t_dateformatsymbols *self,
  417                                                     PyObject *arg)
  418 {
  419     UnicodeString *strings;
  420     int len;
  421 
  422     if (!parseArg(arg, "T", &strings, &len))
  423     {
  424         self->object->setAmPmStrings(strings, len);
  425         delete[] strings; /* dtfmtsym.cpp code duplicates it */
  426         Py_RETURN_NONE;
  427     }
  428 
  429     return PyErr_SetArgsError((PyObject *) self, "setAmPmStrings", arg);
  430 }
  431 
  432 static PyObject *t_dateformatsymbols_richcmp(t_dateformatsymbols *self,
  433                                              PyObject *arg, int op)
  434 {
  435     int b = 0;
  436     DateFormatSymbols *dfs;
  437 
  438     if (!parseArg(arg, "P", TYPE_CLASSID(DateFormatSymbols), &dfs))
  439     {
  440         switch (op) {
  441           case Py_EQ:
  442           case Py_NE:
  443             b = *self->object == *dfs;
  444             if (op == Py_EQ)
  445                 Py_RETURN_BOOL(b);
  446             Py_RETURN_BOOL(!b);
  447           case Py_LT:
  448           case Py_LE:
  449           case Py_GT:
  450           case Py_GE:
  451             PyErr_SetNone(PyExc_NotImplementedError);
  452             return NULL;
  453         }
  454     }
  455 
  456     return PyErr_SetArgsError((PyObject *) self, "__richcmp__", arg);
  457 }
  458         
  459 static PyObject *t_dateformatsymbols_getLocalPatternChars(t_dateformatsymbols *self, PyObject *args)
  460 {
  461     UnicodeString *u;
  462     UnicodeString _u;
  463 
  464     switch (PyTuple_Size(args)) {
  465       case 0:
  466         self->object->getLocalPatternChars(_u);
  467         return PyUnicode_FromUnicodeString(&_u);
  468       case 1:
  469         if (!parseArgs(args, "U", &u))
  470         {
  471             self->object->getLocalPatternChars(*u);
  472             Py_RETURN_ARG(args, 0);
  473         }
  474         break;
  475     }
  476 
  477     return PyErr_SetArgsError((PyObject *) self, "getLocalPatternChars", args);
  478 }
  479 
  480 static PyObject *t_dateformatsymbols_setLocalPatternChars(t_dateformatsymbols *self, PyObject *arg)
  481 {
  482     UnicodeString *u;
  483     UnicodeString _u;
  484 
  485     if (!parseArg(arg, "S", &u, &_u))
  486     {
  487         self->object->setLocalPatternChars(*u);
  488         Py_RETURN_NONE;
  489     }
  490 
  491     return PyErr_SetArgsError((PyObject *) self, "setLocalPatternChars", arg);
  492 }
  493 
  494 static PyObject *t_dateformatsymbols_getLocale(t_dateformatsymbols *self,
  495                                                PyObject *args)
  496 {
  497     ULocDataLocaleType type;
  498     Locale locale;
  499 
  500     switch (PyTuple_Size(args)) {
  501       case 0:
  502         STATUS_CALL(locale = self->object->getLocale(ULOC_VALID_LOCALE,
  503                                                      status));
  504         return wrap_Locale(locale);
  505       case 1:
  506         if (!parseArgs(args, "i", &type))
  507         {
  508             STATUS_CALL(locale = self->object->getLocale(type, status));
  509             return wrap_Locale(locale);
  510         }
  511         break;
  512     }
  513 
  514     return PyErr_SetArgsError((PyObject *) self, "getLocale", args);
  515 }
  516 
  517 
  518 /* DateFormat */
  519 
  520 static PyObject *t_dateformat_isLenient(t_dateformat *self)
  521 {
  522     int b = self->object->isLenient();
  523     Py_RETURN_BOOL(b);
  524 }
  525 
  526 static PyObject *t_dateformat_setLenient(t_dateformat *self, PyObject *arg)
  527 {
  528     int b;
  529 
  530     if (!parseArg(arg, "b", &b))
  531     {
  532         self->object->setLenient(b);
  533         Py_RETURN_NONE;
  534     }
  535 
  536     return PyErr_SetArgsError((PyObject *) self, "setLenient", arg);
  537 }
  538 
  539 static PyObject *t_dateformat_format(t_dateformat *self, PyObject *args)
  540 {
  541     UDate date;
  542     Calendar *calendar;
  543     UnicodeString *u;
  544     UnicodeString _u;
  545     FieldPosition *fp;
  546 
  547     switch (PyTuple_Size(args)) {
  548       case 1:
  549         if (!parseArgs(args, "D", &date))
  550         {
  551             self->object->format(date, _u);
  552             return PyUnicode_FromUnicodeString(&_u);
  553         }
  554         break;
  555       case 2:
  556         if (!parseArgs(args, "DP", TYPE_CLASSID(FieldPosition),
  557                        &date, &fp))
  558         {
  559             self->object->format(date, _u, *fp);
  560             return PyUnicode_FromUnicodeString(&_u);
  561         }
  562         if (!parseArgs(args, "PP",
  563                        TYPE_ID(Calendar), TYPE_CLASSID(FieldPosition),
  564                        &calendar, &fp))
  565         {
  566             self->object->format(*calendar, _u, *fp);
  567             return PyUnicode_FromUnicodeString(&_u);
  568         }
  569         if (!parseArgs(args, "DU", &date, &u))
  570         {
  571             self->object->format(date, *u);
  572             Py_RETURN_ARG(args, 1);
  573         }
  574         break;
  575       case 3:
  576         if (!parseArgs(args, "DUP", TYPE_CLASSID(FieldPosition),
  577                        &date, &u, &fp))
  578         {
  579             self->object->format(date, *u, *fp);
  580             Py_RETURN_ARG(args, 1);
  581         }
  582         if (!parseArgs(args, "PUP",
  583                        TYPE_ID(Calendar), TYPE_CLASSID(FieldPosition),
  584                        &calendar, &u, &fp))
  585         {
  586             self->object->format(*calendar, *u, *fp);
  587             Py_RETURN_ARG(args, 1);
  588         }
  589         break;
  590     }
  591 
  592     return t_format_format((t_format *) self, args);
  593 }
  594 
  595 static PyObject *t_dateformat_parse(t_dateformat *self, PyObject *args)
  596 {
  597     UnicodeString *u;
  598     UnicodeString _u;
  599     Calendar *calendar;
  600     ParsePosition *pp;
  601     UDate date;
  602 
  603     switch (PyTuple_Size(args)) {
  604       case 1:
  605         if (!parseArgs(args, "S", &u, &_u))
  606         {
  607             STATUS_CALL(date = self->object->parse(*u, status));
  608             return PyFloat_FromDouble(date / 1000.0);
  609         }
  610         break;
  611       case 2:
  612         if (!parseArgs(args, "SP", TYPE_CLASSID(ParsePosition),
  613                        &u, &_u, &pp))
  614         {
  615             pp->setErrorIndex(-1);
  616             STATUS_CALL(date = self->object->parse(*u, *pp));
  617             if (pp->getErrorIndex() == -1)
  618                 Py_RETURN_NONE;
  619             return PyFloat_FromDouble(date / 1000.0);
  620         }
  621         break;
  622       case 3:
  623         if (!parseArgs(args, "SPP",
  624                        TYPE_ID(Calendar), TYPE_CLASSID(ParsePosition),
  625                        &u, &_u, &calendar, &pp))
  626         {
  627             pp->setErrorIndex(-1);
  628             STATUS_CALL(self->object->parse(*u, *calendar, *pp));
  629             Py_RETURN_NONE;
  630         }
  631         break;
  632     }
  633 
  634     return PyErr_SetArgsError((PyObject *) self, "parse", args);
  635 }
  636 
  637 static PyObject *t_dateformat_getCalendar(t_dateformat *self)
  638 {
  639     return wrap_Calendar(self->object->getCalendar()->clone(), T_OWNED);
  640 }
  641 
  642 static PyObject *t_dateformat_setCalendar(t_dateformat *self, PyObject *arg)
  643 {
  644     Calendar *calendar;
  645 
  646     if (!parseArg(arg, "P", TYPE_ID(Calendar), &calendar))
  647     {
  648         self->object->setCalendar(*calendar);
  649         Py_RETURN_NONE;
  650     }
  651 
  652     return PyErr_SetArgsError((PyObject *) self, "setCalendar", arg);
  653 }
  654 
  655 static PyObject *t_dateformat_getNumberFormat(t_dateformat *self)
  656 {
  657     return wrap_NumberFormat((NumberFormat *) self->object->getNumberFormat()->clone(), T_OWNED);
  658 }
  659 
  660 static PyObject *t_dateformat_setNumberFormat(t_dateformat *self, PyObject *arg)
  661 {
  662     NumberFormat *format;
  663 
  664     if (!parseArg(arg, "P", TYPE_CLASSID(NumberFormat), &format))
  665     {
  666         self->object->setNumberFormat(*format);
  667         Py_RETURN_NONE;
  668     }
  669 
  670     return PyErr_SetArgsError((PyObject *) self, "setNumberFormat", arg);
  671 }
  672 
  673 static PyObject *t_dateformat_getTimeZone(t_dateformat *self)
  674 {
  675     return wrap_TimeZone(self->object->getTimeZone());
  676 }
  677 
  678 static PyObject *t_dateformat_setTimeZone(t_dateformat *self, PyObject *arg)
  679 {
  680     TimeZone *tz;
  681 
  682     if (!parseArg(arg, "P", TYPE_CLASSID(TimeZone), &tz))
  683     {
  684         self->object->setTimeZone(*tz);
  685         Py_RETURN_NONE;
  686     }
  687 
  688     return PyErr_SetArgsError((PyObject *) self, "setTimeZone", arg);
  689 }
  690 
  691 static PyObject *t_dateformat_createInstance(PyTypeObject *type)
  692 {
  693     return wrap_DateFormat(DateFormat::createInstance());
  694 }
  695 
  696 static PyObject *t_dateformat_createTimeInstance(PyTypeObject *type,
  697                                                  PyObject *args)
  698 {
  699     DateFormat::EStyle style;
  700     Locale *locale;
  701 
  702     switch (PyTuple_Size(args)) {
  703       case 1:
  704         if (!parseArgs(args, "i", &style))
  705             return wrap_DateFormat(DateFormat::createTimeInstance(style));
  706         break;
  707       case 2:
  708         if (!parseArgs(args, "iP", TYPE_CLASSID(Locale),
  709                        &style, &locale))
  710             return wrap_DateFormat(DateFormat::createTimeInstance(style, *locale));
  711         break;
  712     }
  713 
  714     return PyErr_SetArgsError(type, "createTimeInstance", args);
  715 }
  716 
  717 static PyObject *t_dateformat_createDateInstance(PyTypeObject *type,
  718                                                  PyObject *args)
  719 {
  720     DateFormat::EStyle style;
  721     Locale *locale;
  722 
  723     switch (PyTuple_Size(args)) {
  724       case 1:
  725         if (!parseArgs(args, "i", &style))
  726             return wrap_DateFormat(DateFormat::createDateInstance(style));
  727         break;
  728       case 2:
  729         if (!parseArgs(args, "iP", TYPE_CLASSID(Locale),
  730                        &style, &locale))
  731             return wrap_DateFormat(DateFormat::createDateInstance(style, *locale));
  732         break;
  733     }
  734 
  735     return PyErr_SetArgsError(type, "createDateInstance", args);
  736 }
  737 
  738 static PyObject *t_dateformat_createDateTimeInstance(PyTypeObject *type,
  739                                                      PyObject *args)
  740 {
  741     DateFormat::EStyle dateStyle, timeStyle;
  742     Locale *locale;
  743 
  744     switch (PyTuple_Size(args)) {
  745       case 1:
  746         if (!parseArgs(args, "i", &dateStyle))
  747             return wrap_DateFormat(DateFormat::createDateTimeInstance(dateStyle));
  748         break;
  749       case 2:
  750         if (!parseArgs(args, "ii", &dateStyle, &timeStyle))
  751             return wrap_DateFormat(DateFormat::createDateTimeInstance(dateStyle, timeStyle));
  752         break;
  753       case 3:
  754         if (!parseArgs(args, "iiP", TYPE_CLASSID(Locale),
  755                        &dateStyle, &timeStyle, &locale))
  756             return wrap_DateFormat(DateFormat::createDateTimeInstance(dateStyle, timeStyle, *locale));
  757         break;
  758     }
  759 
  760     return PyErr_SetArgsError(type, "createDateTimeInstance", args);
  761 }
  762 
  763 static PyObject *t_dateformat_getAvailableLocales(PyTypeObject *type)
  764 {
  765     int count;
  766     const Locale *locales = DateFormat::getAvailableLocales(count);
  767     PyObject *dict = PyDict_New();
  768 
  769     for (int32_t i = 0; i < count; i++) {
  770         Locale *locale = (Locale *) locales + i;
  771         PyObject *obj = wrap_Locale(locale, 0);
  772         PyDict_SetItemString(dict, locale->getName(), obj);
  773     Py_DECREF(obj);
  774     }
  775 
  776     return dict;
  777 }
  778 
  779 
  780 /* SimpleDateFormat */
  781 
  782 static int t_simpledateformat_init(t_simpledateformat *self,
  783                                    PyObject *args, PyObject *kwds)
  784 {
  785     UnicodeString *u;
  786     UnicodeString _u;
  787     Locale *locale;
  788     DateFormatSymbols *dfs;
  789     SimpleDateFormat *format;
  790 
  791     switch (PyTuple_Size(args)) {
  792       case 0:
  793         INT_STATUS_CALL(format = new SimpleDateFormat(status));
  794         self->object = format;
  795         self->flags = T_OWNED;
  796         break;
  797       case 1:
  798         if (!parseArgs(args, "S", &u, &_u))
  799         {
  800             INT_STATUS_CALL(format = new SimpleDateFormat(*u, status));
  801             self->object = format;
  802             self->flags = T_OWNED;
  803             break;
  804         }
  805         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  806         return -1;
  807       case 2:
  808         if (!parseArgs(args, "SP", TYPE_CLASSID(Locale),
  809                        &u, &_u, &locale))
  810         {
  811             INT_STATUS_CALL(format = new SimpleDateFormat(*u, *locale, status));
  812             self->object = format;
  813             self->flags = T_OWNED;
  814             break;
  815         }
  816         if (!parseArgs(args, "SP", TYPE_CLASSID(DateFormatSymbols),
  817                        &u, &_u, &dfs))
  818         {
  819             INT_STATUS_CALL(format = new SimpleDateFormat(*u, *dfs, status));
  820             self->object = format;
  821             self->flags = T_OWNED;
  822             break;
  823         }
  824         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  825         return -1;
  826       default:
  827         PyErr_SetArgsError((PyObject *) self, "__init__", args);
  828         return -1;
  829     }
  830         
  831     if (self->object)
  832         return 0;
  833 
  834     return -1;
  835 }
  836 
  837 static PyObject *t_simpledateformat_toPattern(t_simpledateformat *self,
  838                                               PyObject *args)
  839 {
  840     UnicodeString *u;
  841     UnicodeString _u;
  842 
  843     switch (PyTuple_Size(args)) {
  844       case 0:
  845         self->object->toPattern(_u);
  846         return PyUnicode_FromUnicodeString(&_u);
  847       case 1:
  848         if (!parseArgs(args, "U", &u))
  849         {
  850             self->object->toPattern(*u);
  851             Py_RETURN_ARG(args, 0);
  852         }
  853         break;
  854     }
  855 
  856     return PyErr_SetArgsError((PyObject *) self, "toPattern", args);
  857 }
  858 
  859 static PyObject *t_simpledateformat_toLocalizedPattern(t_simpledateformat *self,
  860                                                        PyObject *args)
  861 {
  862     UnicodeString *u;
  863     UnicodeString _u;
  864 
  865     switch (PyTuple_Size(args)) {
  866       case 0:
  867         STATUS_CALL(self->object->toLocalizedPattern(_u, status));
  868         return PyUnicode_FromUnicodeString(&_u);
  869       case 1:
  870         if (!parseArgs(args, "U", &u))
  871         {
  872             STATUS_CALL(self->object->toLocalizedPattern(*u, status));
  873             Py_RETURN_ARG(args, 0);
  874         }
  875         break;
  876     }
  877 
  878     return PyErr_SetArgsError((PyObject *) self, "toLocalizedPattern", args);
  879 }
  880 
  881 static PyObject *t_simpledateformat_applyPattern(t_simpledateformat *self,
  882                                                  PyObject *arg)
  883 {
  884     UnicodeString *u;
  885     UnicodeString _u;
  886 
  887     if (!parseArg(arg, "S", &u, &_u))
  888     {
  889         self->object->applyPattern(*u);
  890         Py_RETURN_NONE;
  891     }
  892 
  893     return PyErr_SetArgsError((PyObject *) self, "applyPattern", arg);
  894 }
  895 
  896 static PyObject *t_simpledateformat_applyLocalizedPattern(t_simpledateformat *self, PyObject *arg)
  897 {
  898     UnicodeString *u;
  899     UnicodeString _u;
  900 
  901     if (!parseArg(arg, "S", &u, &_u))
  902     {
  903         STATUS_CALL(self->object->applyLocalizedPattern(*u, status));
  904         Py_RETURN_NONE;
  905     }
  906 
  907     return PyErr_SetArgsError((PyObject *) self, "applyLocalizedPattern", arg);
  908 }
  909 
  910 static PyObject *t_simpledateformat_get2DigitYearStart(t_simpledateformat *self)
  911 {
  912     UDate date;
  913 
  914     STATUS_CALL(date = self->object->get2DigitYearStart(status));
  915     return PyFloat_FromDouble(date / 1000.0);
  916 }
  917 
  918 static PyObject *t_simpledateformat_set2DigitYearStart(t_simpledateformat *self,
  919                                                        PyObject *arg)
  920 {
  921     UDate date;
  922 
  923     if (!parseArg(arg, "D", &date))
  924     {
  925         STATUS_CALL(self->object->set2DigitYearStart(date, status));
  926         Py_RETURN_NONE;
  927     }
  928 
  929     return PyErr_SetArgsError((PyObject *) self, "set2DigitYearStart", arg);
  930 }
  931 
  932 static PyObject *t_simpledateformat_getDateFormatSymbols(t_simpledateformat *self)
  933 {
  934     return wrap_DateFormatSymbols(new DateFormatSymbols(*self->object->getDateFormatSymbols()), T_OWNED);
  935 }
  936 
  937 static PyObject *t_simpledateformat_setDateFormatSymbols(t_simpledateformat *self, PyObject *arg)
  938 {
  939     DateFormatSymbols *dfs;
  940 
  941     if (!parseArg(arg, "P", TYPE_CLASSID(DateFormatSymbols), &dfs))
  942     {
  943         self->object->setDateFormatSymbols(*dfs);
  944         Py_RETURN_NONE;
  945     }
  946 
  947     return PyErr_SetArgsError((PyObject *) self, "setDateFormatSymbols", arg);
  948 }
  949 
  950 static PyObject *t_simpledateformat_str(t_simpledateformat *self)
  951 {
  952     UnicodeString u;
  953 
  954     self->object->toPattern(u);
  955     return PyUnicode_FromUnicodeString(&u);
  956 }
  957 
  958 
  959 void _init_dateformat(PyObject *m)
  960 {
  961     DateFormatSymbolsType.tp_richcompare =
  962         (richcmpfunc) t_dateformatsymbols_richcmp;
  963     SimpleDateFormatType.tp_str = (reprfunc) t_simpledateformat_str;
  964 
  965     REGISTER_TYPE(DateFormatSymbols, m);
  966     INSTALL_TYPE(DateFormat, m);
  967     REGISTER_TYPE(SimpleDateFormat, m);
  968 
  969     INSTALL_STATIC_INT(DateFormatSymbols, FORMAT);
  970     INSTALL_STATIC_INT(DateFormatSymbols, STANDALONE);
  971 
  972     INSTALL_STATIC_INT(DateFormatSymbols, WIDE);
  973     INSTALL_STATIC_INT(DateFormatSymbols, ABBREVIATED);
  974     INSTALL_STATIC_INT(DateFormatSymbols, NARROW);
  975 
  976     INSTALL_STATIC_INT(DateFormat, kNone);
  977     INSTALL_STATIC_INT(DateFormat, kFull);
  978     INSTALL_STATIC_INT(DateFormat, kLong);
  979     INSTALL_STATIC_INT(DateFormat, kMedium);
  980     INSTALL_STATIC_INT(DateFormat, kShort);
  981     INSTALL_STATIC_INT(DateFormat, kDateOffset);
  982     INSTALL_STATIC_INT(DateFormat, kDateTime);
  983     INSTALL_STATIC_INT(DateFormat, kDefault);
  984     INSTALL_STATIC_INT(DateFormat, FULL);
  985     INSTALL_STATIC_INT(DateFormat, LONG);
  986     INSTALL_STATIC_INT(DateFormat, MEDIUM);
  987     INSTALL_STATIC_INT(DateFormat, SHORT);
  988     INSTALL_STATIC_INT(DateFormat, DEFAULT);
  989     INSTALL_STATIC_INT(DateFormat, DATE_OFFSET);
  990     INSTALL_STATIC_INT(DateFormat, NONE);
  991     INSTALL_STATIC_INT(DateFormat, DATE_TIME);
  992 
  993     INSTALL_STATIC_INT(DateFormat, kEraField);
  994     INSTALL_STATIC_INT(DateFormat, kYearField);
  995     INSTALL_STATIC_INT(DateFormat, kMonthField);
  996     INSTALL_STATIC_INT(DateFormat, kDateField);
  997     INSTALL_STATIC_INT(DateFormat, kHourOfDay1Field);
  998     INSTALL_STATIC_INT(DateFormat, kHourOfDay0Field);
  999     INSTALL_STATIC_INT(DateFormat, kMinuteField);
 1000     INSTALL_STATIC_INT(DateFormat, kSecondField);
 1001     INSTALL_STATIC_INT(DateFormat, kMillisecondField);
 1002     INSTALL_STATIC_INT(DateFormat, kDayOfWeekField);
 1003     INSTALL_STATIC_INT(DateFormat, kDayOfYearField);
 1004     INSTALL_STATIC_INT(DateFormat, kDayOfWeekInMonthField);
 1005     INSTALL_STATIC_INT(DateFormat, kWeekOfYearField);
 1006     INSTALL_STATIC_INT(DateFormat, kWeekOfMonthField);
 1007     INSTALL_STATIC_INT(DateFormat, kAmPmField);
 1008     INSTALL_STATIC_INT(DateFormat, kHour1Field);
 1009     INSTALL_STATIC_INT(DateFormat, kHour0Field);
 1010     INSTALL_STATIC_INT(DateFormat, kTimezoneField);
 1011     INSTALL_STATIC_INT(DateFormat, kYearWOYField);
 1012     INSTALL_STATIC_INT(DateFormat, kDOWLocalField);
 1013     INSTALL_STATIC_INT(DateFormat, kExtendedYearField);
 1014     INSTALL_STATIC_INT(DateFormat, kJulianDayField);
 1015     INSTALL_STATIC_INT(DateFormat, kMillisecondsInDayField);
 1016     INSTALL_STATIC_INT(DateFormat, ERA_FIELD);
 1017     INSTALL_STATIC_INT(DateFormat, YEAR_FIELD);
 1018     INSTALL_STATIC_INT(DateFormat, MONTH_FIELD);
 1019     INSTALL_STATIC_INT(DateFormat, DATE_FIELD);
 1020     INSTALL_STATIC_INT(DateFormat, HOUR_OF_DAY1_FIELD);
 1021     INSTALL_STATIC_INT(DateFormat, HOUR_OF_DAY0_FIELD);
 1022     INSTALL_STATIC_INT(DateFormat, MINUTE_FIELD);
 1023     INSTALL_STATIC_INT(DateFormat, SECOND_FIELD);
 1024     INSTALL_STATIC_INT(DateFormat, MILLISECOND_FIELD);
 1025     INSTALL_STATIC_INT(DateFormat, DAY_OF_WEEK_FIELD);
 1026     INSTALL_STATIC_INT(DateFormat, DAY_OF_YEAR_FIELD);
 1027     INSTALL_STATIC_INT(DateFormat, DAY_OF_WEEK_IN_MONTH_FIELD);
 1028     INSTALL_STATIC_INT(DateFormat, WEEK_OF_YEAR_FIELD);
 1029     INSTALL_STATIC_INT(DateFormat, WEEK_OF_MONTH_FIELD);
 1030     INSTALL_STATIC_INT(DateFormat, AM_PM_FIELD);
 1031     INSTALL_STATIC_INT(DateFormat, HOUR1_FIELD);
 1032     INSTALL_STATIC_INT(DateFormat, HOUR0_FIELD);
 1033     INSTALL_STATIC_INT(DateFormat, TIMEZONE_FIELD);
 1034 }