@@ -1522,29 +1522,6 @@ PyDoc_STRVAR(get_clock_info_doc,
1522
1522
\n\
1523
1523
Get information of the specified clock." );
1524
1524
1525
- #if !defined(HAVE_TZNAME ) || defined(__GLIBC__ ) || defined(__CYGWIN__ )
1526
- static void
1527
- get_zone (char * zone , int n , struct tm * p )
1528
- {
1529
- #ifdef HAVE_STRUCT_TM_TM_ZONE
1530
- strncpy (zone , p -> tm_zone ? p -> tm_zone : " " , n );
1531
- #else
1532
- tzset ();
1533
- strftime (zone , n , "%Z" , p );
1534
- #endif
1535
- }
1536
-
1537
- static int
1538
- get_gmtoff (time_t t , struct tm * p )
1539
- {
1540
- #ifdef HAVE_STRUCT_TM_TM_ZONE
1541
- return p -> tm_gmtoff ;
1542
- #else
1543
- return timegm (p ) - t ;
1544
- #endif
1545
- }
1546
- #endif /* !defined(HAVE_TZNAME) || defined(__GLIBC__) || defined(__CYGWIN__) */
1547
-
1548
1525
static void
1549
1526
PyInit_timezone (PyObject * m ) {
1550
1527
/* This code moved from PyInit_time wholesale to allow calling it from
@@ -1563,65 +1540,35 @@ PyInit_timezone(PyObject *m) {
1563
1540
1564
1541
And I'm lazy and hate C so nyer.
1565
1542
*/
1566
- #if defined(HAVE_TZNAME ) && !defined(__GLIBC__ ) && !defined(__CYGWIN__ )
1567
1543
PyObject * otz0 , * otz1 ;
1568
1544
tzset ();
1569
1545
PyModule_AddIntConstant (m , "timezone" , timezone );
1570
1546
#ifdef HAVE_ALTZONE
1571
1547
PyModule_AddIntConstant (m , "altzone" , altzone );
1572
- #else
1573
- PyModule_AddIntConstant (m , "altzone" , timezone - 3600 );
1574
- #endif
1575
- PyModule_AddIntConstant (m , "daylight" , daylight );
1576
- otz0 = PyUnicode_DecodeLocale (tzname [0 ], "surrogateescape" );
1577
- otz1 = PyUnicode_DecodeLocale (tzname [1 ], "surrogateescape" );
1578
- PyModule_AddObject (m , "tzname" , Py_BuildValue ("(NN)" , otz0 , otz1 ));
1579
- #else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
1548
+ #elif defined(HAVE_STRUCT_TM_TM_ZONE )
1580
1549
{
1581
- #define YEAR ((time_t)(( 365 * 24 + 6) * 3600))
1550
+ static const time_t YEAR = ( 365 * 24 + 6 ) * 3600 ;
1582
1551
time_t t ;
1583
1552
struct tm p ;
1584
1553
long janzone , julyzone ;
1585
- char janname [10 ], julyname [10 ];
1586
1554
t = (time ((time_t * )0 ) / YEAR ) * YEAR ;
1587
1555
_PyTime_localtime (t , & p );
1588
- get_zone (janname , 9 , & p );
1589
- janzone = - get_gmtoff (t , & p );
1590
- janname [9 ] = '\0' ;
1556
+ janzone = - p .tm_gmtoff ;
1591
1557
t += YEAR /2 ;
1592
1558
_PyTime_localtime (t , & p );
1593
- get_zone (julyname , 9 , & p );
1594
- julyzone = - get_gmtoff (t , & p );
1595
- julyname [9 ] = '\0' ;
1596
-
1597
- if ( janzone < julyzone ) {
1598
- /* DST is reversed in the southern hemisphere */
1599
- PyModule_AddIntConstant (m , "timezone" , julyzone );
1600
- PyModule_AddIntConstant (m , "altzone" , janzone );
1601
- PyModule_AddIntConstant (m , "daylight" ,
1602
- janzone != julyzone );
1603
- PyModule_AddObject (m , "tzname" ,
1604
- Py_BuildValue ("(zz)" ,
1605
- julyname , janname ));
1606
- } else {
1607
- PyModule_AddIntConstant (m , "timezone" , janzone );
1608
- PyModule_AddIntConstant (m , "altzone" , julyzone );
1609
- PyModule_AddIntConstant (m , "daylight" ,
1610
- janzone != julyzone );
1611
- PyModule_AddObject (m , "tzname" ,
1612
- Py_BuildValue ("(zz)" ,
1613
- janname , julyname ));
1614
- }
1559
+ julyzone = - p .tm_gmtoff ;
1560
+
1561
+ // DST is reversed in the southern hemisphere.
1562
+ PyModule_AddIntConstant (m , "altzone" ,
1563
+ (janzone < julyzone ) ? janzone : julyzone );
1615
1564
}
1616
- #ifdef __CYGWIN__
1617
- tzset ();
1618
- PyModule_AddIntConstant (m , "timezone" , _timezone );
1619
- PyModule_AddIntConstant (m , "altzone" , _timezone - 3600 );
1620
- PyModule_AddIntConstant (m , "daylight" , _daylight );
1621
- PyModule_AddObject (m , "tzname" ,
1622
- Py_BuildValue ("(zz)" , _tzname [0 ], _tzname [1 ]));
1623
- #endif /* __CYGWIN__ */
1624
- #endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
1565
+ #else
1566
+ PyModule_AddIntConstant (m , "altzone" , timezone - 3600 );
1567
+ #endif
1568
+ PyModule_AddIntConstant (m , "daylight" , daylight );
1569
+ otz0 = PyUnicode_DecodeLocale (tzname [0 ], "surrogateescape" );
1570
+ otz1 = PyUnicode_DecodeLocale (tzname [1 ], "surrogateescape" );
1571
+ PyModule_AddObject (m , "tzname" , Py_BuildValue ("(NN)" , otz0 , otz1 ));
1625
1572
}
1626
1573
1627
1574
0 commit comments