This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch fix-time-seq-since-function-clause
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 3d78ed688884cdba20211f8f89218ac29462de50
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Mon Feb 23 18:08:13 2026 -0500

    Fix time_seq since function clause
    
    If user specifies a correctly formatted timestamp but it's before 0 unix 
time,
    return entries since 0 unix time (1970-01-01T00:00:00Z) instead of a 
function
    clause error.
---
 src/chttpd/test/eunit/chttpd_changes_test.erl | 18 ++++++++++++++++++
 src/fabric/src/fabric.erl                     |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/src/chttpd/test/eunit/chttpd_changes_test.erl 
b/src/chttpd/test/eunit/chttpd_changes_test.erl
index a89842ae3..dff2915dc 100644
--- a/src/chttpd/test/eunit/chttpd_changes_test.erl
+++ b/src/chttpd/test/eunit/chttpd_changes_test.erl
@@ -534,6 +534,24 @@ t_time_since({_, DbUrl}) ->
         "Invalid time"
     ),
 
+    Params4 = "?since=1000-01-01T01:01:01Z",
+    Res4 = {_, _, _} = changes(DbUrl, Params4),
+    ?assertEqual(
+        Res4,
+        changes(DbUrl, "?since=0"),
+        "Expected the same result as from '?since=0'"
+    ),
+
+    ?assertEqual(400, InvalCode),
+    ?assertMatch(
+        #{
+            <<"error">> := <<"bad_request">>,
+            <<"reason">> := <<"invalid_time_format">>
+        },
+        json(InvalRes),
+        "Invalid time"
+    ),
+
     {TSeqCode, TSeqRes} = reqraw(get, DbUrl ++ "/_time_seq"),
     ?assertEqual(200, TSeqCode),
     Year = integer_to_binary(element(1, date())),
diff --git a/src/fabric/src/fabric.erl b/src/fabric/src/fabric.erl
index 3a6ce7ebd..1b8434b03 100644
--- a/src/fabric/src/fabric.erl
+++ b/src/fabric/src/fabric.erl
@@ -678,6 +678,8 @@ time_seq_since(DbName, Time) when is_list(Time) ->
         _:_ ->
             {error, invalid_time_format}
     end;
+time_seq_since(DbName, Time) when is_integer(Time), Time < 0 ->
+    time_seq_since(DbName, 0);
 time_seq_since(DbName, Time) when is_integer(Time), Time >= 0 ->
     fabric_time_seq:since(dbname(DbName), Time).
 

Reply via email to