55import itertools
66import json
77import os
8- import pytz
98import shutil
109import sys
1110import tempfile
1211import unittest
1312from io import StringIO
13+ from zoneinfo import ZoneInfo
1414
1515from .backends import TaskWarrior
1616from .task import Task , ReadOnlyDictView
@@ -1110,8 +1110,7 @@ def test_export_data(self):
11101110 self .tw ,
11111111 description = 'test task' ,
11121112 project = 'Home' ,
1113- due = pytz .utc .localize (
1114- datetime .datetime (2015 , 1 , 1 , 23 , 23 , 23 )),
1113+ due = datetime .datetime (2015 , 1 , 1 , 23 , 23 , 23 , tzinfo = ZoneInfo ('UTC' )),
11151114 )
11161115
11171116 # Check that the output is a permutation of:
@@ -1135,8 +1134,8 @@ def setUp(self):
11351134 self .zone = local_zone
11361135 self .localdate_naive = datetime .datetime (2015 , 2 , 2 )
11371136 self .localtime_naive = datetime .datetime (2015 , 2 , 2 , 0 , 0 , 0 )
1138- self .localtime_aware = self .zone . localize ( self .localtime_naive )
1139- self .utctime_aware = self .localtime_aware .astimezone (pytz . utc )
1137+ self .localtime_aware = self .localtime_naive . replace ( tzinfo = self .zone )
1138+ self .utctime_aware = self .localtime_aware .astimezone (ZoneInfo ( 'UTC' ) )
11401139
11411140 def test_timezone_naive_datetime_setitem (self ):
11421141 t = Task (self .tw , description = 'test task' )
@@ -1217,7 +1216,7 @@ def test_simple_now_conversion(self):
12171216 return
12181217
12191218 t = Task (self .tw , description = 'test task' , due = 'now' )
1220- now = local_zone . localize ( datetime .datetime .now ())
1219+ now = datetime .datetime .now (). replace ( tzinfo = local_zone )
12211220
12221221 # Assert that both times are not more than 5 seconds apart
12231222 if sys .version_info < (2 , 7 ):
@@ -1237,24 +1236,26 @@ def test_simple_eoy_conversion(self):
12371236 return
12381237
12391238 t = Task (self .tw , description = 'test task' , due = 'eoy' )
1240- now = local_zone . localize ( datetime .datetime .now ())
1241- eoy = local_zone . localize ( datetime .datetime (
1239+ now = datetime .datetime .now (). replace ( tzinfo = local_zone )
1240+ eoy = datetime .datetime (
12421241 year = now .year ,
12431242 month = 12 ,
12441243 day = 31 ,
12451244 hour = 23 ,
12461245 minute = 59 ,
12471246 second = 59 ,
1248- ))
1247+ tzinfo = local_zone
1248+ )
12491249 if self .tw .version >= '2.5.2' and self .tw .version < '2.6.0' :
1250- eoy = local_zone . localize ( datetime .datetime (
1250+ eoy = datetime .datetime (
12511251 year = now .year + 1 ,
12521252 month = 1 ,
12531253 day = 1 ,
12541254 hour = 0 ,
12551255 minute = 0 ,
12561256 second = 0 ,
1257- ))
1257+ tzinfo = local_zone
1258+ )
12581259 self .assertEqual (eoy , t ['due' ])
12591260
12601261 def test_complex_eoy_conversion (self ):
@@ -1267,27 +1268,25 @@ def test_complex_eoy_conversion(self):
12671268 return
12681269
12691270 t = Task (self .tw , description = 'test task' , due = 'eoy - 4 months' )
1270- now = local_zone .localize (datetime .datetime .now ())
1271- due_date = local_zone .localize (
1272- datetime .datetime (
1273- year = now .year ,
1274- month = 12 ,
1275- day = 31 ,
1276- hour = 23 ,
1277- minute = 59 ,
1278- second = 59 ,
1279- )
1271+ now = datetime .datetime .now ().replace (tzinfo = local_zone )
1272+ due_date = datetime .datetime (
1273+ year = now .year ,
1274+ month = 12 ,
1275+ day = 31 ,
1276+ hour = 23 ,
1277+ minute = 59 ,
1278+ second = 59 ,
1279+ tzinfo = local_zone
12801280 ) - datetime .timedelta (0 , 4 * 30 * 86400 )
12811281 if self .tw .version >= '2.5.2' and self .tw .version < '2.6.0' :
1282- due_date = local_zone .localize (
1283- datetime .datetime (
1284- year = now .year + 1 ,
1285- month = 1 ,
1286- day = 1 ,
1287- hour = 0 ,
1288- minute = 0 ,
1289- second = 0 ,
1290- )
1282+ due_date = datetime .datetime (
1283+ year = now .year + 1 ,
1284+ month = 1 ,
1285+ day = 1 ,
1286+ hour = 0 ,
1287+ minute = 0 ,
1288+ second = 0 ,
1289+ tzinfo = local_zone
12911290 ) - datetime .timedelta (0 , 4 * 30 * 86400 )
12921291 self .assertEqual (due_date , t ['due' ])
12931292
0 commit comments