Skip to content

Commit a37eddc

Browse files
authored
feat: add support for TimeDelta type in Python and Rust (#497)
* feat: add support for TimeDelta type in Python and Rust Continuation on #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 482750b commit a37eddc

File tree

12 files changed

+752
-10
lines changed

12 files changed

+752
-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
@@ -168,6 +168,8 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
168168
kind = 'Time'
169169
elif t is datetime.datetime:
170170
kind = 'OffsetDateTime'
171+
elif t is datetime.timedelta:
172+
kind = 'TimeDelta'
171173
else:
172174
raise ValueError(f"type unsupported yet: {t}")
173175

0 commit comments

Comments
 (0)