Dates and Times

class Temporal(value=Unspecified, **kw)

Bases: flatland.schema.scalars.Scalar

Base for datetime-based date and time fields.

type_

Abstract. The native type for element values, will be called with positional arguments per used below.

regex

Abstract. A regular expression to parse datetime values from a string. Must supply named groupings.

used

Abstract. A sequence of regex match group names. These matches will be converted to ints and supplied to the type_ constructor in the order specified.

format

Abstract. A Python string format for serializing the native value. The format will be supplied a dict containing all attributes of the native type.

adapt(value)

Coerces value to a native type.

If value is an instance of type_, returns it unchanged. If a string, attempts to parse it and construct a type as described in the attribute documentation.

serialize(value)

Serializes value to string.

If value is an instance of type, formats it as described in the attribute documentation. Otherwise returns unicode(value).

class DateTime(value=Unspecified, **kw)

Bases: flatland.schema.scalars.Temporal

Element type for Python datetime.datetime.

Serializes to and from YYYY-MM-DD HH:MM:SS format.

type_

alias of datetime

class Date(value=Unspecified, **kw)

Bases: flatland.schema.scalars.Temporal

Element type for Python datetime.date.

Serializes to and from YYYY-MM-DD format.

type_

alias of date

class Time(value=Unspecified, **kw)

Bases: flatland.schema.scalars.Temporal

Element type for Python datetime.time.

Serializes to and from HH:MM:SS format.

type_

alias of time

Topics