Skip to content

Commit 396e189

Browse files
committed
Fixes UTC conversion from python datetime to managed DateTime
1 parent 94694db commit 396e189

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
@@ -66,18 +66,18 @@ static Converter()
6666
timeSpanCtor = Runtime.PyObject_GetAttrString(dateTimeMod, "timedelta");
6767
if (timeSpanCtor == null) throw new PythonException();
6868

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

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

0 commit comments

Comments
 (0)