Skip to content

Instantly share code, notes, and snippets.

@talentdeficit
talentdeficit / :posterize_xt_date.ex
Last active January 8, 2017 22:03
date with infinity
defmodule :posterize_xt_date do
@moduledoc false
@behaviour Postgrex.Extension
import Postgrex.BinaryUtils, warn: false
use Postgrex.BinaryExtension, [send: "date_send"]
@pg_epoch :calendar.date_to_gregorian_days({ 2000, 1, 1 })
@max_year 5874897
@min_year -4713
@talentdeficit
talentdeficit / posterize_xt_timestamp.ex
Created January 8, 2017 21:59
timestamps with infinity
defmodule :posterize_xt_timestamp do
@moduledoc false
@behaviour Postgrex.Extension
import Postgrex.BinaryUtils, warn: false
use Postgrex.BinaryExtension, [send: "timestamp_send"]
@unix_epoch :calendar.datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}})
@gs_epoch :calendar.datetime_to_gregorian_seconds({{2000, 1, 1}, {0, 0, 0}})
@adjustment :erlang.convert_time_unit(@gs_epoch - @unix_epoch, :seconds, :microsecond)