summaryrefslogtreecommitdiffstats
path: root/tests/datetime/test_diff.py
blob: 7a315070f64c56de29efa82f060791679376954e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
from __future__ import annotations

from datetime import datetime

import pytest

import pendulum


def test_diff_in_years_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(years=1)).in_years() == 1


def test_diff_in_years_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1), False).in_years() == -1


def test_diff_in_years_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1)).in_years() == 1


def test_diff_in_years_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(years=1).diff().in_years() == 1


def test_diff_in_years_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(years=1).add(months=7)).in_years() == 1


def test_diff_in_months_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(years=1).add(months=1)).in_months() == 13


def test_diff_in_months_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1).add(months=1), False).in_months() == -11


def test_diff_in_months_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1).add(months=1)).in_months() == 11


def test_diff_in_months_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(years=1).diff().in_months() == 12


def test_diff_in_months_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(months=1).add(days=16)).in_months() == 1


def test_diff_in_days_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(years=1)).in_days() == 366


def test_diff_in_days_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1), False).in_days() == -365


def test_diff_in_days_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1)).in_days() == 365


def test_diff_in_days_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=1).diff().in_days() == 7


def test_diff_in_days_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(days=1).add(hours=13)).in_days() == 1


def test_diff_in_weeks_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(years=1)).in_weeks() == 52


def test_diff_in_weeks_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1), False).in_weeks() == -52


def test_diff_in_weeks_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(years=1)).in_weeks() == 52


def test_diff_in_weeks_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=1).diff().in_weeks() == 1


def test_diff_in_weeks_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(weeks=1).subtract(days=1)).in_weeks() == 0


def test_diff_in_hours_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(days=1).add(hours=2)).in_hours() == 26


def test_diff_in_hours_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(days=1).add(hours=2), False).in_hours() == -22


def test_diff_in_hours_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(days=1).add(hours=2)).in_hours() == 22


def test_diff_in_hours_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 15), freeze=True):
        assert pendulum.now().subtract(days=2).diff().in_hours() == 48


def test_diff_in_hours_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(hours=1).add(minutes=31)).in_hours() == 1


def test_diff_in_minutes_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(hours=1).add(minutes=2)).in_minutes() == 62


def test_diff_in_minutes_positive_big():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(hours=25).add(minutes=2)).in_minutes() == 1502


def test_diff_in_minutes_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(hours=1).add(minutes=2), False).in_minutes() == -58


def test_diff_in_minutes_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(hours=1).add(minutes=2)).in_minutes() == 58


def test_diff_in_minutes_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(hours=1).diff().in_minutes() == 60


def test_diff_in_minutes_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(minutes=1).add(seconds=59)).in_minutes() == 1


def test_diff_in_seconds_positive():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(minutes=1).add(seconds=2)).in_seconds() == 62


def test_diff_in_seconds_positive_big():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(hours=2).add(seconds=2)).in_seconds() == 7202


def test_diff_in_seconds_negative_with_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(minutes=1).add(seconds=2), False).in_seconds() == -58


def test_diff_in_seconds_negative_no_sign():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.subtract(minutes=1).add(seconds=2)).in_seconds() == 58


def test_diff_in_seconds_vs_default_now():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(hours=1).diff().in_seconds() == 3600


def test_diff_in_seconds_ensure_is_truncated():
    dt = pendulum.datetime(2000, 1, 1)
    assert dt.diff(dt.add(seconds=1.9)).in_seconds() == 1


def test_diff_in_seconds_with_timezones():
    dt_ottawa = pendulum.datetime(2000, 1, 1, 13, tz="America/Toronto")
    dt_vancouver = pendulum.datetime(2000, 1, 1, 13, tz="America/Vancouver")
    assert dt_ottawa.diff(dt_vancouver).in_seconds() == 3 * 60 * 60


def test_diff_for_humans_now_and_second():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().diff_for_humans() == "a few seconds ago"


