Skip to content

Commit 363b352

Browse files
committed
Remove tzinfo check in datetime conversion
1 parent 0678780 commit 363b352

File tree

2 files changed

+5
-35
lines changed

2 files changed

+5
-35
lines changed

src/embed_tests/TestConverter.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ public void ConvertDateTimeRoundTrip(DateTimeKind kind)
187187
Assert.AreEqual(datetime, result);
188188
}
189189

190-
[TestCase("", DateTimeKind.Unspecified)]
191-
[TestCase("America/New_York", DateTimeKind.Unspecified)]
192-
[TestCase("UTC", DateTimeKind.Utc)]
193-
public void ConvertDateTimeWithTimeZonePythonToCSharp(string timeZone, DateTimeKind expectedDateTimeKind)
190+
[TestCase("")]
191+
[TestCase("America/New_York")]
192+
[TestCase("UTC")]
193+
public void ConvertDateTimeWithTimeZonePythonToCSharp(string timeZone)
194194
{
195195
const int year = 2024;
196196
const int month = 2;
@@ -231,7 +231,6 @@ def GetNextDay(dateTime):
231231

232232
var expectedDateTime = new DateTime(year, month, day, hour, minute, second);
233233
Assert.AreEqual(expectedDateTime, managedDateTime);
234-
Assert.AreEqual(managedDateTime.Kind, expectedDateTimeKind);
235234
}
236235
}
237236

src/runtime/Converter.cs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,24 +1123,6 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec
11231123
var minute = Runtime.PyObject_GetAttrString(value, minutePtr);
11241124
var second = Runtime.PyObject_GetAttrString(value, secondPtr);
11251125
var microsecond = Runtime.PyObject_GetAttrString(value, microsecondPtr);
1126-
var timeKind = DateTimeKind.Unspecified;
1127-
var tzinfo = Runtime.PyObject_GetAttrString(value, tzinfoPtr);
1128-
1129-
NewReference hours = default;
1130-
NewReference minutes = default;
1131-
if (!tzinfo.IsNone() && !tzinfo.IsNull())
1132-
{
1133-
var tznameMethod = Runtime.PyObject_GetAttrString(tzinfo.Borrow(), new StrPtr("tzname", Encoding.UTF8));
1134-
var args = Runtime.PyTuple_New(1);
1135-
Runtime.PyTuple_SetItem(args.Borrow(), 0, Runtime.None.Steal());
1136-
var tznameObj = Runtime.PyObject_CallObject(tznameMethod.Borrow(), args.Borrow());
1137-
var tzname = Runtime.GetManagedString(tznameObj.Borrow());
1138-
1139-
if (tzname.Contains("UTC", StringComparison.InvariantCultureIgnoreCase))
1140-
{
1141-
timeKind = DateTimeKind.Utc;
1142-
}
1143-
}
11441126

11451127
var convertedHour = 0L;
11461128
var convertedMinute = 0L;
@@ -1161,8 +1143,7 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec
11611143
(int)convertedHour,
11621144
(int)convertedMinute,
11631145
(int)convertedSecond,
1164-
millisecond: (int)milliseconds,
1165-
timeKind);
1146+
(int)milliseconds);
11661147

11671148
year.Dispose();
11681149
month.Dispose();
@@ -1172,16 +1153,6 @@ internal static bool ToPrimitive(BorrowedReference value, Type obType, out objec
11721153
second.Dispose();
11731154
microsecond.Dispose();
11741155

1175-
if (!tzinfo.IsNull())
1176-
{
1177-
tzinfo.Dispose();
1178-
if (!tzinfo.IsNone())
1179-
{
1180-
hours.Dispose();
1181-
minutes.Dispose();
1182-
}
1183-
}
1184-
11851156
Exceptions.Clear();
11861157
return true;
11871158
default:

0 commit comments

Comments
 (0)