Repository navigation
ResultSet.to_json_list writes a DATE as the epoch milliseconds of midnight in the JVM's time zone, so it disagrees with Result.to_json and decodes to the wrong day #116
Description
Level: bridge and engine (JSONObject.put). For a DATE value, ResultSet.to_json_list() (and iter_json_batches() and export_to_csv(), which use it) writes the epoch milliseconds of midnight in the JVM's default time zone. Result.to_json() writes the epoch milliseconds of midnight UTC for the same row, and so does a DATETIME. On a JVM east of UTC, reading the integer as an epoch in UTC gives the previous day: 2024-01-02 comes out as 2024-01-01 15:00 UTC with -Duser.timezone=Asia/Seoul. The same row, read twice, gives two different integers in one process.
Repro
The script prints to stdout. The JVM's own log lines go to stderr and are discarded by the command below.
uv venv .venv
uv pip install --python .venv/bin/python arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
.venv/bin/python repro-9-to-json-list-date-timezone.py 2>/dev/null"""ResultSet.to_json_list() writes a DATE as the epoch milliseconds of midnight in the JVM's time zone, not in UTC."""
import datetime as dt
import os
import subprocess
import sys
import tempfile
ZONES = ("UTC", "Asia/Seoul", "America/Los_Angeles")
if len(sys.argv) == 1: # parent: run the same check in one JVM per time zone
for zone in ZONES:
subprocess.run([sys.executable, __file__, zone], check=True, stderr=subprocess.DEVNULL)
sys.exit()
import arcadedb_embedded as arcade
from arcadedb_embedded.jvm import start_jvm
zone = sys.argv[1]
start_jvm(heap_size="2g", jvm_args=[f"-Duser.timezone={zone}"])
db = arcade.create_database(os.path.join(tempfile.mkdtemp(prefix="hb9-"), "db"))
db.command("sql", "CREATE DOCUMENT TYPE Event")
with db.transaction():
db.command("sql", "INSERT INTO Event SET day = :day, at = :at", {"day": dt.date(2024, 1, 2), "at": dt.datetime(2024, 1, 2)})
epoch = dt.datetime(1970, 1, 1, tzinfo=dt.timezone.utc)
as_utc = lambda ms: epoch + dt.timedelta(milliseconds=ms)
row = db.query("sql", "SELECT FROM Event").to_json_list()[0]
print(f"-Duser.timezone={zone}")
print(f" to_list() : day={db.query('sql', 'SELECT FROM Event').to_list()[0]['day']}")
print(f" to_json_list() : day={row['day']} = {as_utc(row['day']):%Y-%m-%d %H:%M} UTC at={row['at']} = {as_utc(row['at']):%Y-%m-%d %H:%M} UTC")
print(f" Result.to_json() : {db.query('sql', 'SELECT FROM Event').first().to_json()}")
db.close()Output
Wheel arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl with its bundled JRE (OpenJDK 25.0.4.1), JPype 1.7.1, and Python 3.12.13. The engine build the wheel reports through com.arcadedb.Constants is 26.10.1-SNAPSHOT (build 04bb03ebec07fce19101595d65ca1e3bdf516755), an ancestor of upstream cecb369df9. The repository is at f92ac1381c8335249a6fde644cbf04594f6d6391, and the installed Python sources are identical to bindings/python/src/arcadedb_embedded/ at that commit.
-Duser.timezone=UTC
to_list() : day=2024-01-02
to_json_list() : day=1704153600000 = 2024-01-02 00:00 UTC at=1704153600000 = 2024-01-02 00:00 UTC
Result.to_json() : {"day":1704153600000,"at":1704153600000,"@cat":"d","@type":"Event","@rid":"#1:0"}
-Duser.timezone=Asia/Seoul
to_list() : day=2024-01-02
to_json_list() : day=1704121200000 = 2024-01-01 15:00 UTC at=1704153600000 = 2024-01-02 00:00 UTC
Result.to_json() : {"day":1704153600000,"at":1704153600000,"@cat":"d","@type":"Event","@rid":"#1:0"}
-Duser.timezone=America/Los_Angeles
to_list() : day=2024-01-02
to_json_list() : day=1704182400000 = 2024-01-02 08:00 UTC at=1704153600000 = 2024-01-02 00:00 UTC
Result.to_json() : {"day":1704153600000,"at":1704153600000,"@cat":"d","@type":"Event","@rid":"#1:0"}
In the UTC run the three readers agree. In the other two zones to_json_list is the only one whose DATE value moves, and at (a DATETIME) does not. The docs say DATE and DATETIME "arrive as epoch-millisecond integers" for to_json_list and do not name a zone (api/results.md L120-L124).
Cause
RowBatcher.appendRow puts each value into the engine's JSONObject with obj.put(property, (Object) row.getProperty(property)) (RowBatcher.java L54). JSONObject.put(String, Object) turns a LocalDate into localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli() (JSONObject.java L169-L172, and the same expression in objectToElement, which the values nested in lists and maps go through, at L698; a DATE inside a list and inside a map moves with the zone too). For a record row Result.toJSON() returns the record's own toJSON() (ResultInternal.java L513-L515), which builds the JSON with JsonSerializer.map2json (ImmutableDocument.java L321-L325) and gives midnight UTC in all three zones above, so two serializers of one engine disagree. A LocalDateTime goes through DateUtils.dateTimeToTimestamp, which reads it as UTC, and is not affected.
Expected
A DATE is written as the same integer by every reader and does not depend on the JVM's time zone. The existing convention for DATETIME (a UTC wall clock) means midnight UTC.
Proposed fix
In the bridge, convert a LocalDate before it reaches JSONObject.put. This handles top-level values only (a LocalDate inside a list or map would still use the zone), and it is a sketch that I did not compile or apply:
private static void appendRow(final StringBuilder sb, final Result row) {
final JSONObject obj = new JSONObject();
- for (final String property : row.getPropertyNames())
- obj.put(property, (Object) row.getProperty(property));
+ for (final String property : row.getPropertyNames()) {
+ final Object value = row.getProperty(property);
+ obj.put(property, value instanceof java.time.LocalDate d
+ ? (Object) d.atStartOfDay(java.time.ZoneOffset.UTC).toInstant().toEpochMilli() : value);
+ }
sb.append(obj);The engine-side fix is to make JSONObject.put and objectToElement use UTC for a LocalDate, as JsonSerializer does.
Related issues
ArcadeData#6455 (closed) is DATE written as epoch milliseconds by the JSONL export and read as epoch days by the import, a different mismatch. Nothing found for the JVM time zone.
In this repository's tracker no issue is about this. The searches for time zone and datetime found #58 (closed), about a naive datetime and the host's time zone on writes, and #64 (closed), which corrected the docs to say to_json_list returns DATE and DATETIME as epoch milliseconds and did not examine the zone.
Activity
tae898 commentedon Oct 3, 2026
The engine half (
JSONObject.putandResult.toJSON()of a projection write a DATE in the JVM's zone) is filed upstream as ArcadeData#9037, with a Java repro on Temurin 25 and 21, a tested one-line direction, and no bindings involved. The bridge half is fixed in #131.fix(#112, #116): insert_many stores plain lists, to_json_list writes …
tae898 commentedon Oct 3, 2026
Fixed in #131 (the bridge: a DATE is written as midnight UTC, at the top level and inside a list or map). The engine half is ArcadeData#9037.
benchmarks: the instrument changes for the 26.10.1 re-pin campaign, w…
docs: the fixes that shipped in 26.10.2 are no longer "not released y…
docs: the fixes that shipped in 26.10.2 are no longer "not released y…