Skip to content

Commit be64ef3

Browse files
ricardobranco777dbrattli
authored andcommitted
Fix deprecated calls to datetime
1 parent af1663d commit be64ef3

16 files changed

+53
-53
lines changed

examples/marbles/hot_datetime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Delay the emission of elements to the specified datetime.
88
"""
99

10-
now = datetime.datetime.utcnow()
10+
now = datetime.datetime.now(datetime.timezone.utc)
1111
dt = datetime.timedelta(seconds=3.0)
1212
duetime = now + dt
1313

reactivex/internal/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone
22
from typing import Any, NoReturn, TypeVar, Union
33

44
_T = TypeVar("_T")
@@ -14,7 +14,7 @@ def identity(x: _T) -> _T:
1414

1515

1616
def default_now() -> datetime:
17-
return datetime.utcnow()
17+
return datetime.now(timezone.utc)
1818

1919

2020
def default_comparer(x: _T, y: _T) -> bool:

reactivex/internal/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, timezone
22

33
DELTA_ZERO = timedelta(0)
4-
UTC_ZERO = datetime.utcfromtimestamp(0)
4+
UTC_ZERO = datetime.fromtimestamp(0, tz=timezone.utc)

reactivex/operators/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ def skip_until_with_time(
29172917
Args:
29182918
start_time: Time to start taking elements from the source
29192919
sequence. If this value is less than or equal to
2920-
`datetime.utcnow()`, no elements will be skipped.
2920+
`datetime.now(timezone.utc)`, no elements will be skipped.
29212921
29222922
Returns:
29232923
An operator function that takes an observable source and
@@ -3622,7 +3622,7 @@ def take_until_with_time(
36223622
Args:
36233623
end_time: Time to stop taking elements from the source
36243624
sequence. If this value is less than or equal to
3625-
`datetime.utcnow()`, the result stream will complete
3625+
`datetime.now(timezone.utc)`, the result stream will complete
36263626
immediately.
36273627
scheduler: Scheduler to run the timer on.
36283628

reactivex/scheduler/scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import abstractmethod
2-
from datetime import datetime, timedelta
2+
from datetime import datetime, timedelta, timezone
33
from typing import Optional, TypeVar
44

55
from reactivex import abc, typing
@@ -145,7 +145,7 @@ def to_datetime(cls, value: typing.AbsoluteOrRelativeTime) -> datetime:
145145
if isinstance(value, timedelta):
146146
value = UTC_ZERO + value
147147
elif not isinstance(value, datetime):
148-
value = datetime.utcfromtimestamp(value)
148+
value = datetime.fromtimestamp((value), tz=timezone.utc)
149149

150150
return value
151151

tests/test_observable/test_delay.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
import unittest
3-
from datetime import datetime
3+
from datetime import datetime, timezone
44

55
from reactivex.operators import delay
66
from reactivex.testing import ReactiveTest, TestScheduler
@@ -62,7 +62,7 @@ def test_delay_datetime_offset_simple1_impl(self):
6262
)
6363

6464
def create():
65-
dt = datetime.utcfromtimestamp(300.0)
65+
dt = datetime.fromtimestamp(300.0, tz=timezone.utc)
6666
return xs.pipe(delay(dt))
6767

6868
results = scheduler.start(create)
@@ -107,7 +107,7 @@ def test_delay_datetime_offset_simple2_impl(self):
107107
)
108108

109109
def create():
110-
return xs.pipe(delay(datetime.utcfromtimestamp(250)))
110+
return xs.pipe(delay(datetime.fromtimestamp(250, tz=timezone.utc)))
111111

112112
results = scheduler.start(create)
113113

@@ -153,7 +153,7 @@ def test_delay_datetime_offset_simple3_impl(self):
153153
)
154154

155155
def create():
156-
return xs.pipe(delay(datetime.utcfromtimestamp(350)))
156+
return xs.pipe(delay(datetime.fromtimestamp(350, tz=timezone.utc)))
157157

158158
results = scheduler.start(create)
159159

@@ -201,7 +201,7 @@ def test_delay_datetime_offset_error1_impl(self):
201201
)
202202

203203
def create():
204-
return xs.pipe(delay(datetime.utcfromtimestamp(250)))
204+
return xs.pipe(delay(datetime.fromtimestamp(250, tz=timezone.utc)))
205205

206206
results = scheduler.start(create)
207207

@@ -244,7 +244,7 @@ def test_delay_datetime_offset_error2_impl(self):
244244
)
245245

246246
def create():
247-
return xs.pipe(delay(datetime.utcfromtimestamp(350)))
247+
return xs.pipe(delay(datetime.fromtimestamp(350, tz=timezone.utc)))
248248

249249
results = scheduler.start(create)
250250

tests/test_observable/test_skipuntilwithtime.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
from reactivex import operators as ops
55
from reactivex.testing import ReactiveTest, TestScheduler
@@ -21,7 +21,7 @@ def test_skipuntil_zero(self):
2121
)
2222

2323
def create():
24-
return xs.pipe(ops.skip_until_with_time(datetime.utcfromtimestamp(0)))
24+
return xs.pipe(ops.skip_until_with_time(datetime.fromtimestamp(0, tz=timezone.utc)))
2525

2626
res = scheduler.start(create)
2727

@@ -35,7 +35,7 @@ def test_skipuntil_late(self):
3535
)
3636

3737
def create():
38-
return xs.pipe(ops.skip_until_with_time(datetime.utcfromtimestamp(250)))
38+
return xs.pipe(ops.skip_until_with_time(datetime.fromtimestamp(250, tz=timezone.utc)))
3939

4040
res = scheduler.start(create)
4141

@@ -48,7 +48,7 @@ def test_skipuntil_error(self):
4848
xs = scheduler.create_hot_observable(on_error(210, ex))
4949

5050
def create():
51-
return xs.pipe(ops.skip_until_with_time(datetime.utcfromtimestamp(250)))
51+
return xs.pipe(ops.skip_until_with_time(datetime.fromtimestamp(250, tz=timezone.utc)))
5252

5353
res = scheduler.start(create)
5454

@@ -60,7 +60,7 @@ def test_skipuntil_never(self):
6060
xs = scheduler.create_hot_observable()
6161

6262
def create():
63-
return xs.pipe(ops.skip_until_with_time(datetime.utcfromtimestamp(250)))
63+
return xs.pipe(ops.skip_until_with_time(datetime.fromtimestamp(250, tz=timezone.utc)))
6464

6565
res = scheduler.start(create)
6666

@@ -81,8 +81,8 @@ def test_skipuntil_twice1(self):
8181

8282
def create():
8383
return xs.pipe(
84-
ops.skip_until_with_time(datetime.utcfromtimestamp(215)),
85-
ops.skip_until_with_time(datetime.utcfromtimestamp(230)),
84+
ops.skip_until_with_time(datetime.fromtimestamp(215, tz=timezone.utc)),
85+
ops.skip_until_with_time(datetime.fromtimestamp(230, tz=timezone.utc)),
8686
)
8787

8888
res = scheduler.start(create)
@@ -109,8 +109,8 @@ def test_skipuntil_twice2(self):
109109

110110
def create():
111111
return xs.pipe(
112-
ops.skip_until_with_time(datetime.utcfromtimestamp(230)),
113-
ops.skip_until_with_time(datetime.utcfromtimestamp(215)),
112+
ops.skip_until_with_time(datetime.fromtimestamp(230, tz=timezone.utc)),
113+
ops.skip_until_with_time(datetime.fromtimestamp(215, tz=timezone.utc)),
114114
)
115115

116116
res = scheduler.start(create)

tests/test_observable/test_takeuntilwithtime.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
from reactivex import operators as ops
55
from reactivex.testing import ReactiveTest, TestScheduler
@@ -30,7 +30,7 @@ def test_takeuntil_zero(self):
3030
)
3131

3232
def create():
33-
return xs.pipe(ops.take_until_with_time(datetime.utcfromtimestamp(0)))
33+
return xs.pipe(ops.take_until_with_time(datetime.fromtimestamp(0)), tz=timezone.utc)
3434

3535
res = scheduler.start(create)
3636

@@ -44,7 +44,7 @@ def test_takeuntil_late(self):
4444
)
4545

4646
def create():
47-
dt = datetime.utcfromtimestamp(250)
47+
dt = datetime.fromtimestamp(250, tz=timezone.utc)
4848
return xs.pipe(ops.take_until_with_time(dt))
4949

5050
res = scheduler.start(create)
@@ -58,7 +58,7 @@ def test_takeuntil_error(self):
5858
xs = scheduler.create_hot_observable(on_error(210, ex))
5959

6060
def create():
61-
dt = datetime.utcfromtimestamp(250)
61+
dt = datetime.fromtimestamp(250, tz=timezone.utc)
6262
return xs.pipe(ops.take_until_with_time(dt))
6363

6464
res = scheduler.start(create)
@@ -71,7 +71,7 @@ def test_takeuntil_never(self):
7171
xs = scheduler.create_hot_observable()
7272

7373
def create():
74-
dt = datetime.utcfromtimestamp(250)
74+
dt = datetime.fromtimestamp(250, tz=timezone.utc)
7575
return xs.pipe(ops.take_until_with_time(dt))
7676

7777
res = scheduler.start(create)
@@ -92,8 +92,8 @@ def test_takeuntil_twice1(self):
9292
)
9393

9494
def create():
95-
dt235 = datetime.utcfromtimestamp(235)
96-
dt255 = datetime.utcfromtimestamp(255)
95+
dt235 = datetime.fromtimestamp(235, tz=timezone.utc)
96+
dt255 = datetime.fromtimestamp(255, tz=timezone.utc)
9797
return xs.pipe(
9898
ops.take_until_with_time(dt255),
9999
ops.take_until_with_time(dt235),
@@ -122,8 +122,8 @@ def test_takeuntil_twice2(self):
122122
)
123123

124124
def create():
125-
dt235 = datetime.utcfromtimestamp(235)
126-
dt255 = datetime.utcfromtimestamp(255)
125+
dt235 = datetime.fromtimestamp(235, tz=timezone.utc)
126+
dt255 = datetime.fromtimestamp(255, tz=timezone.utc)
127127
return xs.pipe(
128128
ops.take_until_with_time(dt235),
129129
ops.take_until_with_time(dt255),

tests/test_observable/test_timeout.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
from reactivex import operators as ops
55
from reactivex.testing import ReactiveTest, TestScheduler
@@ -241,7 +241,7 @@ def test_timeout_datetime_offset_timeout_occurs(self):
241241
ys = scheduler.create_cold_observable(on_next(100, -1))
242242

243243
def create():
244-
return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
244+
return xs.pipe(ops.timeout(datetime.fromtimestamp(400, tz=timezone.utc), ys))
245245

246246
results = scheduler.start(create)
247247

@@ -255,7 +255,7 @@ def test_timeout_datetime_offset_timeout_does_not_occur_completed(self):
255255
ys = scheduler.create_cold_observable(on_next(100, -1))
256256

257257
def create():
258-
return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
258+
return xs.pipe(ops.timeout(datetime.fromtimestamp(400, tz=timezone.utc), ys))
259259

260260
results = scheduler.start(create)
261261

@@ -270,7 +270,7 @@ def test_timeout_datetime_offset_timeout_does_not_occur_error(self):
270270
ys = scheduler.create_cold_observable(on_next(100, -1))
271271

272272
def create():
273-
return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
273+
return xs.pipe(ops.timeout(datetime.fromtimestamp(400, tz=timezone.utc), ys))
274274

275275
results = scheduler.start(create)
276276

@@ -286,7 +286,7 @@ def test_timeout_datetime_offset_timeout_occur_2(self):
286286
ys = scheduler.create_cold_observable(on_next(100, -1))
287287

288288
def create():
289-
return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
289+
return xs.pipe(ops.timeout(datetime.fromtimestamp(400, tz=timezone.utc), ys))
290290

291291
results = scheduler.start(create)
292292

@@ -302,7 +302,7 @@ def test_timeout_datetime_offset_timeout_occur_3(self):
302302
ys = scheduler.create_cold_observable()
303303

304304
def create():
305-
return xs.pipe(ops.timeout(datetime.utcfromtimestamp(400), ys))
305+
return xs.pipe(ops.timeout(datetime.fromtimestamp(400, tz=timezone.utc), ys))
306306

307307
results = scheduler.start(create)
308308

tests/test_observable/test_timestamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33

44
import reactivex
55
from reactivex import operators as ops
@@ -17,7 +17,7 @@
1717
class Timestamp(object):
1818
def __init__(self, value, timestamp):
1919
if isinstance(timestamp, datetime):
20-
timestamp = timestamp - datetime.utcfromtimestamp(0)
20+
timestamp = timestamp - datetime.fromtimestamp(0, tz=timezone.utc)
2121
timestamp = int(
2222
timestamp.seconds
2323
) # FIXME: Must fix when tests run at fraction of seconds.

0 commit comments

Comments
 (0)