diff options
author | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
---|---|---|
committer | Jon Santmyer <jon@jonsantmyer.com> | 2022-06-22 17:41:59 -0400 |
commit | 5e3a2492c7bb73daa4e27398daaf490d09980ff3 (patch) | |
tree | 75178d823d596b6a898002c3f1d45b9ceede0e1e /src/units.cpp | |
download | systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.gz systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.tar.bz2 systemviewer-5e3a2492c7bb73daa4e27398daaf490d09980ff3.zip |
Base system viewer with data loaded from csv files
Diffstat (limited to 'src/units.cpp')
-rw-r--r-- | src/units.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/units.cpp b/src/units.cpp new file mode 100644 index 0000000..7cc7d61 --- /dev/null +++ b/src/units.cpp @@ -0,0 +1,61 @@ +#include "units.hpp" +#include <sstream> +#include <cstring> +#include <iostream> + +namespace unit { + +std::string +Time::format(const char *fmt) +{ + std::stringstream ss; + for(; *fmt; fmt++) { + if(*fmt != '%') { + ss << *fmt; + continue; + } + fmt++; + switch(*fmt) { + case '%': + ss << '%'; + break; + case 'Y': + ss << real_years(); + break; + case 'C': + ss << years(); + break; + case 'S': { + Time year = current_year(); + ss << month_str[year.months()]; + break; } + case 'M': { + Time year = current_year(); + ss << year.months(); + break; } + case 'W': { + Time month = current_month(); + ss << month.weeks(); + break; } + case 'D': { + Time month = current_month(); + ss << month.days(); + break; } + case 'H': { + Time day = current_day(); + ss << day.hours(); + break; } + case 'm': { + Time hour = current_hour(); + ss << hour.minutes(); + break; } + case 's': { + Time minute = current_minute(); + ss << minute.seconds(); + break; } + } + } + return ss.str(); +} + +} |