aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/frontend/html/util/compactbinary.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenserver/frontend/html/util/compactbinary.js')
-rw-r--r--src/zenserver/frontend/html/util/compactbinary.js41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/zenserver/frontend/html/util/compactbinary.js b/src/zenserver/frontend/html/util/compactbinary.js
index 415fa4be8..270c96a2f 100644
--- a/src/zenserver/frontend/html/util/compactbinary.js
+++ b/src/zenserver/frontend/html/util/compactbinary.js
@@ -369,6 +369,14 @@ CbObjectView.prototype[Symbol.iterator] = function()
////////////////////////////////////////////////////////////////////////////////
CbObjectView.prototype.to_js_object = function()
{
+ const TicksPerMs = 10000;
+ const UnixEpochTicks = 621355968000000000n; // .NET ticks at 1970-01-01
+
+ const readTicks = function(data) {
+ const dv = new DataView(data.buffer, data.byteOffset, 8);
+ return dv.getBigInt64(0, false);
+ };
+
const impl = function(node)
{
if (node.is_object())
@@ -388,9 +396,40 @@ CbObjectView.prototype.to_js_object = function()
}
if (node.is_string()) return node.as_value();
- if (node.is_integer()) return node.as_value();
if (node.is_float()) return node.as_value();
+ if (node.is_integer())
+ {
+ const v = node.as_value();
+ if (v >= -9007199254740991n && v <= 9007199254740991n)
+ return Number(v);
+ return v;
+ }
+
+ const type = CbFieldTypeOps.get_type(node.get_type());
+
+ if (type == CbFieldType.DateTime)
+ {
+ const ticks = readTicks(node.as_value());
+ const unixMs = Number((ticks - UnixEpochTicks) / BigInt(TicksPerMs));
+ return new Date(unixMs).toISOString();
+ }
+
+ if (type == CbFieldType.TimeSpan)
+ {
+ const ticks = readTicks(node.as_value());
+ const absTicks = ticks < 0n ? -ticks : ticks;
+ const totalMs = Number(absTicks / BigInt(TicksPerMs));
+ const ms = totalMs % 1000;
+ const totalSec = Math.floor(totalMs / 1000);
+ const sec = totalSec % 60;
+ const totalMin = Math.floor(totalSec / 60);
+ const min = totalMin % 60;
+ const hours = Math.floor(totalMin / 60);
+ const sign = ticks < 0n ? "-" : "";
+ return `${sign}${hours}:${String(min).padStart(2, "0")}:${String(sec).padStart(2, "0")}.${String(ms).padStart(3, "0")}0000`;
+ }
+
var ret = node.as_value();
if (ret instanceof Uint8Array)
{