mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601p: Renamed ::_value to ::_period
This commit is contained in:
parent
219f23de33
commit
bb53ae17ae
5 changed files with 41 additions and 41 deletions
|
@ -300,7 +300,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value)
|
||||||
ISO8601p iso;
|
ISO8601p iso;
|
||||||
std::string::size_type cursor = 0;
|
std::string::size_type cursor = 0;
|
||||||
if (iso.parse (period, cursor))
|
if (iso.parse (period, cursor))
|
||||||
value = Variant ((time_t) iso._value, Variant::type_duration);
|
value = Variant ((time_t) iso, Variant::type_duration);
|
||||||
else
|
else
|
||||||
value = Variant ((time_t) ISO8601p (ref.get (canonical)), Variant::type_duration);
|
value = Variant ((time_t) ISO8601p (ref.get (canonical)), Variant::type_duration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,7 +592,7 @@ ISO8601p::ISO8601p ()
|
||||||
ISO8601p::ISO8601p (time_t input)
|
ISO8601p::ISO8601p (time_t input)
|
||||||
{
|
{
|
||||||
clear ();
|
clear ();
|
||||||
_value = input;
|
_period = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -605,7 +605,7 @@ ISO8601p::ISO8601p (const std::string& input)
|
||||||
time_t value = (time_t) strtol (input.c_str (), NULL, 10);
|
time_t value = (time_t) strtol (input.c_str (), NULL, 10);
|
||||||
if (value == 0 || value > 60)
|
if (value == 0 || value > 60)
|
||||||
{
|
{
|
||||||
_value = value;
|
_period = value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,7 +630,7 @@ ISO8601p& ISO8601p::operator= (const ISO8601p& other)
|
||||||
_hours = other._hours;
|
_hours = other._hours;
|
||||||
_minutes = other._minutes;
|
_minutes = other._minutes;
|
||||||
_seconds = other._seconds;
|
_seconds = other._seconds;
|
||||||
_value = other._value;
|
_period = other._period;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
@ -639,27 +639,27 @@ ISO8601p& ISO8601p::operator= (const ISO8601p& other)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool ISO8601p::operator< (const ISO8601p& other)
|
bool ISO8601p::operator< (const ISO8601p& other)
|
||||||
{
|
{
|
||||||
return _value < other._value;
|
return _period < other._period;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool ISO8601p::operator> (const ISO8601p& other)
|
bool ISO8601p::operator> (const ISO8601p& other)
|
||||||
{
|
{
|
||||||
return _value > other._value;
|
return _period > other._period;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
ISO8601p::operator std::string () const
|
ISO8601p::operator std::string () const
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << _value;
|
s << _period;
|
||||||
return s.str ();
|
return s.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
ISO8601p::operator time_t () const
|
ISO8601p::operator time_t () const
|
||||||
{
|
{
|
||||||
return _value;
|
return _period;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -732,7 +732,7 @@ bool ISO8601p::parse (const std::string& input, std::string::size_type& start)
|
||||||
if (durations[i].unit == unit &&
|
if (durations[i].unit == unit &&
|
||||||
durations[i].standalone == true)
|
durations[i].standalone == true)
|
||||||
{
|
{
|
||||||
_value = static_cast <int> (durations[i].seconds);
|
_period = static_cast <int> (durations[i].seconds);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -781,7 +781,7 @@ bool ISO8601p::parse (const std::string& input, std::string::size_type& start)
|
||||||
if (durations[i].unit == unit)
|
if (durations[i].unit == unit)
|
||||||
{
|
{
|
||||||
seconds = durations[i].seconds;
|
seconds = durations[i].seconds;
|
||||||
_value = static_cast <int> (quantity * static_cast <double> (seconds));
|
_period = static_cast <int> (quantity * static_cast <double> (seconds));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -801,15 +801,15 @@ void ISO8601p::clear ()
|
||||||
_hours = 0;
|
_hours = 0;
|
||||||
_minutes = 0;
|
_minutes = 0;
|
||||||
_seconds = 0;
|
_seconds = 0;
|
||||||
_value = 0;
|
_period = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
const std::string ISO8601p::format () const
|
const std::string ISO8601p::format () const
|
||||||
{
|
{
|
||||||
if (_value)
|
if (_period)
|
||||||
{
|
{
|
||||||
time_t t = _value;
|
time_t t = _period;
|
||||||
int seconds = t % 60; t /= 60;
|
int seconds = t % 60; t /= 60;
|
||||||
int minutes = t % 60; t /= 60;
|
int minutes = t % 60; t /= 60;
|
||||||
int hours = t % 24; t /= 24;
|
int hours = t % 24; t /= 24;
|
||||||
|
@ -839,15 +839,15 @@ const std::string ISO8601p::format () const
|
||||||
const std::string ISO8601p::formatVague () const
|
const std::string ISO8601p::formatVague () const
|
||||||
{
|
{
|
||||||
char formatted[24];
|
char formatted[24];
|
||||||
float days = (float) _value / 86400.0;
|
float days = (float) _period / 86400.0;
|
||||||
|
|
||||||
if (_value >= 86400 * 365) sprintf (formatted, "%.1fy", (days / 365.0));
|
if (_period >= 86400 * 365) sprintf (formatted, "%.1fy", (days / 365.0));
|
||||||
else if (_value >= 86400 * 84) sprintf (formatted, "%1dmo", (int) (days / 30));
|
else if (_period >= 86400 * 84) sprintf (formatted, "%1dmo", (int) (days / 30));
|
||||||
else if (_value >= 86400 * 13) sprintf (formatted, "%dw", (int) (float) (days / 7.0));
|
else if (_period >= 86400 * 13) sprintf (formatted, "%dw", (int) (float) (days / 7.0));
|
||||||
else if (_value >= 86400) sprintf (formatted, "%dd", (int) days);
|
else if (_period >= 86400) sprintf (formatted, "%dd", (int) days);
|
||||||
else if (_value >= 3600) sprintf (formatted, "%dh", (int) (_value / 3600));
|
else if (_period >= 3600) sprintf (formatted, "%dh", (int) (_period / 3600));
|
||||||
else if (_value >= 60) sprintf (formatted, "%dmin", (int) (_value / 60));
|
else if (_period >= 60) sprintf (formatted, "%dmin", (int) (_period / 60));
|
||||||
else if (_value >= 1) sprintf (formatted, "%ds", (int) _value);
|
else if (_period >= 1) sprintf (formatted, "%ds", (int) _period);
|
||||||
else formatted[0] = '\0';
|
else formatted[0] = '\0';
|
||||||
|
|
||||||
return std::string (formatted);
|
return std::string (formatted);
|
||||||
|
@ -923,12 +923,12 @@ bool ISO8601p::validate ()
|
||||||
// Allow un-normalized values.
|
// Allow un-normalized values.
|
||||||
void ISO8601p::resolve ()
|
void ISO8601p::resolve ()
|
||||||
{
|
{
|
||||||
_value = (_year * 365 * 86400) +
|
_period = (_year * 365 * 86400) +
|
||||||
(_month * 30 * 86400) +
|
(_month * 30 * 86400) +
|
||||||
(_day * 86400) +
|
(_day * 86400) +
|
||||||
(_hours * 3600) +
|
(_hours * 3600) +
|
||||||
(_minutes * 60) +
|
(_minutes * 60) +
|
||||||
_seconds;
|
_seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -98,7 +98,7 @@ public:
|
||||||
int _hours;
|
int _hours;
|
||||||
int _minutes;
|
int _minutes;
|
||||||
int _seconds;
|
int _seconds;
|
||||||
time_t _value;
|
time_t _period;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO Recurrence
|
// TODO Recurrence
|
||||||
|
|
|
@ -379,7 +379,7 @@ int CmdInfo::execute (std::string& output)
|
||||||
ISO8601p iso;
|
ISO8601p iso;
|
||||||
std::string::size_type cursor = 0;
|
std::string::size_type cursor = 0;
|
||||||
if (iso.parse (value, cursor))
|
if (iso.parse (value, cursor))
|
||||||
value = (std::string) Variant ((time_t) iso._value, Variant::type_duration);
|
value = (std::string) Variant ((time_t) iso, Variant::type_duration);
|
||||||
else
|
else
|
||||||
value = "PT0S";
|
value = "PT0S";
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ void testParse (
|
||||||
int in_hours,
|
int in_hours,
|
||||||
int in_minutes,
|
int in_minutes,
|
||||||
int in_seconds,
|
int in_seconds,
|
||||||
time_t in_value,
|
time_t in_period,
|
||||||
const std::string& output,
|
const std::string& output,
|
||||||
const std::string& vague)
|
const std::string& vague)
|
||||||
{
|
{
|
||||||
|
@ -53,17 +53,17 @@ void testParse (
|
||||||
ISO8601p iso;
|
ISO8601p iso;
|
||||||
std::string::size_type start = 0;
|
std::string::size_type start = 0;
|
||||||
|
|
||||||
t.ok (iso.parse (input, start), label + "true");
|
t.ok (iso.parse (input, start), label + "true");
|
||||||
t.is ((int) start, in_start, label + "[]");
|
t.is ((int) start, in_start, label + "[]");
|
||||||
t.is (iso._year, in_year, label + "_year");
|
t.is (iso._year, in_year, label + "_year");
|
||||||
t.is (iso._month, in_month, label + "_month");
|
t.is (iso._month, in_month, label + "_month");
|
||||||
t.is (iso._day, in_day, label + "_day");
|
t.is (iso._day, in_day, label + "_day");
|
||||||
t.is (iso._hours, in_hours, label + "_hours");
|
t.is (iso._hours, in_hours, label + "_hours");
|
||||||
t.is (iso._minutes, in_minutes, label + "_minutes");
|
t.is (iso._minutes, in_minutes, label + "_minutes");
|
||||||
t.is (iso._seconds, in_seconds, label + "_seconds");
|
t.is (iso._seconds, in_seconds, label + "_seconds");
|
||||||
t.is ((size_t) iso._value, (size_t) in_value, label + "_value");
|
t.is ((size_t) iso._period, (size_t) in_period, label + "_period");
|
||||||
t.is (iso.format (), output, label + " format");
|
t.is (iso.format (), output, label + " format");
|
||||||
t.is (iso.formatVague (), vague, label + " formatVague");
|
t.is (iso.formatVague (), vague, label + " formatVague");
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue