From 0f8f99aa239717223d2ab7d1eaec64b6dc295f3f Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Wed, 30 Sep 2026 15:35:06 +0200 Subject: [PATCH] Split a temporal number by value and time from the start it is given TNumber.value_time_split converts its duration whatever its start, takes the default time origin, Monday 3 January 2000, only when no start is given, and reads a given start as a LocalDateTime or as its text. It passes NULL for the value and time bins, which it does not return. Witness. With a start given, the method left its duration unconverted and MEOS refused the null interval, MeosInvalidArgError "Null pointer not allowed"; with no start, it threw a NullPointerException reading the start. Measured. Against the catalog and libmeos of MobilityDB 8a23781e4c with MEOS-API 8dddf59, testValueTimeSplit of TIntTest splits [1@2019-09-01, 5@2019-09-03] at value size 2 and a day: from midnight, and from the default origin, into the two days of the value 1 and the instant of the value 5; from noon into four fragments cut at noon on 1 and 2 September. The build succeeds and the suites run 106 and 1,806 tests, all passing. Why. The start a caller gives is the origin of the time buckets, as in TPoint.space_time_split. --- .../java/types/basic/tnumber/TNumber.java | 33 ++++++++----------- jmeos-core/src/test/java/basic/TIntTest.java | 21 ++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/jmeos-core/src/main/java/types/basic/tnumber/TNumber.java b/jmeos-core/src/main/java/types/basic/tnumber/TNumber.java index 4d17da6ed..ce889ad6a 100644 --- a/jmeos-core/src/main/java/types/basic/tnumber/TNumber.java +++ b/jmeos-core/src/main/java/types/basic/tnumber/TNumber.java @@ -841,33 +841,28 @@ default List value_split(int size, int start){ */ default List value_time_split(Object duration, int value_size, int value_start, Object time_start){ - OffsetDateTime st= null; - Pointer dt= null; - if(time_start != null){ + OffsetDateTime st; + if(time_start == null){ st= GeneratedFunctions.timestamptz_in("2000-01-03", -1); } + else if(time_start instanceof LocalDateTime){ + st= ConversionUtils.datetimeToTimestampTz((LocalDateTime) time_start); + } + else{ + st= GeneratedFunctions.timestamptz_in(time_start.toString(), -1); + } + Pointer dt; + if(duration instanceof Duration){ + dt= ConversionUtils.timedelta_to_interval((Duration) duration); + } else{ - if(time_start instanceof LocalDateTime){ - st= ConversionUtils.datetimeToTimestampTz((LocalDateTime) time_start); - } - else{ - st= GeneratedFunctions.timestamptz_in(time_start.toString(), -1); - } - - if(duration instanceof Duration){ - dt= ConversionUtils.timedelta_to_interval((Duration) duration); - } - else{ - dt= GeneratedFunctions.interval_in(duration.toString(), -1); - } + dt= GeneratedFunctions.interval_in(duration.toString(), -1); } // Create a JNR-FFI runtime instance Runtime runtime = Runtime.getSystemRuntime(); // Allocate memory for an integer (4 bytes) but do not set a value Pointer intPointer = Memory.allocate(runtime, 4); - Pointer valueListPointer = createEmptyPointerArray(runtime, value_size); - Pointer timeListPointer = createEmptyPointerArray(runtime, value_size); - Pointer p= GeneratedFunctions.tint_value_time_split(this.getNumberInner(), value_size, dt, value_start, st, valueListPointer, timeListPointer, intPointer); + Pointer p= GeneratedFunctions.tint_value_time_split(this.getNumberInner(), value_size, dt, value_start, st, null, null, intPointer); List tempList= new ArrayList<>(); int count= intPointer.getInt(0); for(int i=0;i fragments = source.value_time_split(day, 2, 0, start); + assertEquals(3, fragments.size()); + assertEquals("{[1@2019-09-01 00:00:00+00, 1@2019-09-02 00:00:00+00)}", ((TInt) fragments.get(0)).to_string()); + assertEquals("{[1@2019-09-02 00:00:00+00, 1@2019-09-03 00:00:00+00)}", ((TInt) fragments.get(1)).to_string()); + assertEquals("{[5@2019-09-03 00:00:00+00]}", ((TInt) fragments.get(2)).to_string()); + } + java.util.List fragments = source.value_time_split(day, 2, 0, LocalDateTime.of(2019, 9, 1, 12, 0)); + assertEquals(4, fragments.size()); + assertEquals("{[1@2019-09-01 00:00:00+00, 1@2019-09-01 12:00:00+00)}", ((TInt) fragments.get(0)).to_string()); + assertEquals("{[1@2019-09-01 12:00:00+00, 1@2019-09-02 12:00:00+00)}", ((TInt) fragments.get(1)).to_string()); + assertEquals("{[1@2019-09-02 12:00:00+00, 1@2019-09-03 00:00:00+00)}", ((TInt) fragments.get(2)).to_string()); + assertEquals("{[5@2019-09-03 00:00:00+00]}", ((TInt) fragments.get(3)).to_string()); + } }