So this seems to have changed: GitHub - elixir-protobuf/google-protos: Elixir files generated from Google's protobuf files using protobuf-elixir and the author of google-protos is recommending just using the main protobuf library instead, which I am doing.
But this doesn’t seem to be recognising my timestamps. Here is my IntradayBarRequest protobuf definition:
message IntradayBarRequest {
string topic = 2; // securities
google.protobuf.Timestamp start = 3; // startDate
google.protobuf.Timestamp end = 4; // endDate
int32 interval = 5; // interval in minutes
map <string, string> options = 6;
}
But when I try to create timestamps, they’re not accepted:
iex(25)> tpc
%Bloomberg.IntradayBarRequest{
topic: “USDZAR Curncy”,
start: ~U[2025-09-01 13:00:00Z],
end: ~U[2025-10-30 18:12:22.878335Z],
interval: 1,
options: %{},
unknown_fields:
}
iex(26)> Bloomberg.Bbg.Stub.intraday_bar_request(chan, tpc)
** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protobuf.EncodeError) struct DateTime can’t be encoded as Google.Protobuf.Timestamp: ~U[2025-09-01 13:00:00Z]
(grpc 0.11.3) lib/grpc/telemetry.ex:125: anonymous fn/2 in GRPC.Telemetry.client_span/3
(telemetry 1.3.0) /home/tbrowne/code/suprabonds/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(grpc 0.11.3) lib/grpc/telemetry.ex:118: GRPC.Telemetry.client_span/3
iex:26: (file)
[error] ** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protobuf.EncodeError) struct DateTime can’t be encoded as Google.Protobuf.Timestamp: ~U[2025-09-01 13:00:00Z]
(grpc 0.11.3) lib/grpc/telemetry.ex:125: anonymous fn/2 in GRPC.Telemetry.client_span/3
(telemetry 1.3.0) /home/tbrowne/code/suprabonds/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3
(grpc 0.11.3) lib/grpc/telemetry.ex:118: GRPC.Telemetry.client_span/3
(elixir 1.19.1) elixir.erl:365: :elixir.eval_external_handler/3
(stdlib 7.1) erl_eval.erl:924: :erl_eval.do_apply/7
(elixir 1.19.1) elixir.erl:343: :elixir.eval_forms/4
(elixir 1.19.1) lib/module/parallel_checker.ex:152: Module.ParallelChecker.verify/1
(iex 1.19.1) lib/iex/evaluator.ex:349: IEx.Evaluator.eval_and_inspect/3
(iex 1.19.1) lib/iex/evaluator.ex:321: IEx.Evaluator.safe_eval_and_inspect/3
(iex 1.19.1) lib/iex/evaluator.ex:212: IEx.Evaluator.loop/1
(iex 1.19.1) lib/iex/evaluator.ex:38: IEx.Evaluator.init/5
(stdlib 7.1) proc_lib.erl:333: :proc_lib.init_p_do_apply/3
Different error if I try to convert those timestamps to_unix:
iex(26)> tpc = %Bloomberg.IntradayBarRequest{topic: “USDZAR Curncy”, interval: 1, start: DateTime.new!(~D[2025-09-01], ~T[13:00:00], “Etc/UTC”) |> DateTime.to_unix, end: DateTime.utc_now() |> DateTime.to_unix()}
%Bloomberg.IntradayBarRequest{
topic: “USDZAR Curncy”,
start: 1756731600,
end: 1761848742,
interval: 1,
options: %{},
unknown_fields:
}
iex(27)> Bloomberg.Bbg.Stub.intraday_bar_request(chan, tpc)
** (Protobuf.EncodeError) Got error when encoding Bloomberg.IntradayBarRequest#start: ** (Protocol.UndefinedError) protocol Enumerable not implemented for Integer. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, Explorer.Series.Iterator, File.Stream, Flow, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, SFTPClient.Stream, Stream, Table.Mapper, Table.Zipper
Any info on how to get Elixir dates/times into Google protobuf timestamps>
EDIT: figured it out:
iex(27)> %Google.Protobuf.Timestamp{seconds: 1, nanos: 1}
%Google.Protobuf.Timestamp{seconds: 1, nanos: 1, unknown_fields: }