<commit_before>%%% @doc
%%% Codec for `tsrange', `tstzrange', `daterange' types.
%%% https://www.postgresql.org/docs/current/static/rangetypes.html#rangetypes-builtin
%%% $PG$/src/backend/utils/adt/rangetypes.c
%%% @end
%%% Created : 16 Jul 2018 by <NAME> <<EMAIL>>
%%% TODO: universal range, based on pg_range table
%%% TODO: inclusive/exclusive ranges `[]' `[)' `(]' `()'

-module(epgsql_codec_timerange).
-behaviour(epgsql_codec).

-export([init/2, names/0, encode/3, decode/3, decode_text/3]).

-include("protocol.hrl").

-export_type([data/0]).

-type data() :: {epgsql_codec_datetime:data(), epgsql_codec_datetime:data()} | empty.

init(_, Sock) ->
    case epgsql_sock:get_parameter_internal(<<"integer_datetimes">>, Sock) of
        <<"on">>  -> epgsql_idatetime;
        <<"off">> -> epgsql_fdatetime
    end.

names() ->
    [tsrange, tstzrange, daterange].

encode(empty, _T, _CM) ->
    <<1>>;
encode({From, To}, Type, CoderMod) ->
    FromBin = CoderMod:encode(member_type(Type), From),
    ToBin = CoderMod:encode(member_type(Type), To),
    <<2:1/big-signed-unit:8,
      (byte_size(FromBin)):?int32, FromBin/binary,
      (byte_size(ToBin)):?int32, ToBin/binary>>.

decode(<<1>>, _, _) ->
    empty;
decode(<<2:1/big-signed-unit:8,
         FromLen:?int32, FromBin:FromLen/binary,
         ToLen:?int32, ToBin:ToLen/binary>>,
       Type, CoderMod) ->
    {CoderMod:decode(member_type(Type), FromBin), CoderMod:decode(member_type(Type), ToBin)}.

decode_text(V, _, _) -> V.

member_type(tsrange) -> timestamp;
member_type(tstzrange) -> timestamptz;
member_type(daterange) -> date.<commit_msg>make elvis happy<commit_after>%%% @doc
%%% Codec for `tsrange', `tstzrange', `daterange' types.
%%% https://www.postgresql.org/docs/current/static/rangetypes.html#rangetypes-builtin
%%% $PG$/src/backend/utils/adt/rangetypes.c
%%% @end
%%% Created : 16 Jul 2018 by <NAME> <<EMAIL>>
%%% TODO: universal range, based on pg_range table
%%% TODO: inclusive/exclusive ranges `[]' `[)' `(]' `()'

-module(epgsql_codec_timerange).
-behaviour(epgsql_codec).

-export([init/2, names/0, encode/3, decode/3, decode_text/3]).

-include("protocol.hrl").

-export_type([data/0]).

-type data() :: {epgsql_codec_datetime:data(), epgsql_codec_datetime:data()} | empty.

init(_, Sock) ->
    case epgsql_sock:get_parameter_internal(<<"integer_datetimes">>, Sock) of
        <<"on">>  -> epgsql_idatetime;
        <<"off">> -> epgsql_fdatetime
    end.

names() ->
    [tsrange, tstzrange, daterange].

encode(empty, _T, _CM) ->
    <<1>>;
encode({From, To}, Type, epgsql_idatetime) ->
    FromBin = epgsql_idatetime:encode(member_type(Type), From),
    ToBin = epgsql_idatetime:encode(member_type(Type), To),
    <<2:1/big-signed-unit:8,
      (byte_size(FromBin)):?int32, FromBin/binary,
      (byte_size(ToBin)):?int32, ToBin/binary>>;
encode({From, To}, Type, epgsql_fdatetime) ->
    FromBin = epgsql_fdatetime:encode(member_type(Type), From),
    ToBin = epgsql_fdatetime:encode(member_type(Type), To),
    <<2:1/big-signed-unit:8,
      (byte_size(FromBin)):?int32, FromBin/binary,
      (byte_size(ToBin)):?int32, ToBin/binary>>.

decode(<<1>>, _, _) ->
    empty;
decode(<<2:1/big-signed-unit:8,
         FromLen:?int32, FromBin:FromLen/binary,
         ToLen:?int32, ToBin:ToLen/binary>>,
       Type, epgsql_idatetime) ->
    {epgsql_idatetime:decode(member_type(Type), FromBin), epgsql_idatetime:decode(member_type(Type), ToBin)};
decode(<<2:1/big-signed-unit:8,
         FromLen:?int32, FromBin:FromLen/binary,
         ToLen:?int32, ToBin:ToLen/binary>>,
       Type, epgsql_fdatetime) ->
    {epgsql_fdatetime:decode(member_type(Type), FromBin), epgsql_fdatetime:decode(member_type(Type), ToBin)}.

decode_text(V, _, _) -> V.

member_type(tsrange) -> timestamp;
member_type(tstzrange) -> timestamptz;
member_type(daterange) -> date.
{'fraction_non_alphanumeric': 0.19186652763295098, 'fraction_numerical': 0.01824817518248175, 'mean_word_length': 4.593294460641399, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 67, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6527611', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1502, 'n_words': 221}