Skip to content

Commit 7c38be4

Browse files
committed
Don't ignore days in time delta
PullRequest: graalpython/3105
2 parents 12f4079 + cbc7291 commit 7c38be4

File tree

2 files changed

+21
-1
lines changed
  • graalpython

2 files changed

+21
-1
lines changed

graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/TimeDateTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
import static org.junit.Assert.assertEquals;
4444
import static org.junit.Assert.assertFalse;
45+
import static org.junit.Assert.assertNotNull;
46+
import static org.junit.Assert.assertTrue;
4547

4648
import java.io.ByteArrayOutputStream;
4749
import java.time.LocalDate;
@@ -166,6 +168,22 @@ public void testDateTimeDateTime03() {
166168
assertEquals(ZoneId.of("UTC+4"), value.asTimeZone());
167169
}
168170

171+
@Test
172+
public void testDateTimeDateTime04() {
173+
String source = "from datetime import timedelta, datetime, timezone\n" +
174+
"\n" +
175+
"zone = timezone(timedelta(seconds=-18000), \"US/Eastern\")\n" +
176+
"dt = datetime(1970, 1, 1, 0, 0, 1, tzinfo=zone)\n" +
177+
"\n" +
178+
"\n" +
179+
"dt";
180+
Value value = getValue(source, ZoneId.of("US/Eastern"));
181+
assertTrue("Value represents a datatime: " + value, value.isDate());
182+
assertTrue("Value represents a datatime: " + value, value.isTime());
183+
assertTrue("Value represents a timezone: " + value, value.isTimeZone());
184+
assertNotNull("Can return a time zone", value.asTimeZone());
185+
}
186+
169187
@Test
170188
public void testStructTime01() {
171189
String source = "import time\n" +

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,9 @@ public ZoneId asTimeZone(
993993
Object delta = lib.invokeMember(tzinfo, "utcoffset", new Object[]{this});
994994
if (delta != PNone.NONE) {
995995
int seconds = castToIntNode.execute(inliningTarget, lib.readMember(delta, "seconds"));
996-
return createZoneId(seconds);
996+
int days = castToIntNode.execute(inliningTarget, lib.readMember(delta, "days"));
997+
int offset = days * 3600 * 24 + seconds;
998+
return createZoneId(offset);
997999
}
9981000
}
9991001
} catch (UnsupportedMessageException | UnknownIdentifierException | ArityException | UnsupportedTypeException ex) {

0 commit comments

Comments
 (0)