Skip to content

Commit 066c601

Browse files
committed
Date: fix parsing of ISO8601 timezones (+HHMM worked, but +HH:MM and +HH added) (fix #2669)
1 parent 81b6e49 commit 066c601

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
STM32: Ensure setDeepSleep(1) will only sleep if there are no active PWM outputs
44
Pin.getInfo().negated now set if pin negated in firmware
55
Bangle.js: Add Bangle.setOptions({stepCounterDisabled:bool}) to disable the step counter
6+
Date: fix parsing of ISO8601 timezones (+HHMM worked, but +HH:MM and +HH added) (fix #2669)
67

78
2v28 : Add `E.internal` as a way to access the 'hidden root' containing Espruino internal variables that previously needed `global["\xff"]`
89
Bangle.js: Fix back handler not removed when using E.setUI with a back button but without widgets (#2636)

src/jswrap_date.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ int jsdGetEffectiveTimeZone(JsVarFloat ms, bool is_local_time, bool *is_dst) {
157157

158158
// this needs to be called just before a TimeInDay is used -- unless the TimeInDay timezone has been determined by other means.
159159
void setCorrectTimeZone(TimeInDay *td) {
160-
td->zone = 0;
161160
td->zone = jsdGetEffectiveTimeZone(fromTimeInDay(td),true,&(td->is_dst));
162161
}
163162

@@ -837,15 +836,25 @@ static bool _parse_time(TimeInDay *time, int initialChars) {
837836
setCorrectTimeZone(time);
838837
}
839838
}
840-
if (lex->tk == '+' || lex->tk == '-') {
839+
if (lex->tk == '+' || lex->tk == '-') { // Timezone: HH:MM, HHMM, HH
841840
int sign = lex->tk == '+' ? 1 : -1;
842841
jslGetNextToken();
843842
if (lex->tk == LEX_INT) {
844843
int i = _parse_int();
845-
// correct the fact that it's HHMM and turn it into just minutes
846-
i = (i%100) + ((i/100)*60);
847-
time->zone = i*sign;
844+
int tzLength = jslGetTokenLength();
845+
if (tzLength==4) {
846+
// correct the fact that it's HHMM and turn it into just minutes
847+
i = (i%100) + ((i/100)*60);
848+
} else
849+
i *= 60; // length = 2 => hours
848850
jslGetNextToken();
851+
if (tzLength==2 && lex->tk == ':') {
852+
jslGetNextToken();
853+
if (lex->tk == LEX_INT) {
854+
i += _parse_int();
855+
}
856+
}
857+
time->zone = i*sign;
849858
} else {
850859
setCorrectTimeZone(time);
851860
}

0 commit comments

Comments
 (0)