From bb53ae17ae392a7d728b4824e01092fb4de7a3d1 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 26 Sep 2015 12:11:49 -0400 Subject: [PATCH] ISO8601p: Renamed ::_value to ::_period --- src/DOM.cpp | 2 +- src/ISO8601.cpp | 52 ++++++++++++++++++++-------------------- src/ISO8601.h | 2 +- src/commands/CmdInfo.cpp | 2 +- test/iso8601p.t.cpp | 24 +++++++++---------- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/DOM.cpp b/src/DOM.cpp index 929f40823..a7f760a14 100644 --- a/src/DOM.cpp +++ b/src/DOM.cpp @@ -300,7 +300,7 @@ bool DOM::get (const std::string& name, const Task& task, Variant& value) ISO8601p iso; std::string::size_type cursor = 0; if (iso.parse (period, cursor)) - value = Variant ((time_t) iso._value, Variant::type_duration); + value = Variant ((time_t) iso, Variant::type_duration); else value = Variant ((time_t) ISO8601p (ref.get (canonical)), Variant::type_duration); } diff --git a/src/ISO8601.cpp b/src/ISO8601.cpp index 9ce967adb..00212db5d 100644 --- a/src/ISO8601.cpp +++ b/src/ISO8601.cpp @@ -592,7 +592,7 @@ ISO8601p::ISO8601p () ISO8601p::ISO8601p (time_t input) { 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); if (value == 0 || value > 60) { - _value = value; + _period = value; return; } } @@ -630,7 +630,7 @@ ISO8601p& ISO8601p::operator= (const ISO8601p& other) _hours = other._hours; _minutes = other._minutes; _seconds = other._seconds; - _value = other._value; + _period = other._period; } return *this; @@ -639,27 +639,27 @@ ISO8601p& 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) { - return _value > other._value; + return _period > other._period; } //////////////////////////////////////////////////////////////////////////////// ISO8601p::operator std::string () const { std::stringstream s; - s << _value; + s << _period; return s.str (); } //////////////////////////////////////////////////////////////////////////////// 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 && durations[i].standalone == true) { - _value = static_cast (durations[i].seconds); + _period = static_cast (durations[i].seconds); return true; } } @@ -781,7 +781,7 @@ bool ISO8601p::parse (const std::string& input, std::string::size_type& start) if (durations[i].unit == unit) { seconds = durations[i].seconds; - _value = static_cast (quantity * static_cast (seconds)); + _period = static_cast (quantity * static_cast (seconds)); return true; } } @@ -801,15 +801,15 @@ void ISO8601p::clear () _hours = 0; _minutes = 0; _seconds = 0; - _value = 0; + _period = 0; } //////////////////////////////////////////////////////////////////////////////// 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 minutes = t % 60; t /= 60; int hours = t % 24; t /= 24; @@ -839,15 +839,15 @@ const std::string ISO8601p::format () const const std::string ISO8601p::formatVague () const { 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)); - else if (_value >= 86400 * 84) sprintf (formatted, "%1dmo", (int) (days / 30)); - else if (_value >= 86400 * 13) sprintf (formatted, "%dw", (int) (float) (days / 7.0)); - else if (_value >= 86400) sprintf (formatted, "%dd", (int) days); - else if (_value >= 3600) sprintf (formatted, "%dh", (int) (_value / 3600)); - else if (_value >= 60) sprintf (formatted, "%dmin", (int) (_value / 60)); - else if (_value >= 1) sprintf (formatted, "%ds", (int) _value); + if (_period >= 86400 * 365) sprintf (formatted, "%.1fy", (days / 365.0)); + else if (_period >= 86400 * 84) sprintf (formatted, "%1dmo", (int) (days / 30)); + else if (_period >= 86400 * 13) sprintf (formatted, "%dw", (int) (float) (days / 7.0)); + else if (_period >= 86400) sprintf (formatted, "%dd", (int) days); + else if (_period >= 3600) sprintf (formatted, "%dh", (int) (_period / 3600)); + else if (_period >= 60) sprintf (formatted, "%dmin", (int) (_period / 60)); + else if (_period >= 1) sprintf (formatted, "%ds", (int) _period); else formatted[0] = '\0'; return std::string (formatted); @@ -923,12 +923,12 @@ bool ISO8601p::validate () // Allow un-normalized values. void ISO8601p::resolve () { - _value = (_year * 365 * 86400) + - (_month * 30 * 86400) + - (_day * 86400) + - (_hours * 3600) + - (_minutes * 60) + - _seconds; + _period = (_year * 365 * 86400) + + (_month * 30 * 86400) + + (_day * 86400) + + (_hours * 3600) + + (_minutes * 60) + + _seconds; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/ISO8601.h b/src/ISO8601.h index 1d3c54f1e..9b6af4eb0 100644 --- a/src/ISO8601.h +++ b/src/ISO8601.h @@ -98,7 +98,7 @@ public: int _hours; int _minutes; int _seconds; - time_t _value; + time_t _period; }; // TODO Recurrence diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index 3066ac563..e6521b438 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -379,7 +379,7 @@ int CmdInfo::execute (std::string& output) ISO8601p iso; std::string::size_type cursor = 0; 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 value = "PT0S"; } diff --git a/test/iso8601p.t.cpp b/test/iso8601p.t.cpp index b8d0186da..8c0d646bf 100644 --- a/test/iso8601p.t.cpp +++ b/test/iso8601p.t.cpp @@ -44,7 +44,7 @@ void testParse ( int in_hours, int in_minutes, int in_seconds, - time_t in_value, + time_t in_period, const std::string& output, const std::string& vague) { @@ -53,17 +53,17 @@ void testParse ( ISO8601p iso; std::string::size_type start = 0; - t.ok (iso.parse (input, start), label + "true"); - t.is ((int) start, in_start, label + "[]"); - t.is (iso._year, in_year, label + "_year"); - t.is (iso._month, in_month, label + "_month"); - t.is (iso._day, in_day, label + "_day"); - t.is (iso._hours, in_hours, label + "_hours"); - t.is (iso._minutes, in_minutes, label + "_minutes"); - t.is (iso._seconds, in_seconds, label + "_seconds"); - t.is ((size_t) iso._value, (size_t) in_value, label + "_value"); - t.is (iso.format (), output, label + " format"); - t.is (iso.formatVague (), vague, label + " formatVague"); + t.ok (iso.parse (input, start), label + "true"); + t.is ((int) start, in_start, label + "[]"); + t.is (iso._year, in_year, label + "_year"); + t.is (iso._month, in_month, label + "_month"); + t.is (iso._day, in_day, label + "_day"); + t.is (iso._hours, in_hours, label + "_hours"); + t.is (iso._minutes, in_minutes, label + "_minutes"); + t.is (iso._seconds, in_seconds, label + "_seconds"); + t.is ((size_t) iso._period, (size_t) in_period, label + "_period"); + t.is (iso.format (), output, label + " format"); + t.is (iso.formatVague (), vague, label + " formatVague"); } ////////////////////////////////////////////////////////////////////////////////