Merge pull request #173 from gounselor/master

Added DateTime(char *iso8601date) constructor.
This commit is contained in:
dherrada
2020-06-29 10:38:01 -04:00
committed by GitHub
2 changed files with 35 additions and 0 deletions
+34
View File
@@ -367,6 +367,40 @@ DateTime::DateTime(const __FlashStringHelper *date,
ss = conv2d(buff + 6);
}
/**************************************************************************/
/*!
@brief Constructor for creating a DateTime from an ISO8601 date string.
This constructor expects its parameters to be a string in the
https://en.wikipedia.org/wiki/ISO_8601 format, e.g:
"2020-06-25T15:29:37"
Usage:
```
DateTime dt("2020-06-25T15:29:37");
```
@note The year must be > 2000, as only the yOff is considered.
@param iso8601dateTime
A dateTime string in iso8601 format,
e.g. "2020-06-25T15:29:37".
*/
/**************************************************************************/
DateTime::DateTime(const char *iso8601dateTime) {
char ref[] = "2000-01-01T00:00:00";
memcpy(ref, iso8601dateTime, strlen(ref));
yOff = conv2d(ref + 2);
m = conv2d(ref + 5);
d = conv2d(ref + 8);
hh = conv2d(ref + 11);
mm = conv2d(ref + 14);
ss = conv2d(ref + 17);
}
/**************************************************************************/
/*!
@brief Check whether this DateTime is valid.
+1
View File
@@ -79,6 +79,7 @@ public:
DateTime(const DateTime &copy);
DateTime(const char *date, const char *time);
DateTime(const __FlashStringHelper *date, const __FlashStringHelper *time);
DateTime(const char *iso8601date);
bool isValid() const;
char *toString(char *buffer);