diff options
author | 2018-03-27 17:33:22 +0800 | |
---|---|---|
committer | 2018-03-27 17:33:22 +0800 | |
commit | 8261a4ea8091c27b61ac581a852e2e18283b3cdd (patch) | |
tree | a2ca109f7600e9e0cbe73eb9139ffe6284be1159 /sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts | |
parent | 573f32b362f4639928485d66feb1c0721109716b (diff) |
Include paletx components
Include paletx components to WF Designer UI.
Issue-ID: SDC-1130,SDC-1131
Change-Id: Iad06b2dde8fc98d03a0e3633e829b686d75cafd0
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
Diffstat (limited to 'sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts')
-rw-r--r-- | sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts b/sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts new file mode 100644 index 00000000..ab31a498 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/paletx/plx-datepicker/time.ts @@ -0,0 +1,51 @@ +import { isNumber, toInteger } from './util/util'; + +export class NgbTime { + public hour: number; + public minute: number; + public second: number; + + constructor(hour?: number, minute?: number, second?: number) { + this.hour = toInteger(hour); + this.minute = toInteger(minute); + this.second = toInteger(second); + } + + public changeHour(step = 1) { this.updateHour((isNaN(this.hour) ? 0 : this.hour) + step); } + + public updateHour(hour: number) { + if (isNumber(hour)) { + this.hour = (hour < 0 ? 24 + hour : hour) % 24; + } else { + this.hour = NaN; + } + } + + public changeMinute(step = 1) { this.updateMinute((isNaN(this.minute) ? 0 : this.minute) + step); } + + public updateMinute(minute: number) { + if (isNumber(minute)) { + this.minute = minute % 60 < 0 ? 60 + minute % 60 : minute % 60; + this.changeHour(Math.floor(minute / 60)); + } else { + this.minute = NaN; + } + } + + public changeSecond(step = 1) { this.updateSecond((isNaN(this.second) ? 0 : this.second) + step); } + + public updateSecond(second: number) { + if (isNumber(second)) { + this.second = second < 0 ? 60 + second % 60 : second % 60; + this.changeMinute(Math.floor(second / 60)); + } else { + this.second = NaN; + } + } + + public isValid(checkSecs = true) { + return isNumber(this.hour) && isNumber(this.minute) && (checkSecs ? isNumber(this.second) : true); + } + + public toString() { return `${this.hour || 0}:${this.minute || 0}:${this.second || 0}`; } +} |