Skip to content

Commit

Permalink
Fix issue with timestamp timezone (#1740)
Browse files Browse the repository at this point in the history
* Fix issue with timestamp timezone

* Add test
  • Loading branch information
slozier committed Sep 9, 2023
1 parent e8ed79b commit 72f4268
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Src/IronPython.Modules/_datetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ public datetime(DateTime dt, tzinfo? tzinfo)

public double timestamp() {
if (tzinfo is null) {
return PythonTime.TicksToTimestamp(_dateTime.Ticks);
return PythonTime.TicksToTimestamp(_dateTime.ToUniversalTime().Ticks);
}
else {
return (this - new datetime(new DateTime(1970, 1, 1), timezone.utc)).total_seconds();
Expand Down
5 changes: 5 additions & 0 deletions Tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def test_fromtimestamp(self):
ts = 5399410716.777882
self.assertEqual(datetime.datetime.fromtimestamp(ts).microsecond, 777882)

def test_timestamp(self):
# https://github.com/IronLanguages/ironpython3/pull/1740
dt = datetime.datetime(2000, 1, 1)
self.assertEqual(datetime.datetime.fromtimestamp(dt.timestamp()), dt)

@skipUnlessIronPython()
def test_System_DateTime_conversion(self):
import clr
Expand Down

0 comments on commit 72f4268

Please sign in to comment.