Pendulum
Native Pendulum DateTime object implementation. This is a copy of the Pendulum DateTime object, but with a Pydantic CoreSchema implementation. This allows Pydantic to validate the DateTime object.
DateTime ¶
Bases: DateTime
A pendulum.DateTime
object. At runtime, this type decomposes into pendulum.DateTime automatically.
This type exists because Pydantic throws a fit on unknown types.
from pydantic import BaseModel
from pydantic_extra_types.pendulum_dt import DateTime
class test_model(BaseModel):
dt: DateTime
print(test_model(dt='2021-01-01T00:00:00+00:00'))
# > test_model(dt=DateTime(2021, 1, 1, 0, 0, 0, tzinfo=FixedTimezone(0, name="+00:00")))
Date ¶
Bases: Date
A pendulum.Date
object. At runtime, this type decomposes into pendulum.Date automatically.
This type exists because Pydantic throws a fit on unknown types.
from pydantic import BaseModel
from pydantic_extra_types.pendulum_dt import Date
class test_model(BaseModel):
dt: Date
print(test_model(dt='2021-01-01'))
# > test_model(dt=Date(2021, 1, 1))
Duration ¶
Bases: Duration
A pendulum.Duration
object. At runtime, this type decomposes into pendulum.Duration automatically.
This type exists because Pydantic throws a fit on unknown types.
from pydantic import BaseModel
from pydantic_extra_types.pendulum_dt import Duration
class test_model(BaseModel):
delta_t: Duration
print(test_model(delta_t='P1DT25H'))
# > test_model(delta_t=Duration(days=2, hours=1))
to_iso8601_string ¶
to_iso8601_string() -> str
Convert a Duration object to an ISO 8601 string.
In addition to the standard ISO 8601 format, this method also supports the representation of fractions of a second and negative durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
duration |
Duration
|
The Duration object. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The ISO 8601 string representation of the duration. |
Source code in pydantic_extra_types/pendulum_dt.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
|
本文总阅读量次