Skip to content

Commit ba57db8

Browse files
committed
fixed date/time support for optional format strings
1 parent c7ebccc commit ba57db8

File tree

5 files changed

+38
-63
lines changed

5 files changed

+38
-63
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/suculent/thinx-firmware-esp8266"
88
},
9-
"version": "2.1.170",
9+
"version": "2.1.171",
1010
"authors": {
1111
"name": "Matej Sychra",
1212
"url": "https://thinx.cloud"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=THiNX
2-
version=2.1.170
2+
version=2.1.171
33
author=Matej Sychra
44
maintainer=Matej Sychra
55
sentence=A library to wrap THiNX device registration, MQTT and ESP8266HttpUpdate/ArduinoOTA

src/THiNXLib.cpp

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -814,62 +814,37 @@ long THiNX::epoch() {
814814
}
815815

816816
String THiNX::time(const char* optional_format) {
817-
818-
/*
819-
char *format = (const char *)time_format;
820-
821-
if (optional_format != NULL) {
822-
format = optional_format;
823-
}
824-
*/
825-
826-
long stamp = THiNX::epoch();
827-
struct tm lt;
828-
char res[32];
829-
(void) localtime_r(&stamp, &lt);
830-
if (strftime(res, sizeof(res), time_format, &lt) == 0) {
831-
Serial.println(F("cannot format supplied time into buffer"));
832-
}
833-
return String(res);
834-
835-
/* deprecated
836-
unsigned long stamp = THiNX::epoch();
837-
unsigned long time_unix = stamp + 3600;
838-
String time_representation = String((time_unix % 86400L) / 3600);
839-
time_representation += ":";
840-
// leading minute zero
841-
if ( ((time_unix % 3600) / 60) < 10 ) {
842-
time_representation += "0";
843-
}
844-
time_representation += String((time_unix % 3600) / 60);
845-
time_representation += ":";
846-
// leading second zero
847-
if ( ((time_unix % 3600) % 60) < 10 ) {
848-
time_representation += "0";
849-
}
850-
time_representation += String((time_unix % 3600) % 60);
851-
return String(time_representation);
852-
*/
817+
818+
char *format = strdup(time_format);
819+
if (optional_format != NULL) {
820+
format = strdup(optional_format);
821+
}
822+
823+
long stamp = THiNX::epoch();
824+
struct tm lt;
825+
char res[32];
826+
(void) localtime_r(&stamp, &lt);
827+
if (strftime(res, sizeof(res), format, &lt) == 0) {
828+
Serial.println(F("cannot format supplied time into buffer"));
829+
}
830+
return String(res);
853831
}
854832

855833
String THiNX::date(const char* optional_format) {
856-
857-
/*
858-
char *format = (const char *) date_format;
859-
860-
if (optional_format != NULL) {
861-
format = (const char *)optional_format;
862-
}*/
863-
864-
long stamp = THiNX::epoch();
865-
866-
struct tm lt;
867-
char res[32];
868-
(void) localtime_r(&stamp, &lt);
869-
if (strftime(res, sizeof(res), date_format, &lt) == 0) {
870-
Serial.println(F("cannot format supplied date into buffer"));
871-
}
872-
return String(res);
834+
835+
char *format = strdup(date_format);
836+
if (optional_format != NULL) {
837+
format = strdup(optional_format);
838+
}
839+
840+
long stamp = THiNX::epoch();
841+
struct tm lt;
842+
char res[32];
843+
(void) localtime_r(&stamp, &lt);
844+
if (strftime(res, sizeof(res), format, &lt) == 0) {
845+
Serial.println(F("cannot format supplied date into buffer"));
846+
}
847+
return String(res);
873848
}
874849

875850
/*

src/THiNXLib.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
// Provides placeholder for THINX_FIRMWARE_VERSION_SHORT
1111
#ifndef VERSION
12-
#define VERSION "2.1.169"
12+
#define VERSION "2.1.171"
1313
#endif
1414

1515
#ifndef THX_REVISION
1616
#ifdef THINX_FIRMWARE_VERSION_SHORT
1717
#define THX_REVISION THINX_FIRMWARE_VERSION_SHORT
1818
#else
19-
#define THX_REVISION "169"
19+
#define THX_REVISION "171"
2020
#endif
2121
#endif
2222

@@ -202,9 +202,9 @@ class THiNX {
202202

203203
long checkin_timeout; // next timeout millis()
204204
long checkin_interval = 3600 * 1000; // can be set externaly, defaults to 1h
205-
205+
206206
long last_checkin_millis;
207-
long last_checkin_timestamp;
207+
long last_checkin_timestamp;
208208

209209
long reboot_timeout; // next timeout millis()
210210
long reboot_interval = 86400 * 1000; // can be set externaly, defaults to 24h

src/thinx.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
const char * THINX_ALIAS = "unnamed";
66
const char * THINX_API_KEY = "0";
7-
const char * THINX_APP_VERSION = "thinx-lib-esp8266-arduino:2.1.169:2018-03-16";
7+
const char * THINX_APP_VERSION = "thinx-lib-esp8266-arduino:2.1.171:2018-03-19";
88
const char * THINX_CLOUD_URL = "thinx.cloud";
9-
const char * THINX_COMMIT_ID = "16b6719284cb56c90db02c289c80aa181df0e906";
10-
const char * THINX_FIRMWARE_VERSION = "thinx-lib-esp8266-arduino:2.1.169";
11-
const char * THINX_FIRMWARE_VERSION_SHORT = "2.1.169";
9+
const char * THINX_COMMIT_ID = "0";
10+
const char * THINX_FIRMWARE_VERSION = "thinx-lib-esp8266-arduino:2.1.171";
11+
const char * THINX_FIRMWARE_VERSION_SHORT = "2.1.171";
1212
const char * THINX_MQTT_URL = "thinx.cloud";
1313
const char * THINX_OWNER = "0";
1414
const char * THINX_PLATFORM = "platformio";

0 commit comments

Comments
 (0)