mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Issue #23517: Fix implementation of the ROUND_HALF_UP rounding mode in
datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp(). microseconds sign should be kept before rounding.
This commit is contained in:
		
							parent
							
								
									19bbb9af67
								
							
						
					
					
						commit
						adfefa527a
					
				
					 4 changed files with 43 additions and 40 deletions
				
			
		|  | @ -668,6 +668,8 @@ def test_microsecond_rounding(self): | |||
|         eq(td(milliseconds=-0.6/1000), td(microseconds=-1)) | ||||
|         eq(td(seconds=0.5/10**6), td(microseconds=1)) | ||||
|         eq(td(seconds=-0.5/10**6), td(microseconds=-1)) | ||||
|         eq(td(seconds=1/2**7), td(microseconds=7813)) | ||||
|         eq(td(seconds=-1/2**7), td(microseconds=-7813)) | ||||
| 
 | ||||
|         # Rounding due to contributions from more than one field. | ||||
|         us_per_hour = 3600e6 | ||||
|  | @ -1842,8 +1844,8 @@ def test_timestamp_aware(self): | |||
|                          18000 + 3600 + 2*60 + 3 + 4*1e-6) | ||||
| 
 | ||||
|     def test_microsecond_rounding(self): | ||||
|         for fts in [self.theclass.fromtimestamp, | ||||
|                     self.theclass.utcfromtimestamp]: | ||||
|         for fts in (datetime.fromtimestamp, | ||||
|                     self.theclass.utcfromtimestamp): | ||||
|             zero = fts(0) | ||||
|             self.assertEqual(zero.second, 0) | ||||
|             self.assertEqual(zero.microsecond, 0) | ||||
|  | @ -1874,6 +1876,12 @@ def test_microsecond_rounding(self): | |||
|             t = fts(0.9999999) | ||||
|             self.assertEqual(t.second, 1) | ||||
|             self.assertEqual(t.microsecond, 0) | ||||
|             t = fts(1/2**7) | ||||
|             self.assertEqual(t.second, 0) | ||||
|             self.assertEqual(t.microsecond, 7813) | ||||
|             t = fts(-1/2**7) | ||||
|             self.assertEqual(t.second, 59) | ||||
|             self.assertEqual(t.microsecond, 992187) | ||||
| 
 | ||||
|     def test_insane_fromtimestamp(self): | ||||
|         # It's possible that some platform maps time_t to double, | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner