View Source Lightning.UnixDateTime (Lightning v2.10.4)

A custom DateTime type for Ecto that uses millisecond Unix timestamps.

NodeJS uses millisecond Unix timestamps, and Ecto has a choice of either second or microsecond precision. This module allows millisecond precision integers to be used as DateTime values without losing precision.

Microsecond timestamps can also be parsed, but currently they are expected to be provided as strings. This is because Javascript can't represent microsecond timestamps as an integer and BigInt can't be represented as a JSON value.

All functions fallback on the default Ecto types conversion functions.

Summary

Functions

Cast a Unix timestamp to a DateTime.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.

Functions

Cast a Unix timestamp to a DateTime.

Accepts integers and strings, and will try to parse the string as an integer. If the integer is 13 digits long, it will be parsed as a millisecond timestamp, and as a microsecond timestamp if it is 16 digits long.

Callback implementation for Ecto.Type.dump/1.

Callback implementation for Ecto.Type.embed_as/1.

Callback implementation for Ecto.Type.equal?/2.

Callback implementation for Ecto.Type.load/1.

Callback implementation for Ecto.Type.type/0.