Skip to content

Commit 3e6a489

Browse files
lemoragechardoncs
authored andcommitted
feat: add support for TimeDelta type in Python and Rust (cocoindex-io#497)
* feat: add support for TimeDelta type in Python and Rust Continuation on cocoindex-io#368 * refactor: update duration parser to align with ISO 8601 standard - Replaced naive parsing with structured component-based approach - Enhanced both iso8601 and human-readable parsers with proper validation and unit order checks - Added more tests, achieving 97.52% test coverage * feat: make duration parser lenient by allowing duplicate and out of order units * refactor: inline code with some cleanups
1 parent d2aef9b commit 3e6a489

File tree

12 files changed

+753
-10
lines changed

12 files changed

+753
-10
lines changed

docs/docs/core/data_types.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ This is the list of all basic types supported by CocoIndex:
3535
| Time | | `datetime.time` | `datetime.time` |
3636
| LocalDatetime | Date and time without timezone | `cocoindex.LocalDateTime` | `datetime.datetime` |
3737
| OffsetDatetime | Date and time with a timezone offset | `cocoindex.OffsetDateTime` | `datetime.datetime` |
38+
| TimeDelta | A duration of time | `datetime.timedelta` | `datetime.timedelta` |
3839
| Vector[*T*, *Dim*?] | *T* must be basic type. *Dim* is a positive integer and optional. |`cocoindex.Vector[T]` or `cocoindex.Vector[T, Dim]` | `list[T]` |
3940
| Json | | `cocoindex.Json` | Any data convertible to JSON by `json` package |
4041

python/cocoindex/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
177177
kind = 'Time'
178178
elif t is datetime.datetime:
179179
kind = 'OffsetDateTime'
180+
elif t is datetime.timedelta:
181+
kind = 'TimeDelta'
180182
else:
181183
raise ValueError(f"type unsupported yet: {t}")
182184

0 commit comments

Comments
 (0)