def test_diff_for_humans_now_and_second_with_timezone():
    van_now = pendulum.now("America/Vancouver")
    here_now = van_now.in_timezone(pendulum.now().timezone)

    with pendulum.travel_to(here_now, freeze=True):
        assert here_now.diff_for_humans() == "a few seconds ago"


def test_diff_for_humans_now_and_seconds():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().subtract(seconds=2).diff_for_humans() == "a few seconds ago"
        )


def test_diff_for_humans_now_and_nearly_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(seconds=59).diff_for_humans() == "59 seconds ago"


def test_diff_for_humans_now_and_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(minutes=1).diff_for_humans() == "1 minute ago"


def test_diff_for_humans_now_and_minutes():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(minutes=2).diff_for_humans() == "2 minutes ago"


def test_diff_for_humans_now_and_nearly_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(minutes=59).diff_for_humans() == "59 minutes ago"


def test_diff_for_humans_now_and_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(hours=1).diff_for_humans() == "1 hour ago"


def test_diff_for_humans_now_and_hours():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(hours=2).diff_for_humans() == "2 hours ago"


def test_diff_for_humans_now_and_nearly_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(hours=23).diff_for_humans() == "23 hours ago"


def test_diff_for_humans_now_and_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(days=1).diff_for_humans() == "1 day ago"


def test_diff_for_humans_now_and_days():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(days=2).diff_for_humans() == "2 days ago"


def test_diff_for_humans_now_and_nearly_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(days=6).diff_for_humans() == "6 days ago"


def test_diff_for_humans_now_and_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=1).diff_for_humans() == "1 week ago"


def test_diff_for_humans_now_and_weeks():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=2).diff_for_humans() == "2 weeks ago"


def test_diff_for_humans_now_and_nearly_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=3).diff_for_humans() == "3 weeks ago"


def test_diff_for_humans_now_and_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(weeks=4).diff_for_humans() == "4 weeks ago"
        assert pendulum.now().subtract(months=1).diff_for_humans() == "1 month ago"


def test_diff_for_humans_now_and_months():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(months=2).diff_for_humans() == "2 months ago"


def test_diff_for_humans_now_and_nearly_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(months=11).diff_for_humans() == "11 months ago"


def test_diff_for_humans_now_and_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(years=1).diff_for_humans() == "1 year ago"


def test_diff_for_humans_now_and_years():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().subtract(years=2).diff_for_humans() == "2 years ago"


def test_diff_for_humans_now_and_future_second():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(seconds=1).diff_for_humans() == "in a few seconds"


def test_diff_for_humans_now_and_future_seconds():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(seconds=2).diff_for_humans() == "in a few seconds"


def test_diff_for_humans_now_and_nearly_future_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(seconds=59).diff_for_humans() == "in 59 seconds"


def test_diff_for_humans_now_and_future_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(minutes=1).diff_for_humans() == "in 1 minute"


def test_diff_for_humans_now_and_future_minutes():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(minutes=2).diff_for_humans() == "in 2 minutes"


def test_diff_for_humans_now_and_nearly_future_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(minutes=59).diff_for_humans() == "in 59 minutes"


def test_diff_for_humans_now_and_future_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(hours=1).diff_for_humans() == "in 1 hour"


def test_diff_for_humans_now_and_future_hours():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(hours=2).diff_for_humans() == "in 2 hours"


def test_diff_for_humans_now_and_nearly_future_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(hours=23).diff_for_humans() == "in 23 hours"


def test_diff_for_humans_now_and_future_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(days=1).diff_for_humans() == "in 1 day"


def test_diff_for_humans_now_and_future_days():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(days=2).diff_for_humans() == "in 2 days"


def test_diff_for_humans_now_and_nearly_future_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(days=6).diff_for_humans() == "in 6 days"


def test_diff_for_humans_now_and_future_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(weeks=1).diff_for_humans() == "in 1 week"


def test_diff_for_humans_now_and_future_weeks():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(weeks=2).diff_for_humans() == "in 2 weeks"


def test_diff_for_humans_now_and_nearly_future_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(weeks=3).diff_for_humans() == "in 3 weeks"


