Skip to content

Commit e400c6a

Browse files
committed
feat: add support for TimeDelta type in Python and Rust
Continuation on #368
1 parent 05f9b60 commit e400c6a

File tree

12 files changed

+538
-11
lines changed

12 files changed

+538
-11
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 | `cocoindex.typing.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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, key: str, value: Any):
2929
Json = Annotated[Any, TypeKind('Json')]
3030
LocalDateTime = Annotated[datetime.datetime, TypeKind('LocalDateTime')]
3131
OffsetDateTime = Annotated[datetime.datetime, TypeKind('OffsetDateTime')]
32+
TimeDelta = Annotated[datetime.timedelta, TypeKind('TimeDelta')]
3233

3334
if TYPE_CHECKING:
3435
T_co = TypeVar('T_co', covariant=True)
@@ -168,6 +169,8 @@ def analyze_type_info(t) -> AnalyzedTypeInfo:
168169
kind = 'Time'
169170
elif t is datetime.datetime:
170171
kind = 'OffsetDateTime'
172+
elif t is datetime.timedelta:
173+
kind = 'TimeDelta'
171174
else:
172175
raise ValueError(f"type unsupported yet: {t}")
173176

0 commit comments

Comments
 (0)