Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(29)

Side by Side Diff: Lib/test/datetimetester.py

Issue 23517: datetime.utcfromtimestamp rounds results incorrectly
Patch Set: Created 4 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/datetime.py ('k') | Modules/_datetimemodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Test date/time type. 1 """Test date/time type.
2 2
3 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases 3 See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
4 """ 4 """
5 5
6 import sys 6 import sys
7 import pickle 7 import pickle
8 import random 8 import random
9 import unittest 9 import unittest
10 10
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 self.assertRaises(OverflowError, day.__mul__, INF) 643 self.assertRaises(OverflowError, day.__mul__, INF)
644 self.assertRaises(OverflowError, day.__mul__, -INF) 644 self.assertRaises(OverflowError, day.__mul__, -INF)
645 645
646 def test_microsecond_rounding(self): 646 def test_microsecond_rounding(self):
647 td = timedelta 647 td = timedelta
648 eq = self.assertEqual 648 eq = self.assertEqual
649 649
650 # Single-field rounding. 650 # Single-field rounding.
651 eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0 651 eq(td(milliseconds=0.4/1000), td(0)) # rounds to 0
652 eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0 652 eq(td(milliseconds=-0.4/1000), td(0)) # rounds to 0
653 eq(td(milliseconds=0.5/1000), td(microseconds=1))
654 eq(td(milliseconds=-0.5/1000), td(microseconds=-1))
653 eq(td(milliseconds=0.6/1000), td(microseconds=1)) 655 eq(td(milliseconds=0.6/1000), td(microseconds=1))
654 eq(td(milliseconds=-0.6/1000), td(microseconds=-1)) 656 eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
657 eq(td(seconds=0.5/10**6), td(microseconds=1))
658 eq(td(seconds=-0.5/10**6), td(microseconds=-1))
655 659
656 # Rounding due to contributions from more than one field. 660 # Rounding due to contributions from more than one field.
657 us_per_hour = 3600e6 661 us_per_hour = 3600e6
658 us_per_day = us_per_hour * 24 662 us_per_day = us_per_hour * 24
659 eq(td(days=.4/us_per_day), td(0)) 663 eq(td(days=.4/us_per_day), td(0))
660 eq(td(hours=.2/us_per_hour), td(0)) 664 eq(td(hours=.2/us_per_hour), td(0))
661 eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1)) 665 eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1), td)
662 666
663 eq(td(days=-.4/us_per_day), td(0)) 667 eq(td(days=-.4/us_per_day), td(0))
664 eq(td(hours=-.2/us_per_hour), td(0)) 668 eq(td(hours=-.2/us_per_hour), td(0))
665 eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1)) 669 eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
666 670
667 # Test for a patch in Issue 8860
668 eq(td(microseconds=0.5), 0.5*td(microseconds=1.0))
669 eq(td(microseconds=0.5)//td.resolution, 0.5*td.resolution//td.resolution )
670
671 def test_massive_normalization(self): 671 def test_massive_normalization(self):
672 td = timedelta(microseconds=-1) 672 td = timedelta(microseconds=-1)
673 self.assertEqual((td.days, td.seconds, td.microseconds), 673 self.assertEqual((td.days, td.seconds, td.microseconds),
674 (-1, 24*3600-1, 999999)) 674 (-1, 24*3600-1, 999999))
675 675
676 def test_bool(self): 676 def test_bool(self):
677 self.assertTrue(timedelta(1)) 677 self.assertTrue(timedelta(1))
678 self.assertTrue(timedelta(0, 1)) 678 self.assertTrue(timedelta(0, 1))
679 self.assertTrue(timedelta(0, 0, 1)) 679 self.assertTrue(timedelta(0, 0, 1))
680 self.assertTrue(timedelta(microseconds=1)) 680 self.assertTrue(timedelta(microseconds=1))
(...skipping 3131 matching lines...) Expand 10 before | Expand all | Expand 10 after
3812 datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month, 3812 datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month,
3813 as_date.day, 0, 0, 0) 3813 as_date.day, 0, 0, 0)
3814 self.assertEqual(as_datetime, datetime_sc) 3814 self.assertEqual(as_datetime, datetime_sc)
3815 self.assertEqual(datetime_sc, as_datetime) 3815 self.assertEqual(datetime_sc, as_datetime)
3816 3816
3817 def test_main(): 3817 def test_main():
3818 support.run_unittest(__name__) 3818 support.run_unittest(__name__)
3819 3819
3820 if __name__ == "__main__": 3820 if __name__ == "__main__":
3821 test_main() 3821 test_main()
OLDNEW
« no previous file with comments | « Lib/datetime.py ('k') | Modules/_datetimemodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+