@@ -127,46 +127,50 @@ Index: micropython/ports/esp32/modtime.c
127
127
struct timeval tv;
128
128
gettimeofday(&tv, NULL);
129
129
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) {
131
131
gettimeofday(&tv, NULL);
132
132
return mp_obj_new_int(tv.tv_sec);
133
133
}
134
134
+
135
135
+ static mp_obj_t time_timezone(size_t n_args, const mp_obj_t *args) {
136
136
+ if (n_args == 0 || args[0] == mp_const_none) {
137
+ + // Get timezone
137
138
+ char *tz = getenv("TZ");
138
139
+ if (tz == NULL) {
139
140
+ return mp_const_none;
140
141
+ } else {
141
- + char *ptr = strchr(tz, '+');
142
+ + char timezone[64] = { 0 };
143
+ + memcpy(timezone, tz, strlen(tz));
144
+ + char *ptr = strchr(timezone, '+');
142
145
+ if (ptr != NULL) {
143
146
+ *ptr = '-';
144
147
+ } else {
145
- + ptr = strchr(tz , '-');
148
+ + ptr = strchr(timezone , '-');
146
149
+ if (ptr != NULL) {
147
150
+ *ptr = '+';
148
151
+ }
149
152
+ }
150
- + return mp_obj_new_str(tz , strlen(tz ));
153
+ + return mp_obj_new_str(timezone , strlen(timezone ));
151
154
+ }
152
155
+ } 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]));
155
159
+
156
- + char *ptr = strchr(tz , '-');
160
+ + char *ptr = strchr(timezone , '-');
157
161
+ if (ptr != NULL) {
158
162
+ *ptr = '+';
159
163
+ } else {
160
- + ptr = strchr(tz , '+');
164
+ + ptr = strchr(timezone , '+');
161
165
+ if (ptr != NULL) {
162
166
+ *ptr = '-';
163
167
+ }
164
168
+ }
165
169
+
166
- + setenv("TZ", tz , 1);
170
+ + setenv("TZ", timezone , 1);
167
171
+ tzset();
168
172
+
169
- + nvs_write_str_helper(UIFLOW_NVS_NAMESPACE, "tz", tz );
173
+ + nvs_write_str_helper(UIFLOW_NVS_NAMESPACE, "tz", timezone );
170
174
+ return mp_const_none;
171
175
+ }
172
176
+ }
0 commit comments