def test_diff_for_humans_now_and_future_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(weeks=4).diff_for_humans() == "in 4 weeks"
        assert pendulum.now().add(months=1).diff_for_humans() == "in 1 month"


def test_diff_for_humans_now_and_future_months():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(months=2).diff_for_humans() == "in 2 months"


def test_diff_for_humans_now_and_nearly_future_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(months=11).diff_for_humans() == "in 11 months"


def test_diff_for_humans_now_and_future_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(years=1).diff_for_humans() == "in 1 year"


def test_diff_for_humans_now_and_future_years():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert pendulum.now().add(years=2).diff_for_humans() == "in 2 years"


def test_diff_for_humans_other_and_second():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(seconds=1))
            == "a few seconds before"
        )


def test_diff_for_humans_other_and_seconds():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(seconds=2))
            == "a few seconds before"
        )


def test_diff_for_humans_other_and_nearly_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(seconds=59))
            == "59 seconds before"
        )


def test_diff_for_humans_other_and_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(minutes=1))
            == "1 minute before"
        )


def test_diff_for_humans_other_and_minutes():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(minutes=2))
            == "2 minutes before"
        )


def test_diff_for_humans_other_and_nearly_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(minutes=59))
            == "59 minutes before"
        )


def test_diff_for_humans_other_and_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(hours=1))
            == "1 hour before"
        )


def test_diff_for_humans_other_and_hours():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(hours=2))
            == "2 hours before"
        )


def test_diff_for_humans_other_and_nearly_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(hours=23))
            == "23 hours before"
        )


def test_diff_for_humans_other_and_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(days=1)) == "1 day before"
        )


def test_diff_for_humans_other_and_days():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(days=2))
            == "2 days before"
        )


def test_diff_for_humans_other_and_nearly_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(days=6))
            == "6 days before"
        )


def test_diff_for_humans_other_and_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(weeks=1))
            == "1 week before"
        )


def test_diff_for_humans_other_and_weeks():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(weeks=2))
            == "2 weeks before"
        )


def test_diff_for_humans_other_and_nearly_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(weeks=3))
            == "3 weeks before"
        )


def test_diff_for_humans_other_and_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(weeks=4))
            == "4 weeks before"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(months=1))
            == "1 month before"
        )


def test_diff_for_humans_other_and_months():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(months=2))
            == "2 months before"
        )


def test_diff_for_humans_other_and_nearly_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(months=11))
            == "11 months before"
        )


def test_diff_for_humans_other_and_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(years=1))
            == "1 year before"
        )


def test_diff_for_humans_other_and_years():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(years=2))
            == "2 years before"
        )


def test_diff_for_humans_other_and_future_second():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(seconds=1))
            == "a few seconds after"
        )


def test_diff_for_humans_other_and_future_seconds():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(seconds=2))
            == "a few seconds after"
        )


def test_diff_for_humans_other_and_nearly_future_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(seconds=59))
            == "59 seconds after"
        )


def test_diff_for_humans_other_and_future_minute():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(minutes=1))
            == "1 minute after"
        )


def test_diff_for_humans_other_and_future_minutes():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(minutes=2))
            == "2 minutes after"
        )


def test_diff_for_humans_other_and_nearly_future_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(minutes=59))
            == "59 minutes after"
        )


def test_diff_for_humans_other_and_future_hour():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(hours=1))
            == "1 hour after"
        )


def test_diff_for_humans_other_and_future_hours():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(hours=2))
            == "2 hours after"
        )


def test_diff_for_humans_other_and_nearly_future_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(hours=23))
            == "23 hours after"
        )


def test_diff_for_humans_other_and_future_day():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(days=1))
            == "1 day after"
        )


def test_diff_for_humans_other_and_future_days():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(days=2))
            == "2 days after"
        )


def test_diff_for_humans_other_and_nearly_future_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(days=6))
            == "6 days after"
        )


def test_diff_for_humans_other_and_future_week():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(weeks=1))
            == "1 week after"
        )


def test_diff_for_humans_other_and_future_weeks():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(weeks=2))
            == "2 weeks after"
        )


