Skip to content

Commit 72f4268

Browse files
authored
Fix issue with timestamp timezone (#1740)
* Fix issue with timestamp timezone * Add test
1 parent e8ed79b commit 72f4268

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Src/IronPython.Modules/_datetime.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ public override string strftime(CodeContext/*!*/ context, [NotNone] string dateF
10361036

10371037
public double timestamp() {
10381038
if (tzinfo is null) {
1039-
return PythonTime.TicksToTimestamp(_dateTime.Ticks);
1039+
return PythonTime.TicksToTimestamp(_dateTime.ToUniversalTime().Ticks);
10401040
}
10411041
else {
10421042
return (this - new datetime(new DateTime(1970, 1, 1), timezone.utc)).total_seconds();

Tests/test_datetime.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def test_fromtimestamp(self):
126126
ts = 5399410716.777882
127127
self.assertEqual(datetime.datetime.fromtimestamp(ts).microsecond, 777882)
128128

129+
def test_timestamp(self):
130+
# https://github.com/IronLanguages/ironpython3/pull/1740
131+
dt = datetime.datetime(2000, 1, 1)
132+
self.assertEqual(datetime.datetime.fromtimestamp(dt.timestamp()), dt)
133+
129134
@skipUnlessIronPython()
130135
def test_System_DateTime_conversion(self):
131136
import clr

0 commit comments

Comments
 (0)