1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 from datetime
import datetime
, timedelta
19 from mediagoblin
.tools
.timesince
import timesince
23 test_time
= datetime
.now()
25 # it should ignore second and microseconds
26 assert timesince(test_time
, test_time
+ timedelta(microseconds
=1)) == "0 minutes"
27 assert timesince(test_time
, test_time
+ timedelta(seconds
=1)) == "0 minutes"
29 # test minutes, hours, days, weeks, months and years (singular and plural)
30 assert timesince(test_time
, test_time
+ timedelta(minutes
=1)) == "1 minute"
31 assert timesince(test_time
, test_time
+ timedelta(minutes
=2)) == "2 minutes"
33 assert timesince(test_time
, test_time
+ timedelta(hours
=1)) == "1 hour"
34 assert timesince(test_time
, test_time
+ timedelta(hours
=2)) == "2 hours"
36 assert timesince(test_time
, test_time
+ timedelta(days
=1)) == "1 day"
37 assert timesince(test_time
, test_time
+ timedelta(days
=2)) == "2 days"
39 assert timesince(test_time
, test_time
+ timedelta(days
=7)) == "1 week"
40 assert timesince(test_time
, test_time
+ timedelta(days
=14)) == "2 weeks"
42 assert timesince(test_time
, test_time
+ timedelta(days
=30)) == "1 month"
43 assert timesince(test_time
, test_time
+ timedelta(days
=60)) == "2 months"
45 assert timesince(test_time
, test_time
+ timedelta(days
=365)) == "1 year"
46 assert timesince(test_time
, test_time
+ timedelta(days
=730)) == "2 years"
48 # okay now we want to test combinations
50 assert timesince(test_time
, test_time
+ timedelta(days
=5, hours
=1)) == "5 days, 1 hour"
52 assert timesince(test_time
, test_time
+ timedelta(days
=15)) == "2 weeks, 1 day"
54 assert timesince(test_time
, test_time
+ timedelta(days
=97)) == "3 months, 1 week"
56 assert timesince(test_time
, test_time
+ timedelta(days
=2250)) == "6 years, 2 months"