@@ -1555,7 +1555,7 @@ static jv f_strptime(jq_state *jq, jv a, jv b) {
1555
1555
return r ;
1556
1556
}
1557
1557
1558
- static int jv2tm (jv a , struct tm * tm ) {
1558
+ static int jv2tm (jv a , struct tm * tm , int localtime ) {
1559
1559
memset (tm , 0 , sizeof (* tm ));
1560
1560
static const size_t offsets [] = {
1561
1561
offsetof(struct tm , tm_year ),
@@ -1585,13 +1585,25 @@ static int jv2tm(jv a, struct tm *tm) {
1585
1585
jv_free (n );
1586
1586
}
1587
1587
1588
- // We use UTC everywhere (gettimeofday, gmtime) and UTC does not do DST.
1589
- // Setting tm_isdst to 0 is done by the memset.
1590
- // tm->tm_isdst = 0;
1588
+ if (localtime ) {
1589
+ tm -> tm_isdst = -1 ;
1590
+ mktime (tm );
1591
+ } else {
1592
+ #ifdef HAVE_TIMEGM
1593
+ timegm (tm );
1594
+ #elif HAVE_TM_TM_GMT_OFF
1595
+ // tm->tm_gmtoff = 0;
1596
+ tm -> tm_zone = "GMT" ;
1597
+ #elif HAVE_TM___TM_GMT_OFF
1598
+ // tm->__tm_gmtoff = 0;
1599
+ tm -> __tm_zone = "GMT" ;
1600
+ #endif
1601
+ // tm->tm_isdst = 0;
1591
1602
1592
- // The standard permits the tm structure to contain additional members. We
1593
- // hope it is okay to initialize them to zero, because the standard does not
1594
- // provide an alternative.
1603
+ // The standard permits the tm structure to contain additional members. We
1604
+ // hope it is okay to initialize them to zero, because the standard does not
1605
+ // provide an alternative.
1606
+ }
1595
1607
1596
1608
jv_free (a );
1597
1609
return 1 ;
@@ -1603,7 +1615,7 @@ static jv f_mktime(jq_state *jq, jv a) {
1603
1615
if (jv_get_kind (a ) != JV_KIND_ARRAY )
1604
1616
return ret_error (a , jv_string ("mktime requires array inputs" ));
1605
1617
struct tm tm ;
1606
- if (!jv2tm (a , & tm ))
1618
+ if (!jv2tm (a , & tm , 0 ))
1607
1619
return jv_invalid_with_msg (jv_string ("mktime requires parsed datetime inputs" ));
1608
1620
time_t t = my_mktime (& tm );
1609
1621
if (t == (time_t )- 1 )
@@ -1701,7 +1713,7 @@ static jv f_strftime(jq_state *jq, jv a, jv b) {
1701
1713
if (jv_get_kind (b ) != JV_KIND_STRING )
1702
1714
return ret_error2 (a , b , jv_string ("strftime/1 requires a string format" ));
1703
1715
struct tm tm ;
1704
- if (!jv2tm (a , & tm ))
1716
+ if (!jv2tm (a , & tm , 0 ))
1705
1717
return ret_error (b , jv_string ("strftime/1 requires parsed datetime inputs" ));
1706
1718
1707
1719
const char * fmt = jv_string_value (b );
@@ -1732,7 +1744,7 @@ static jv f_strflocaltime(jq_state *jq, jv a, jv b) {
1732
1744
if (jv_get_kind (b ) != JV_KIND_STRING )
1733
1745
return ret_error2 (a , b , jv_string ("strflocaltime/1 requires a string format" ));
1734
1746
struct tm tm ;
1735
- if (!jv2tm (a , & tm ))
1747
+ if (!jv2tm (a , & tm , 1 ))
1736
1748
return ret_error (b , jv_string ("strflocaltime/1 requires parsed datetime inputs" ));
1737
1749
const char * fmt = jv_string_value (b );
1738
1750
size_t alloced = strlen (fmt ) + 100 ;
0 commit comments