Trying to format a time and also a date, help requested #1373
-
I'm writing a pattern for some data I've got (serial data being sent to some hardware), and I'm trying to parse three bytes as a time (H:M:S). I've read the documentation, but there isn't a whole lot of examples. The data is simply the hour, minute and second as integers. So for example, 08:32:00 would be represented in the data as In addition to that, I've got two bytes that make up a date. I'd like to parse that as a date (assuming the year will be the current year). I've looked over the docs, but there's no examples of formatting dates, nor assuming data (e.g. just getting the current year) I've looked through the discussions, the documentation, and also checked out the included patterns, but I can't seem to work it out. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey, you don't really need to mess with any date-time things since the format is super easy. The stuff that's included in the standard library deals with Unix / Epoch time. A pattern for this could maybe look like this: struct DateTime {
u8 hour, minute, second;
u8 day, month;
} [[format("format_date_time")]];
fn format_date_time(ref auto dateTime) {
return std::format("{}:{}:{} {}.{}", dateTime.hour, dateTime.minute, dateTime.second, dateTime.day, dateTime.month);
}; |
Beta Was this translation helpful? Give feedback.
Hey, you don't really need to mess with any date-time things since the format is super easy. The stuff that's included in the standard library deals with Unix / Epoch time.
A pattern for this could maybe look like this: