@abaplint/runtime
Version:
Transpiler - Runtime
89 lines • 2.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convert = convert;
const temporal_polyfill_1 = require("temporal-polyfill");
function convert(source, target) {
/*
console.dir(source);
console.dir(target);
*/
let date = "";
if (source.date) {
if (typeof source.date === "string") {
date = source.date;
}
else {
date = source.date.get();
}
if (date.trimEnd() === "") {
date = "00000000";
}
}
let time = "";
if (source.time) {
if (typeof source.time === "string") {
time = source.time;
}
else {
time = source.time.get();
}
if (time.trimEnd() === "") {
time = "000000";
}
}
let stamp = "";
if (source.stamp) {
if (typeof source.stamp === "string") {
stamp = source.stamp;
}
else {
stamp = source.stamp.get() + "";
}
}
let zone = "";
if (source.zone) {
if (typeof source.zone === "string") {
zone = source.zone;
}
else {
zone = source.zone.get() + "";
}
zone = zone.trimEnd();
}
if (zone.trim() === "") {
zone = "UTC";
}
////////////////////////
let zoned = undefined;
if (date !== "" && time !== "") {
if (date === "00000000" && time === "000000") {
target.stamp?.clear();
return;
}
const pt = temporal_polyfill_1.Temporal.PlainTime.from(time.substring(0, 2) + ":" + time.substring(2, 4) + ":" + time.substring(4, 6));
zoned = temporal_polyfill_1.Temporal.PlainDate.from(date).toZonedDateTime({ timeZone: zone, plainTime: pt });
zoned = zoned.withTimeZone("UTC");
}
else {
if (stamp === "0") {
target.date?.clear();
target.time?.clear();
return;
}
const pt = temporal_polyfill_1.Temporal.PlainTime.from(stamp.substring(8, 10) + ":" + stamp.substring(10, 12) + ":" + stamp.substring(12, 14));
zoned = temporal_polyfill_1.Temporal.PlainDate.from(stamp.substring(0, 8)).toZonedDateTime({ timeZone: "UTC", plainTime: pt });
zoned = zoned.withTimeZone(zone);
}
const d = zoned.toPlainDate().toString().replace(/-/g, "");
const t = zoned.toPlainTime().toString().replace(/:/g, "");
if (target.stamp) {
target.stamp.set(d + t);
}
if (target.date) {
target.date.set(d);
}
if (target.time) {
target.time.set(t);
}
}
//# sourceMappingURL=convert.js.map