summaryrefslogtreecommitdiffstats
path: root/decor/elapsed.go
diff options
context:
space:
mode:
Diffstat (limited to 'decor/elapsed.go')
-rw-r--r--decor/elapsed.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/decor/elapsed.go b/decor/elapsed.go
new file mode 100644
index 0000000..6cee7d1
--- /dev/null
+++ b/decor/elapsed.go
@@ -0,0 +1,33 @@
+package decor
+
+import (
+ "time"
+)
+
+// Elapsed decorator. It's wrapper of NewElapsed.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `wcc` optional WC config
+func Elapsed(style TimeStyle, wcc ...WC) Decorator {
+ return NewElapsed(style, time.Now(), wcc...)
+}
+
+// NewElapsed returns elapsed time decorator.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `startTime` start time
+//
+// `wcc` optional WC config
+func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator {
+ var msg string
+ producer := chooseTimeProducer(style)
+ fn := func(s Statistics) string {
+ if !s.Completed {
+ msg = producer(time.Since(startTime))
+ }
+ return msg
+ }
+ return Any(fn, wcc...)
+}