Mercurial > p > roundup > code
comparison roundup/date.py @ 5376:64b05e24dbd8
Python 3 preparation: convert print to a function.
Tool-assisted patch. It is possible that some "from __future__ import
print_function" are not in fact needed, if a file only uses print()
with a single string as an argument and so would work fine in Python 2
without that import.
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Tue, 24 Jul 2018 09:54:52 +0000 |
| parents | 03505579abef |
| children | 12fe83f90f0d |
comparison
equal
deleted
inserted
replaced
| 5375:1ad46057ae4a | 5376:64b05e24dbd8 |
|---|---|
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 | 17 |
| 18 """Date, time and time interval handling. | 18 """Date, time and time interval handling. |
| 19 """ | 19 """ |
| 20 from __future__ import print_function | |
| 20 __docformat__ = 'restructuredtext' | 21 __docformat__ = 'restructuredtext' |
| 21 | 22 |
| 22 import calendar | 23 import calendar |
| 23 import datetime | 24 import datetime |
| 24 import time | 25 import time |
| 1202 def test_range(): | 1203 def test_range(): |
| 1203 rspecs = ("from 2-12 to 4-2", "from 18:00 TO +2m", "12:00;", "tO +3d", | 1204 rspecs = ("from 2-12 to 4-2", "from 18:00 TO +2m", "12:00;", "tO +3d", |
| 1204 "2002-11-10; 2002-12-12", "; 20:00 +1d", '2002-10-12') | 1205 "2002-11-10; 2002-12-12", "; 20:00 +1d", '2002-10-12') |
| 1205 rispecs = ('from -1w 2d 4:32 to 4d', '-2w 1d') | 1206 rispecs = ('from -1w 2d 4:32 to 4d', '-2w 1d') |
| 1206 for rspec in rspecs: | 1207 for rspec in rspecs: |
| 1207 print '>>> Range("%s")' % rspec | 1208 print('>>> Range("%s")' % rspec) |
| 1208 print `Range(rspec, Date)` | 1209 print(`Range(rspec, Date)`) |
| 1209 print | 1210 print() |
| 1210 for rspec in rispecs: | 1211 for rspec in rispecs: |
| 1211 print '>>> Range("%s")' % rspec | 1212 print('>>> Range("%s")' % rspec) |
| 1212 print `Range(rspec, Interval)` | 1213 print(`Range(rspec, Interval)`) |
| 1213 print | 1214 print() |
| 1214 | 1215 |
| 1215 def test(): | 1216 def test(): |
| 1216 intervals = (" 3w 1 d 2:00", " + 2d", "3w") | 1217 intervals = (" 3w 1 d 2:00", " + 2d", "3w") |
| 1217 for interval in intervals: | 1218 for interval in intervals: |
| 1218 print '>>> Interval("%s")'%interval | 1219 print('>>> Interval("%s")'%interval) |
| 1219 print `Interval(interval)` | 1220 print(`Interval(interval)`) |
| 1220 | 1221 |
| 1221 dates = (".", "2000-06-25.19:34:02", ". + 2d", "1997-04-17", "01-25", | 1222 dates = (".", "2000-06-25.19:34:02", ". + 2d", "1997-04-17", "01-25", |
| 1222 "08-13.22:13", "14:25", '2002-12') | 1223 "08-13.22:13", "14:25", '2002-12') |
| 1223 for date in dates: | 1224 for date in dates: |
| 1224 print '>>> Date("%s")'%date | 1225 print('>>> Date("%s")'%date) |
| 1225 print `Date(date)` | 1226 print(`Date(date)`) |
| 1226 | 1227 |
| 1227 sums = ((". + 2d", "3w"), (".", " 3w 1 d 2:00")) | 1228 sums = ((". + 2d", "3w"), (".", " 3w 1 d 2:00")) |
| 1228 for date, interval in sums: | 1229 for date, interval in sums: |
| 1229 print '>>> Date("%s") + Interval("%s")'%(date, interval) | 1230 print('>>> Date("%s") + Interval("%s")'%(date, interval)) |
| 1230 print `Date(date) + Interval(interval)` | 1231 print(`Date(date) + Interval(interval)`) |
| 1231 | 1232 |
| 1232 if __name__ == '__main__': | 1233 if __name__ == '__main__': |
| 1233 test() | 1234 test() |
| 1234 | 1235 |
| 1235 # vim: set filetype=python sts=4 sw=4 et si : | 1236 # vim: set filetype=python sts=4 sw=4 et si : |
