Skip to content

Commit d2d12b3

Browse files
committed
Fixes UTC conversion from python datetime to managed DateTime
1 parent c355ab4 commit d2d12b3

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/runtime/converter.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ static Converter()
6565
timeSpanCtor = Runtime.PyObject_GetAttrString(dateTimeMod, "timedelta");
6666
if (timeSpanCtor == null) throw new PythonException();
6767

68-
IntPtr tzInfoMod = PythonEngine.ModuleFromString("custom_tzinfo",
69-
"from datetime import timedelta, tzinfo\n" +
70-
"class GMT(tzinfo):\n" +
71-
" def __init__(self, hours, minutes):\n" +
72-
" self.hours = hours\n" +
73-
" self.minutes = minutes\n" +
74-
" def utcoffset(self, dt):\n" +
75-
" return timedelta(hours=self.hours, minutes=self.minutes)\n" +
76-
" def tzname(self, dt):\n" +
77-
" return \"GMT {0:00}:{1:00}\".format(self.hours, self.minutes)\n" +
78-
" def dst (self, dt):\n" +
79-
" return timedelta(0)\n").Handle;
68+
IntPtr tzInfoMod = PythonEngine.ModuleFromString("custom_tzinfo", @"
69+
from datetime import timedelta, tzinfo
70+
class GMT(tzinfo):
71+
def __init__(self, hours, minutes):
72+
self.hours = hours
73+
self.minutes = minutes
74+
def utcoffset(self, dt):
75+
return timedelta(hours=self.hours, minutes=self.minutes)
76+
def tzname(self, dt):
77+
return f'GMT {self.hours:00}:{self.minutes:00}'
78+
def dst (self, dt):
79+
return timedelta(0)").Handle;
8080

8181
tzInfoCtor = Runtime.PyObject_GetAttrString(tzInfoMod, "GMT");
8282
if (tzInfoCtor == null) throw new PythonException();
@@ -951,7 +951,7 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
951951
goto type_error;
952952
}
953953
Runtime.XDecref(op);
954-
result = dt;
954+
result = sdt.EndsWith("+00:00") ? dt.ToUniversalTime() : dt;
955955
return true;
956956
}
957957

0 commit comments

Comments
 (0)