mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Issue #9527: tm_gmtoff has 'correct' sign.
This commit is contained in:
		
							parent
							
								
									5f6213be2d
								
							
						
					
					
						commit
						93c9cd07b6
					
				
					 4 changed files with 11 additions and 13 deletions
				
			
		| 
						 | 
					@ -545,7 +545,7 @@ The module defines the following functions and data items:
 | 
				
			||||||
   +-------+-------------------+---------------------------------+
 | 
					   +-------+-------------------+---------------------------------+
 | 
				
			||||||
   | N/A   | :attr:`tm_zone`   | abbreviation of timezone name   |
 | 
					   | N/A   | :attr:`tm_zone`   | abbreviation of timezone name   |
 | 
				
			||||||
   +-------+-------------------+---------------------------------+
 | 
					   +-------+-------------------+---------------------------------+
 | 
				
			||||||
   | N/A   | :attr:`tm_gmtoff` | offset from UTC in seconds      |
 | 
					   | N/A   | :attr:`tm_gmtoff` | offset east of UTC in seconds   |
 | 
				
			||||||
   +-------+-------------------+---------------------------------+
 | 
					   +-------+-------------------+---------------------------------+
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   Note that unlike the C structure, the month value is a range of [1, 12], not
 | 
					   Note that unlike the C structure, the month value is a range of [1, 12], not
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1510,13 +1510,13 @@ def astimezone(self, tz=None):
 | 
				
			||||||
                # implied by tm_isdst.
 | 
					                # implied by tm_isdst.
 | 
				
			||||||
                delta = local - datetime(*_time.gmtime(ts)[:6])
 | 
					                delta = local - datetime(*_time.gmtime(ts)[:6])
 | 
				
			||||||
                dst = _time.daylight and localtm.tm_isdst > 0
 | 
					                dst = _time.daylight and localtm.tm_isdst > 0
 | 
				
			||||||
                gmtoff = _time.altzone if dst else _time.timezone
 | 
					                gmtoff = -(_time.altzone if dst else _time.timezone)
 | 
				
			||||||
                if delta == timedelta(seconds=-gmtoff):
 | 
					                if delta == timedelta(seconds=gmtoff):
 | 
				
			||||||
                    tz = timezone(delta, _time.tzname[dst])
 | 
					                    tz = timezone(delta, _time.tzname[dst])
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    tz = timezone(delta)
 | 
					                    tz = timezone(delta)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                tz = timezone(timedelta(seconds=-gmtoff), zone)
 | 
					                tz = timezone(timedelta(seconds=gmtoff), zone)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        elif not isinstance(tz, tzinfo):
 | 
					        elif not isinstance(tz, tzinfo):
 | 
				
			||||||
            raise TypeError("tz argument must be an instance of tzinfo")
 | 
					            raise TypeError("tz argument must be an instance of tzinfo")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3278,16 +3278,18 @@ def test_astimezone_default_utc(self):
 | 
				
			||||||
        self.assertEqual(dt.astimezone(None), dt)
 | 
					        self.assertEqual(dt.astimezone(None), dt)
 | 
				
			||||||
        self.assertEqual(dt.astimezone(), dt)
 | 
					        self.assertEqual(dt.astimezone(), dt)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Note that offset in TZ variable has the opposite sign to that
 | 
				
			||||||
 | 
					    # produced by %z directive.
 | 
				
			||||||
    @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
 | 
					    @support.run_with_tz('EST+05EDT,M3.2.0,M11.1.0')
 | 
				
			||||||
    def test_astimezone_default_eastern(self):
 | 
					    def test_astimezone_default_eastern(self):
 | 
				
			||||||
        dt = self.theclass(2012, 11, 4, 6, 30, tzinfo=timezone.utc)
 | 
					        dt = self.theclass(2012, 11, 4, 6, 30, tzinfo=timezone.utc)
 | 
				
			||||||
        local = dt.astimezone()
 | 
					        local = dt.astimezone()
 | 
				
			||||||
        self.assertEqual(dt, local)
 | 
					        self.assertEqual(dt, local)
 | 
				
			||||||
        self.assertEqual(local.strftime("%z %Z"), "+0500 EST")
 | 
					        self.assertEqual(local.strftime("%z %Z"), "-0500 EST")
 | 
				
			||||||
        dt = self.theclass(2012, 11, 4, 5, 30, tzinfo=timezone.utc)
 | 
					        dt = self.theclass(2012, 11, 4, 5, 30, tzinfo=timezone.utc)
 | 
				
			||||||
        local = dt.astimezone()
 | 
					        local = dt.astimezone()
 | 
				
			||||||
        self.assertEqual(dt, local)
 | 
					        self.assertEqual(dt, local)
 | 
				
			||||||
        self.assertEqual(local.strftime("%z %Z"), "+0400 EDT")
 | 
					        self.assertEqual(local.strftime("%z %Z"), "-0400 EDT")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_aware_subtract(self):
 | 
					    def test_aware_subtract(self):
 | 
				
			||||||
        cls = self.theclass
 | 
					        cls = self.theclass
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4717,12 +4717,8 @@ local_timezone(PyDateTime_DateTime *utc_time)
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    timep = localtime(×tamp);
 | 
					    timep = localtime(×tamp);
 | 
				
			||||||
#ifdef HAVE_STRUCT_TM_TM_ZONE
 | 
					#ifdef HAVE_STRUCT_TM_TM_ZONE
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        long offset;
 | 
					 | 
				
			||||||
        offset = timep->tm_gmtoff;
 | 
					 | 
				
			||||||
    zone = timep->tm_zone;
 | 
					    zone = timep->tm_zone;
 | 
				
			||||||
        delta = new_delta(0, -offset, 0, 0);
 | 
					    delta = new_delta(0, timep->tm_gmtoff, 0, 1);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
#else /* HAVE_STRUCT_TM_TM_ZONE */
 | 
					#else /* HAVE_STRUCT_TM_TM_ZONE */
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        PyObject *local_time;
 | 
					        PyObject *local_time;
 | 
				
			||||||
| 
						 | 
					@ -4732,7 +4728,7 @@ local_timezone(PyDateTime_DateTime *utc_time)
 | 
				
			||||||
                                  utc_time->tzinfo);
 | 
					                                  utc_time->tzinfo);
 | 
				
			||||||
        if (local_time == NULL)
 | 
					        if (local_time == NULL)
 | 
				
			||||||
            goto error;
 | 
					            goto error;
 | 
				
			||||||
        delta = datetime_subtract((PyObject*)utc_time, local_time);
 | 
					        delta = datetime_subtract(local_time, (PyObject*)utc_time);
 | 
				
			||||||
        /* XXX: before relying on tzname, we should compare delta
 | 
					        /* XXX: before relying on tzname, we should compare delta
 | 
				
			||||||
           to the offset implied by timezone/altzone */
 | 
					           to the offset implied by timezone/altzone */
 | 
				
			||||||
        if (daylight && timep->tm_isdst >= 0)
 | 
					        if (daylight && timep->tm_isdst >= 0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue