Skip to content

Commit 0c747a4

Browse files
committed
ColumnUDADuration: add "iso" style as synonym for "default"
For compatibility reasons I couldn't simply rename "default", so I just added a new "iso" as a synonym. While I was in there I added some example output. There are currently no tests for UDA durations so I added one.
1 parent eddcc07 commit 0c747a4

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

src/columns/ColUDA.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ ColumnUDADuration::ColumnUDADuration() {
243243
_style = "default";
244244
_label = "";
245245
_uda = true;
246-
_styles = {_style, "indicator"};
246+
_styles = {_style, "indicator", "iso"};
247+
_examples = {"P30D", "U", "P30D"};
247248
}
248249

249250
////////////////////////////////////////////////////////////////////////////////
@@ -265,7 +266,7 @@ bool ColumnUDADuration::validate(const std::string& value) const {
265266
void ColumnUDADuration::measure(Task& task, unsigned int& minimum, unsigned int& maximum) {
266267
minimum = maximum = 0;
267268
if (task.has(_name)) {
268-
if (_style == "default") {
269+
if (_style == "default" || _style == "iso") {
269270
auto value = task.get(_name);
270271
if (value != "") minimum = maximum = Duration(value).formatISO().length();
271272
} else if (_style == "indicator") {
@@ -284,7 +285,7 @@ void ColumnUDADuration::measure(Task& task, unsigned int& minimum, unsigned int&
284285
void ColumnUDADuration::render(std::vector<std::string>& lines, Task& task, int width,
285286
Color& color) {
286287
if (task.has(_name)) {
287-
if (_style == "default") {
288+
if (_style == "default" || _style == "iso") {
288289
auto value = task.get(_name);
289290
renderStringRight(lines, width, color, Duration(value).formatISO());
290291
} else if (_style == "indicator") {

test/columns.test.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,46 @@ def test_uda_uuid_short(self):
543543
self.assertEqual(self.expected_str[:8], out.strip())
544544

545545

546+
class TestUDADurationFormats(TestCase):
547+
@classmethod
548+
def setUpClass(cls):
549+
"""Executed once before any test in the class"""
550+
cls.t = Task()
551+
cls.t.config("verbose", "nothing")
552+
cls.t.config("uda.uda_duration.label", "uda_duration")
553+
cls.t.config("uda.uda_duration.type", "duration")
554+
cls.t.config("report.xxx.columns", "id,uda_duration")
555+
556+
# Test only nonnegative durations, since negative ones are not handled
557+
# well. See https://github.com/GothenburgBitFactory/libshared/pull/110
558+
cls.t("add one uda_duration:0min")
559+
cls.t("add two uda_duration:1min")
560+
cls.t("add thr uda_duration:60d")
561+
cls.t("add four uda_duration:'30d + 10h + 3min + 2s'")
562+
563+
def test_uda_duration_format_indicator(self):
564+
"""Verify uda_duration.indicator formatting"""
565+
code, out, err = self.t(f"xxx rc.report.xxx.columns:id,uda_duration.indicator")
566+
# The indicator for UDAs is always U.
567+
self.assertRegex(out, r"1\s+U")
568+
self.assertRegex(out, r"2\s+U")
569+
self.assertRegex(out, r"3\s+U")
570+
self.assertRegex(out, r"4\s+U")
571+
572+
def test_uda_duration_format_iso(self):
573+
"""Verify uda_duration.iso formatting"""
574+
for style in ["iso", "default"]:
575+
code, out, err = self.t(
576+
f"xxx rc.report.xxx.columns:id,uda_duration.{style}"
577+
)
578+
# The ISO format shouldn't change at all, so do exact matches rather than
579+
# more flexible regexes.
580+
self.assertRegex(out, r"1\s+PT0S")
581+
self.assertRegex(out, r"2\s+PT1M")
582+
self.assertRegex(out, r"3\s+P60D")
583+
self.assertRegex(out, r"4\s+P30DT10H3M2S")
584+
585+
546586
class TestFeature1061(TestCase):
547587
def setUp(self):
548588
"""Executed before each test in the class"""

0 commit comments

Comments
 (0)