@@ -1594,7 +1594,7 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1594
1594
return r ;
1595
1595
}
1596
1596
1597
- static int jv2tm (jv a , struct tm * tm ) {
1597
+ static int jv2tm (jv a , struct tm * tm , int localtime ) {
1598
1598
memset (tm , 0 , sizeof (* tm ));
1599
1599
static const size_t offsets [] = {
1600
1600
offsetof(struct tm , tm_year ),
@@ -1624,13 +1624,25 @@ static int jv2tm(jv a, struct tm *tm) {
1624
1624
jv_free (n );
1625
1625
}
1626
1626
1627
- // We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
1628
- // Setting tm_isdst to 0 is done by the memset.
1629
- // tm->tm_isdst = 0;
1627
+ if (localtime ) {
1628
+ tm -> tm_isdst = -1 ;
1629
+ mktime (tm );
1630
+ } else {
1631
+ #ifdef HAVE_TIMEGM
1632
+ timegm (tm );
1633
+ #elif HAVE_TM_TM_GMT_OFF
1634
+ // tm->tm_gmtoff = 0;
1635
+ tm -> tm_zone = "GMT" ;
1636
+ #elif HAVE_TM___TM_GMT_OFF
1637
+ // tm->__tm_gmtoff = 0;
1638
+ tm -> __tm_zone = "GMT" ;
1639
+ #endif
1640
+ // tm->tm_isdst = 0;
1630
1641
1631
- // The standard permits the tm structure to contain additional members. We
1632
- // hope it is okay to initialize them to zero, because the standard does not
1633
- // provide an alternative.
1642
+ // The standard permits the tm structure to contain additional members. We
1643
+ // hope it is okay to initialize them to zero, because the standard does not
1644
+ // provide an alternative.
1645
+ }
1634
1646
1635
1647
jv_free (a );
1636
1648
return 1 ;
@@ -1642,7 +1654,7 @@ static jv f_mktime(jq_state *jq, jv a) {
1642
1654
if (jv_get_kind (a ) != JV_KIND_ARRAY )
1643
1655
return ret_error (a , jv_string ("mktime requires array inputs" ));
1644
1656
struct tm tm ;
1645
- if (!jv2tm (a , & tm ))
1657
+ if (!jv2tm (a , & tm , 0 ))
1646
1658
return jv_invalid_with_msg (jv_string ("mktime requires parsed datetime inputs" ));
1647
1659
time_t t = my_mktime (& tm );
1648
1660
if (t == (time_t )- 1 )
@@ -1740,7 +1752,7 @@ static jv f_strftime(jq_state *jq, jv a, jv b) {
1740
1752
if (jv_get_kind (b ) != JV_KIND_STRING )
1741
1753
return ret_error2 (a , b , jv_string ("strftime/1 requires a string format" ));
1742
1754
struct tm tm ;
1743
- if (!jv2tm (a , & tm ))
1755
+ if (!jv2tm (a , & tm , 0 ))
1744
1756
return ret_error (b , jv_string ("strftime/1 requires parsed datetime inputs" ));
1745
1757
1746
1758
const char * fmt = jv_string_value (b );
@@ -1771,7 +1783,7 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
1771
1783
if (jv_get_kind (b ) != JV_KIND_STRING )
1772
1784
return ret_error2 (a , b , jv_string ("strflocaltime/1 requires a string format" ));
1773
1785
struct tm tm ;
1774
- if (!jv2tm (a , & tm ))
1786
+ if (!jv2tm (a , & tm , 1 ))
1775
1787
return ret_error (b , jv_string ("strflocaltime/1 requires parsed datetime inputs" ));
1776
1788
const char * fmt = jv_string_value (b );
1777
1789
size_t alloced = strlen (fmt ) + 100 ;
0 commit comments