mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-09-04 10:37:19 +02:00
Variant
- Rewrite ::operator std::string to yield more accurate duration renditions.
This commit is contained in:
parent
3727d2f09c
commit
bd53dd2aeb
1 changed files with 13 additions and 14 deletions
|
@ -1556,28 +1556,27 @@ Variant::operator std::string () const
|
||||||
case type_duration:
|
case type_duration:
|
||||||
{
|
{
|
||||||
time_t t = _duration;
|
time_t t = _duration;
|
||||||
|
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
int seconds = t % 60; t /= 60;
|
|
||||||
int minutes = t % 60; t /= 60;
|
|
||||||
int hours = t % 24; t /= 24;
|
|
||||||
int days = t % 30; t /= 30;
|
|
||||||
int months = t % 12; t /= 12;
|
|
||||||
int years = t;
|
|
||||||
|
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << 'P';
|
s << 'P';
|
||||||
|
|
||||||
|
int years = t / (365 * 86400); t -= years * 365 * 86400;
|
||||||
|
int days = t / 86400; t -= days * 86400;
|
||||||
|
|
||||||
if (years) s << years << 'Y';
|
if (years) s << years << 'Y';
|
||||||
if (months) s << months << 'M';
|
|
||||||
if (days) s << days << 'D';
|
if (days) s << days << 'D';
|
||||||
|
|
||||||
|
int hours = t / 3600; t -= hours * 3600;
|
||||||
|
int minutes = t / 60; t -= minutes * 60;
|
||||||
|
int seconds = t;
|
||||||
|
|
||||||
if (hours || minutes || seconds)
|
if (hours || minutes || seconds)
|
||||||
{
|
{
|
||||||
s << 'T';
|
s << 'T';
|
||||||
if (hours) s << hours << 'H';
|
if (hours) s << hours << 'h';
|
||||||
if (minutes) s << minutes << 'M';
|
if (minutes) s << minutes << 'm';
|
||||||
if (seconds) s << seconds << 'S';
|
if (seconds) s << seconds << 's';
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.str ();
|
return s.str ();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue