@abaplint/runtime
Version:
Transpiler - Runtime
80 lines • 2.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Date = void 0;
const string_1 = require("./string");
const _date_helper_1 = require("./_date_helper");
const float_1 = require("./float");
const _parse_1 = require("../operators/_parse");
class Date {
value;
qualifiedName;
constructor(input) {
this.clear();
this.qualifiedName = input?.qualifiedName;
}
clone() {
const n = new Date({ qualifiedName: this.qualifiedName });
n.value = this.value;
return n;
}
getQualifiedName() {
return this.qualifiedName;
}
set(value) {
if (typeof value === "number") {
if (value <= 0 || value > 3652060) {
this.value = "00000000";
}
else {
this.value = (0, _date_helper_1.getDateFromNumber)(value);
}
}
else if (value instanceof float_1.Float) {
this.set(Math.round(value.getRaw()));
}
else if (typeof value === "string") {
this.value = value;
}
else {
this.set(value.get());
}
if (this.value.length > 8) {
this.value = this.value.substr(0, 8);
}
else if (this.value.length < 8) {
this.value = this.value.padEnd(8, " ");
}
return this;
}
clear() {
this.value = "00000000";
}
get() {
return this.value;
}
getNumeric() {
return (0, _date_helper_1.getNumberFromDate)(this.value);
}
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.Date = Date;
//# sourceMappingURL=date.js.map