mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-09 03:04:20 +01:00
This PR implemets the `timediff(A,B)` function, which returns a string that describes the amount of time that must be added to B in order to reach time A. I used sqlite's timediff function for format reference: https://github.com/sqlite/sqlite/blob/master/src/date.c#L1694 Op-codes seems to be in order: ``` limbo> explain SELECT timediff('12:30:45.123', '12:30:44.987'); addr opcode p1 p2 p3 p4 p5 comment ---- ----------------- ---- ---- ---- ------------- -- ------- 0 Init 0 6 0 0 Start at 6 1 String8 0 2 0 12:30:45.123 0 r[2]='12:30:45.123' 2 String8 0 3 0 12:30:44.987 0 r[3]='12:30:44.987' 3 Function 0 2 1 timediff 0 r[1]=func(r[2..3]) 4 ResultRow 1 1 0 0 output=r[1] 5 Halt 0 0 0 0 6 Goto 0 1 0 0 ``` ``` sqlite> explain SELECT timediff('12:30:45.123', '12:30:44.987'); addr opcode p1 p2 p3 p4 p5 comment ---- ------------- ---- ---- ---- ------------- -- ------------- 0 Init 0 8 0 0 Start at 8 1 Once 0 5 0 0 2 String8 0 3 0 12:30:45.123 0 r[3]='12:30:45.123' 3 String8 0 4 0 12:30:44.987 0 r[4]='12:30:44.987' 4 Function 3 3 2 timediff(2) 0 r[2]=func(r[3..4]) 5 Copy 2 1 0 0 r[1]=r[2] 6 ResultRow 1 1 0 0 output=r[1] 7 Halt 0 0 0 0 8 Goto 0 1 0 0 ``` My first PR, I just followed the [contributing guides](https://github.co m/tursodatabase/limbo/blob/main/CONTRIBUTING.md) and started. Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com> Closes #1302