Skip to content

Commit 8006ac3

Browse files
committed
pathces: Fix timezone reading error.
Signed-off-by: lbuque <[email protected]>
1 parent 793b9d8 commit 8006ac3

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

m5stack/patches/0006-modtime-add-timezone-method.patch

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,46 +127,50 @@ Index: micropython/ports/esp32/modtime.c
127127
struct timeval tv;
128128
gettimeofday(&tv, NULL);
129129
timeutils_struct_time_t tm;
130-
@@ -56,3 +95,46 @@ static mp_obj_t mp_time_time_get(void) {
130+
@@ -56,3 +95,50 @@ static mp_obj_t mp_time_time_get(void) {
131131
gettimeofday(&tv, NULL);
132132
return mp_obj_new_int(tv.tv_sec);
133133
}
134134
+
135135
+static mp_obj_t time_timezone(size_t n_args, const mp_obj_t *args) {
136136
+ if (n_args == 0 || args[0] == mp_const_none) {
137+
+ // Get timezone
137138
+ char *tz = getenv("TZ");
138139
+ if (tz == NULL) {
139140
+ return mp_const_none;
140141
+ } else {
141-
+ char *ptr = strchr(tz, '+');
142+
+ char timezone[64] = { 0 };
143+
+ memcpy(timezone, tz, strlen(tz));
144+
+ char *ptr = strchr(timezone, '+');
142145
+ if (ptr != NULL) {
143146
+ *ptr = '-';
144147
+ } else {
145-
+ ptr = strchr(tz, '-');
148+
+ ptr = strchr(timezone, '-');
146149
+ if (ptr != NULL) {
147150
+ *ptr = '+';
148151
+ }
149152
+ }
150-
+ return mp_obj_new_str(tz, strlen(tz));
153+
+ return mp_obj_new_str(timezone, strlen(timezone));
151154
+ }
152155
+ } else {
153-
+ char tz[64] = { 0 };
154-
+ snprintf(tz, sizeof(tz), "%s", mp_obj_str_get_str(args[0]));
156+
+ // Set timezone
157+
+ char timezone[64] = { 0 };
158+
+ snprintf(timezone, sizeof(timezone), "%s", mp_obj_str_get_str(args[0]));
155159
+
156-
+ char *ptr = strchr(tz, '-');
160+
+ char *ptr = strchr(timezone, '-');
157161
+ if (ptr != NULL) {
158162
+ *ptr = '+';
159163
+ } else {
160-
+ ptr = strchr(tz, '+');
164+
+ ptr = strchr(timezone, '+');
161165
+ if (ptr != NULL) {
162166
+ *ptr = '-';
163167
+ }
164168
+ }
165169
+
166-
+ setenv("TZ", tz, 1);
170+
+ setenv("TZ", timezone, 1);
167171
+ tzset();
168172
+
169-
+ nvs_write_str_helper(UIFLOW_NVS_NAMESPACE, "tz", tz);
173+
+ nvs_write_str_helper(UIFLOW_NVS_NAMESPACE, "tz", timezone);
170174
+ return mp_const_none;
171175
+ }
172176
+}

0 commit comments

Comments
 (0)