Skip to content

Commit bd83144

Browse files
committed
ColumnUDADuration: add "age" style which shows a more human-readable format
I just copied the logic for this from ColumnTypeDate. I also grepped around for other instances of `formatVague`. I don't know what the argument means but in this project it's set to `true` 100% of the time so I kept it that way. I am using the name "age" as suggested in #3738
1 parent 0c747a4 commit bd83144

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/columns/ColUDA.cpp

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

250250
////////////////////////////////////////////////////////////////////////////////
@@ -269,6 +269,9 @@ void ColumnUDADuration::measure(Task& task, unsigned int& minimum, unsigned int&
269269
if (_style == "default" || _style == "iso") {
270270
auto value = task.get(_name);
271271
if (value != "") minimum = maximum = Duration(value).formatISO().length();
272+
} else if (_style == "age") {
273+
auto value = task.get(_name);
274+
if (value != "") minimum = maximum = Duration(value).formatVague(true).length();
272275
} else if (_style == "indicator") {
273276
if (task.has(_name)) {
274277
auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
@@ -288,6 +291,9 @@ void ColumnUDADuration::render(std::vector<std::string>& lines, Task& task, int
288291
if (_style == "default" || _style == "iso") {
289292
auto value = task.get(_name);
290293
renderStringRight(lines, width, color, Duration(value).formatISO());
294+
} else if (_style == "age") {
295+
auto value = task.get(_name);
296+
renderStringRight(lines, width, color, Duration(value).formatVague(true));
291297
} else if (_style == "indicator") {
292298
auto indicator = Context::getContext().config.get("uda." + _name + ".indicator");
293299
if (indicator == "") indicator = "U";

test/columns.test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@ def test_uda_duration_format_iso(self):
582582
self.assertRegex(out, r"3\s+P60D")
583583
self.assertRegex(out, r"4\s+P30DT10H3M2S")
584584

585+
def test_uda_duration_format_age(self):
586+
"""Verify uda_duration.age formatting"""
587+
code, out, err = self.t("xxx rc.report.xxx.columns:id,uda_duration.age")
588+
self.assertRegex(out, r"1\s+")
589+
self.assertRegex(out, r"2\s+[0-9]+[wmin]+")
590+
self.assertRegex(out, r"3\s+[0-9]+[wmin]+")
591+
self.assertRegex(out, r"4\s+[0-9]+[wmin]+")
592+
585593

586594
class TestFeature1061(TestCase):
587595
def setUp(self):

0 commit comments

Comments
 (0)