type_bridge.attribute.date¶
date
¶
Date attribute type for TypeDB.
Date
¶
Bases: Attribute
Date attribute type that accepts date values (date only, no time).
This maps to TypeDB's 'date' type, which is an ISO 8601 compliant date without time information.
Range: January 1, 262144 BCE to December 31, 262142 CE
Example
from datetime import date
class PublishDate(Date): pass
class BirthDate(Date): pass
Usage with date values¶
published = PublishDate(date(2024, 3, 30)) birthday = BirthDate(date(1990, 5, 15))
Initialize Date attribute with a date value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
date | str
|
The date value to store. Can be: - datetime.date instance - str in ISO 8601 format (YYYY-MM-DD) |
required |
Example
from datetime import date
From date instance¶
publish_date = PublishDate(date(2024, 3, 30))
From ISO string¶
publish_date = PublishDate("2024-03-30")
Source code in type_bridge/attribute/date.py
__add__
¶
Add a Duration to this Date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
A Duration to add to this date |
required |
Returns:
| Type | Description |
|---|---|
Date
|
New Date with the duration added |
Example
from type_bridge import Duration d = Date(date(2024, 1, 31)) duration = Duration("P1M") result = d + duration # Date(2024-02-29)
Source code in type_bridge/attribute/date.py
__radd__
¶
__sub__
¶
Subtract a Duration from this Date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
A Duration to subtract from this date |
required |
Returns:
| Type | Description |
|---|---|
Date
|
New Date with the duration subtracted |
Example
from type_bridge import Duration d = Date(date(2024, 3, 31)) duration = Duration("P1M") result = d - duration # Date(2024-02-29)