From c12d4cebfbe7bfa6ef162df4db86165470e48880 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 29 Mar 2022 11:00:09 -0600 Subject: [PATCH] Et2DateDuration: Enforce the order of display to be greatest to least For example hours:days is not allowed anymore, auto-corrected to days:hours --- api/js/etemplate/Et2Date/Et2DateDuration.ts | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/api/js/etemplate/Et2Date/Et2DateDuration.ts b/api/js/etemplate/Et2Date/Et2DateDuration.ts index afa54fd435..ece4c05602 100644 --- a/api/js/etemplate/Et2Date/Et2DateDuration.ts +++ b/api/js/etemplate/Et2Date/Et2DateDuration.ts @@ -338,6 +338,30 @@ export class Et2DateDuration extends Et2InputWidget(FormControlMixin(LitElement) this.requestUpdate(); } + /** + * Set the format for displaying the duration + * + * @param {string} value + */ + set display_format(value : string) + { + this.__display_format = ""; + // Display format must be in decreasing size order (dhms) or the calculations + // don't work out nicely + for(let f of Object.keys(Et2DateDuration.time_formats)) + { + if(value.indexOf(f) !== -1) + { + this.__display_format += f; + } + } + } + + get display_format() + { + return this.__display_format; + } + /** * @return {TemplateResult} * @protected