UNPKG

@abaplint/runtime

Version:
81 lines 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Time = void 0; const string_1 = require("./string"); const _1 = require("."); const _parse_1 = require("../operators/_parse"); class Time { value; qualifiedName; constructor(input) { this.clear(); this.qualifiedName = input?.qualifiedName; } clone() { const n = new Time({ qualifiedName: this.qualifiedName }); n.value = this.value; return n; } getQualifiedName() { return this.qualifiedName; } set(value) { if (typeof value === "number") { const date = new Date(); date.setTime(value * 1000); this.value = date.getUTCHours().toString().padStart(2, "0") + date.getUTCMinutes().toString().padStart(2, "0") + date.getUTCSeconds().toString().padStart(2, "0"); } else if (typeof value === "string") { this.value = value; if (this.value.length > 6) { this.value = this.value.substring(0, 6); } } else if (value instanceof string_1.String) { this.set(value.get().padEnd(6, "0")); } else if (value instanceof _1.Float) { this.set(Math.round(value.getRaw())); } else { this.set(value.get()); } return this; } clear() { this.value = "000000"; } get() { return this.value; } getNumeric() { const hours = parseInt(this.value.substr(0, 2), 10); const minutes = parseInt(this.value.substr(2, 2), 10); const seconds = parseInt(this.value.substr(4, 2), 10); return hours * 3600 + minutes * 60 + seconds; } getOffset(input) { if (input?.offset) { input.offset = (0, _parse_1.parse)(input.offset); } if (input?.length) { input.length = (0, _parse_1.parse)(input.length); } let ret = this.value; if (input?.offset) { // @ts-ignore ret = ret.substr(input.offset); } if (input?.length !== undefined) { // @ts-ignore ret = ret.substr(0, input.length); } const r = new string_1.String(); r.set(ret); return r; } } exports.Time = Time; //# sourceMappingURL=time.js.map