Skip to content

Commit eea2283

Browse files
committed
Merge timelib 2021.13
1 parent c2bdaa4 commit eea2283

File tree

3 files changed

+55
-18
lines changed

3 files changed

+55
-18
lines changed

ext/date/lib/interval.c

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,56 @@
2626
#include "timelib_private.h"
2727
#include <math.h>
2828

29-
timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
29+
static void sort_old_to_new(timelib_time **one, timelib_time **two, timelib_rel_time *rt)
3030
{
31-
timelib_rel_time *rt;
3231
timelib_time *swp;
33-
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
34-
timelib_time_offset *trans = NULL;
3532

33+
/* Check whether date/times need to be inverted. If both times are
34+
* TIMELIB_ZONETYPE_ID times with the same TZID, we use the y-s + us fields. */
35+
if (
36+
(*one)->zone_type == TIMELIB_ZONETYPE_ID &&
37+
(*two)->zone_type == TIMELIB_ZONETYPE_ID &&
38+
(strcmp((*one)->tz_info->name, (*two)->tz_info->name) != 0)
39+
) {
40+
if (
41+
((*one)->y > (*two)->y) ||
42+
((*one)->y == (*two)->y && (*one)->m > (*two)->m) ||
43+
((*one)->y == (*two)->y && (*one)->m == (*two)->m && (*one)->d > (*two)->d) ||
44+
((*one)->y == (*two)->y && (*one)->m == (*two)->m && (*one)->d == (*two)->d && (*one)->h > (*two)->h) ||
45+
((*one)->y == (*two)->y && (*one)->m == (*two)->m && (*one)->d == (*two)->d && (*one)->h == (*two)->h && (*one)->i > (*two)->i) ||
46+
((*one)->y == (*two)->y && (*one)->m == (*two)->m && (*one)->d == (*two)->d && (*one)->h == (*two)->h && (*one)->i == (*two)->i && (*one)->s > (*two)->s) ||
47+
((*one)->y == (*two)->y && (*one)->m == (*two)->m && (*one)->d == (*two)->d && (*one)->h == (*two)->h && (*one)->i == (*two)->i && (*one)->s == (*two)->s && (*one)->us > (*two)->us)
48+
) {
49+
swp = *two;
50+
*two = *one;
51+
*one = swp;
52+
rt->invert = 1;
53+
}
54+
return;
55+
}
3656

37-
rt = timelib_rel_time_ctor();
38-
rt->invert = 0;
57+
/* Fall back to using the SSE instead to rearrange */
3958
if (
40-
(one->sse > two->sse) ||
41-
(one->sse == two->sse && one->us > two->us)
59+
((*one)->sse > (*two)->sse) ||
60+
((*one)->sse == (*two)->sse && (*one)->us > (*two)->us)
4261
) {
43-
swp = two;
44-
two = one;
45-
one = swp;
62+
swp = *two;
63+
*two = *one;
64+
*one = swp;
4665
rt->invert = 1;
4766
}
67+
}
68+
69+
timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
70+
{
71+
timelib_rel_time *rt;
72+
timelib_sll dst_corr = 0, dst_h_corr = 0, dst_m_corr = 0;
73+
timelib_time_offset *trans = NULL;
74+
75+
rt = timelib_rel_time_ctor();
76+
rt->invert = 0;
77+
78+
sort_old_to_new(&one, &two, rt);
4879

4980
/* Calculate correction for UTC offset changes between first and second SSE */
5081
dst_corr = two->z - one->z;
@@ -64,7 +95,7 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
6495
/* Fall Back: Cater for transition period, where rt->invert is 0, but there are negative numbers */
6596
if (one->dst == 1 && two->dst == 0) {
6697
/* First for two "Type 3" times */
67-
if (one->zone_type == 3 && two->zone_type == 3) {
98+
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID) {
6899
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
69100
if (trans) {
70101
if (one->sse >= trans->transition_time + dst_corr && one->sse < trans->transition_time) {
@@ -89,8 +120,8 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
89120

90121
timelib_do_rel_normalize(rt->invert ? one : two, rt);
91122

92-
/* Do corrections for "Type 3" times */
93-
if (one->zone_type == 3 && two->zone_type == 3 && strcmp(one->tz_info->name, two->tz_info->name) == 0) {
123+
/* Do corrections for "Type 3" times with the same TZID */
124+
if (one->zone_type == TIMELIB_ZONETYPE_ID && two->zone_type == TIMELIB_ZONETYPE_ID && strcmp(one->tz_info->name, two->tz_info->name) == 0) {
94125
if (one->dst == 1 && two->dst == 0) { /* Fall Back */
95126
if (two->tz_info) {
96127
trans = timelib_get_time_zone_info(two->sse, two->tz_info);
@@ -130,11 +161,16 @@ timelib_rel_time *timelib_diff(timelib_time *one, timelib_time *two)
130161
}
131162
} else {
132163
/* Then for all the others */
133-
if (one->zone_type == 3 && two->zone_type == 3) {
164+
if (
165+
(one->zone_type == 3 && two->zone_type == 3) ||
166+
(one->zone_type != 3 && two->zone_type == 3 && one->z == two->z) ||
167+
(one->zone_type == 3 && two->zone_type != 3 && one->z == two->z)
168+
) {
134169
rt->h -= dst_h_corr;
135170
} else {
136171
rt->h -= dst_h_corr + (two->dst - one->dst);
137172
}
173+
138174
rt->i -= dst_m_corr;
139175

140176
timelib_do_rel_normalize(rt->invert ? one : two, rt);

ext/date/lib/parse_date.re

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ timelib_long timelib_parse_zone(const char **ptr, int *dst, timelib_time *t, int
909909
offset = timelib_lookup_abbr(ptr, dst, &tz_abbr, &found);
910910
if (found) {
911911
t->zone_type = TIMELIB_ZONETYPE_ABBR;
912+
t->dst = *dst;
912913
timelib_time_tz_abbr_update(t, tz_abbr);
913914
}
914915

ext/date/lib/timelib.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
# include "timelib_config.h"
3131
#endif
3232

33-
#define TIMELIB_VERSION 202112
34-
#define TIMELIB_EXTENDED_VERSION 20211201
35-
#define TIMELIB_ASCII_VERSION "2021.12"
33+
#define TIMELIB_VERSION 202113
34+
#define TIMELIB_EXTENDED_VERSION 20211301
35+
#define TIMELIB_ASCII_VERSION "2021.13"
3636

3737
#include <stdlib.h>
3838
#include <stdbool.h>

0 commit comments

Comments
 (0)