
Originally Posted by
PaulStoffregen
When using the new DateTimeFields in MTP, please keep in mind it is slightly different than TimeElements. It follows C library struct tm format. The month is 0-based, not 1-12 as in TimeElements. The year is offset by 1900, not 1970.
Code:
// DateTimeFields follows C library "struct tm" convention, but uses much less memory
typedef struct {
uint8_t sec; // 0-59
uint8_t min; // 0-59
uint8_t hour; // 0-23
uint8_t wday; // 0-6, 0=sunday
uint8_t mday; // 1-31
uint8_t mon; // 0-11
uint8_t year; // 70-206, 70=1970, 206=2106
} DateTimeFields;
Good heads up... I need to update some more of my WIP for this.
How important is the wday field?
I noticed the 1900 vs 1970...
I have converted code but now debugging...
But I know from this, my conversion to and from MTP dates needs more adjustment:
Code:
case MTP_PROPERTY_DATE_MODIFIED: //0xDC09:
{
#ifdef MTP_SUPPORT_MODIFY_DATE
// String is like: YYYYMMDDThhmmss.s
uint32_t dt;
DateTimeFields dtf;
if (storage_->getModifyTime(p1, dt)) {
// going to use the buffer name to output
breakTime(dt, dtf);
snprintf(name, MAX_FILENAME_LEN, "%04u%02u%02uT%02u%02u%02u",
dtf.year+1900, dtf.mon, dtf.mday, dtf.hour, dtf.min, dtf.sec);
writestring(name);
printf("Modify (%x)Date/time:%s\n", dt, name);
break;
}
#endif
}
And the reverse function as well...