@@ -178,6 +178,7 @@ int is_long_year(int year) {
178178typedef struct {
179179 PyObject_HEAD
180180 int offset ;
181+ char * tzname ;
181182} FixedOffset ;
182183
183184/*
@@ -186,10 +187,16 @@ typedef struct {
186187*/
187188static int FixedOffset_init (FixedOffset * self , PyObject * args , PyObject * kwargs ) {
188189 int offset ;
189- if (!PyArg_ParseTuple (args , "i" , & offset ))
190+ char * tzname = NULL ;
191+
192+ static char * kwlist [] = {"offset" , "tzname" , NULL };
193+
194+ if (!PyArg_ParseTupleAndKeywords (args , kwargs , "i|s" , kwlist , & offset , & tzname ))
190195 return -1 ;
191196
192197 self -> offset = offset ;
198+ self -> tzname = tzname ;
199+
193200 return 0 ;
194201}
195202
@@ -217,6 +224,10 @@ static PyObject *FixedOffset_dst(FixedOffset *self, PyObject *args) {
217224 * return "%s%d:%d" % (sign, self.offset / 60, self.offset % 60)
218225 */
219226static PyObject * FixedOffset_tzname (FixedOffset * self , PyObject * args ) {
227+ if (self -> tzname != NULL ) {
228+ return PyUnicode_FromString (self -> tzname );
229+ }
230+
220231 char tzname_ [7 ] = {0 };
221232 char sign = '+' ;
222233 int offset = self -> offset ;
@@ -292,16 +303,17 @@ static PyTypeObject FixedOffset_type = {
292303 * Skip overhead of calling PyObject_New and PyObject_Init.
293304 * Directly allocate object.
294305 */
295- static PyObject * new_fixed_offset_ex (int offset , PyTypeObject * type ) {
306+ static PyObject * new_fixed_offset_ex (int offset , char * name , PyTypeObject * type ) {
296307 FixedOffset * self = (FixedOffset * ) (type -> tp_alloc (type , 0 ));
297308
298309 if (self != NULL )
299310 self -> offset = offset ;
311+ self -> tzname = name ;
300312
301313 return (PyObject * ) self ;
302314}
303315
304- #define new_fixed_offset (offset ) new_fixed_offset_ex(offset, &FixedOffset_type)
316+ #define new_fixed_offset (offset , name ) new_fixed_offset_ex(offset, name , &FixedOffset_type)
305317
306318
307319/*
@@ -455,6 +467,7 @@ typedef struct {
455467 int microsecond ;
456468 int offset ;
457469 int has_offset ;
470+ char * tzname ;
458471 int years ;
459472 int months ;
460473 int weeks ;
@@ -487,6 +500,7 @@ Parsed* new_parsed() {
487500 parsed -> microsecond = 0 ;
488501 parsed -> offset = 0 ;
489502 parsed -> has_offset = 0 ;
503+ parsed -> tzname = NULL ;
490504
491505 parsed -> years = 0 ;
492506 parsed -> months = 0 ;
@@ -585,7 +599,7 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
585599 }
586600
587601 // Checks
588- if (week > 53 || week > 52 && !is_long_year (parsed -> year )) {
602+ if (week > 53 || ( week > 52 && !is_long_year (parsed -> year ) )) {
589603 parsed -> error = PARSER_INVALID_WEEK_NUMBER ;
590604
591605 return NULL ;
@@ -850,6 +864,7 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
850864 // Timezone
851865 if (* c == 'Z' ) {
852866 parsed -> has_offset = 1 ;
867+ parsed -> tzname = "UTC" ;
853868 c ++ ;
854869 } else if (* c == '+' || * c == '-' ) {
855870 tz_sign = 1 ;
@@ -1258,7 +1273,7 @@ PyObject* parse_iso8601(PyObject *self, PyObject *args) {
12581273 if (!parsed -> has_offset ) {
12591274 tzinfo = Py_BuildValue ("" );
12601275 } else {
1261- tzinfo = new_fixed_offset (parsed -> offset );
1276+ tzinfo = new_fixed_offset (parsed -> offset , parsed -> tzname );
12621277 }
12631278
12641279 obj = PyDateTimeAPI -> DateTime_FromDateAndTime (
0 commit comments