Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inline std::string FormatTimeSpan(double Time)
- {
- using namespace std;
- string names[] = {
- "second",
- "miniute",
- "hour",
- "day",
- "week",
- "year"
- };
- double ajustment[] = {
- 60, // seconds
- 60, // minutes, minuets in
- 60, // hour, hours in
- 24, // day, days in
- 7, // week, weeks in,
- 52
- };
- string ret;
- double units = Time;
- for(int i = 0; i < sizeof(names); i++)
- {
- long long unit = fmod(units, ajustment[i+1]);
- units = units / ajustment[i+1];
- string unit_name = names[i];
- if(unit != 1)
- unit_name.append("s");
- string str_unit;
- stringstream str;
- str << unit;
- str >> str_unit;
- ret = str_unit + " " + unit_name + " " + ret;
- if(units < 1)
- break;
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement