@@ -178,6 +178,7 @@ int is_long_year(int year) {
178
178
typedef struct {
179
179
PyObject_HEAD
180
180
int offset ;
181
+ char * tzname ;
181
182
} FixedOffset ;
182
183
183
184
/*
@@ -186,10 +187,16 @@ typedef struct {
186
187
*/
187
188
static int FixedOffset_init (FixedOffset * self , PyObject * args , PyObject * kwargs ) {
188
189
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 ))
190
195
return -1 ;
191
196
192
197
self -> offset = offset ;
198
+ self -> tzname = tzname ;
199
+
193
200
return 0 ;
194
201
}
195
202
@@ -217,6 +224,10 @@ static PyObject *FixedOffset_dst(FixedOffset *self, PyObject *args) {
217
224
* return "%s%d:%d" % (sign, self.offset / 60, self.offset % 60)
218
225
*/
219
226
static PyObject * FixedOffset_tzname (FixedOffset * self , PyObject * args ) {
227
+ if (self -> tzname != NULL ) {
228
+ return PyUnicode_FromString (self -> tzname );
229
+ }
230
+
220
231
char tzname_ [7 ] = {0 };
221
232
char sign = '+' ;
222
233
int offset = self -> offset ;
@@ -292,16 +303,17 @@ static PyTypeObject FixedOffset_type = {
292
303
* Skip overhead of calling PyObject_New and PyObject_Init.
293
304
* Directly allocate object.
294
305
*/
295
- static PyObject * new_fixed_offset_ex (int offset , PyTypeObject * type ) {
306
+ static PyObject * new_fixed_offset_ex (int offset , char * name , PyTypeObject * type ) {
296
307
FixedOffset * self = (FixedOffset * ) (type -> tp_alloc (type , 0 ));
297
308
298
309
if (self != NULL )
299
310
self -> offset = offset ;
311
+ self -> tzname = name ;
300
312
301
313
return (PyObject * ) self ;
302
314
}
303
315
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)
305
317
306
318
307
319
/*
@@ -455,6 +467,7 @@ typedef struct {
455
467
int microsecond ;
456
468
int offset ;
457
469
int has_offset ;
470
+ char * tzname ;
458
471
int years ;
459
472
int months ;
460
473
int weeks ;
@@ -487,6 +500,7 @@ Parsed* new_parsed() {
487
500
parsed -> microsecond = 0 ;
488
501
parsed -> offset = 0 ;
489
502
parsed -> has_offset = 0 ;
503
+ parsed -> tzname = NULL ;
490
504
491
505
parsed -> years = 0 ;
492
506
parsed -> months = 0 ;
@@ -585,7 +599,7 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
585
599
}
586
600
587
601
// Checks
588
- if (week > 53 || week > 52 && !is_long_year (parsed -> year )) {
602
+ if (week > 53 || ( week > 52 && !is_long_year (parsed -> year ) )) {
589
603
parsed -> error = PARSER_INVALID_WEEK_NUMBER ;
590
604
591
605
return NULL ;
@@ -850,6 +864,7 @@ Parsed* _parse_iso8601_datetime(char *str, Parsed *parsed) {
850
864
// Timezone
851
865
if (* c == 'Z' ) {
852
866
parsed -> has_offset = 1 ;
867
+ parsed -> tzname = "UTC" ;
853
868
c ++ ;
854
869
} else if (* c == '+' || * c == '-' ) {
855
870
tz_sign = 1 ;
@@ -1258,7 +1273,7 @@ PyObject* parse_iso8601(PyObject *self, PyObject *args) {
1258
1273
if (!parsed -> has_offset ) {
1259
1274
tzinfo = Py_BuildValue ("" );
1260
1275
} else {
1261
- tzinfo = new_fixed_offset (parsed -> offset );
1276
+ tzinfo = new_fixed_offset (parsed -> offset , parsed -> tzname );
1262
1277
}
1263
1278
1264
1279
obj = PyDateTimeAPI -> DateTime_FromDateAndTime (
0 commit comments