def test_diff_for_humans_other_and_nearly_future_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(weeks=3))
            == "3 weeks after"
        )


def test_diff_for_humans_other_and_future_month():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(weeks=4))
            == "4 weeks after"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(months=1))
            == "1 month after"
        )


def test_diff_for_humans_other_and_future_months():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(months=2))
            == "2 months after"
        )


def test_diff_for_humans_other_and_nearly_future_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(months=11))
            == "11 months after"
        )


def test_diff_for_humans_other_and_future_year():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(years=1))
            == "1 year after"
        )


def test_diff_for_humans_other_and_future_years():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(years=2))
            == "2 years after"
        )


def test_diff_for_humans_absolute_seconds():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(seconds=59), True)
            == "59 seconds"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(seconds=59), True)
            == "59 seconds"
        )


def test_diff_for_humans_absolute_minutes():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(minutes=30), True)
            == "30 minutes"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(minutes=30), True)
            == "30 minutes"
        )


def test_diff_for_humans_absolute_hours():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(hours=3), True)
            == "3 hours"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(hours=3), True)
            == "3 hours"
        )


def test_diff_for_humans_absolute_days():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(days=2), True)
            == "2 days"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(days=2), True) == "2 days"
        )


def test_diff_for_humans_absolute_weeks():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(weeks=2), True)
            == "2 weeks"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(weeks=2), True)
            == "2 weeks"
        )


def test_diff_for_humans_absolute_months():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(months=2), True)
            == "2 months"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(months=2), True)
            == "2 months"
        )


def test_diff_for_humans_absolute_years():
    with pendulum.travel_to(pendulum.datetime(2012, 1, 1, 1, 2, 3), freeze=True):
        assert (
            pendulum.now().diff_for_humans(pendulum.now().subtract(years=1), True)
            == "1 year"
        )
        assert (
            pendulum.now().diff_for_humans(pendulum.now().add(years=1), True)
            == "1 year"
        )


def test_diff_for_humans_accuracy():
    now = pendulum.now("utc")

    with pendulum.travel_to(now.add(microseconds=200), freeze=True):
        assert now.add(years=1).diff_for_humans(absolute=True) == "1 year"
        assert now.add(months=11).diff_for_humans(absolute=True) == "11 months"
        assert now.add(days=27).diff_for_humans(absolute=True) == "4 weeks"
        assert now.add(years=1, months=3).diff_for_humans(absolute=True) == "1 year"
        assert now.add(years=1, months=8).diff_for_humans(absolute=True) == "2 years"

    # DST
    now = pendulum.datetime(2017, 3, 7, tz="America/Toronto")
    with pendulum.travel_to(now, freeze=True):
        assert now.add(days=6).diff_for_humans(absolute=True) == "6 days"


def test_subtraction():
    d = pendulum.naive(2016, 7, 5, 12, 32, 25, 0)
    future_dt = datetime(2016, 7, 5, 13, 32, 25, 0)
    future = d.add(hours=1)

    assert (future - d).total_seconds() == 3600
    assert (future_dt - d).total_seconds() == 3600


def test_subtraction_aware_naive():
    dt = pendulum.datetime(2016, 7, 5, 12, 32, 25, 0)
    future_dt = datetime(2016, 7, 5, 13, 32, 25, 0)

    with pytest.raises(TypeError):
        future_dt - dt

    future_dt = pendulum.naive(2016, 7, 5, 13, 32, 25, 0)

    with pytest.raises(TypeError):
        future_dt - dt


def test_subtraction_with_timezone():
    dt = pendulum.datetime(2013, 3, 31, 1, 59, 59, 999999, tz="Europe/Paris")
    post = dt.add(microseconds=1)

    assert (post - dt).total_seconds() == 1e-06

    dt = pendulum.datetime(
        2013,
        10,
        27,
        2,
        59,
        59,
        999999,
        tz="Europe/Paris",
        fold=0,
    )
    post = dt.add(microseconds=1)

    assert (post - dt).total_seconds() == 1e-06