ProtoBuf.jl icon indicating copy to clipboard operation
ProtoBuf.jl copied to clipboard

Julia Dates.DateTime type

Open edward-bestx opened this issue 7 months ago • 0 comments

Just a quick query about the DateTime type in Julia.

If one wanted to serialize this using Protobuf, what might be the best way of approaching this?

I tried serializing to integer UInt64.

julia> dt = DateTime(2025,4,22)
2025-04-22T00:00:00

julia> convert(UInt64, dt)
ERROR: MethodError: Cannot `convert` an object of type DateTime to an object of type UInt64

According to this question on Stack Overflow, there is a Datetime type.

import "google/protobuf/timestamp.proto";
```

I tried this too. I get a different error

```
julia> Example.MyMessage(DateTime(2025))
ERROR: MethodError: Cannot `convert` an object of type DateTime to an object of type Main.BidAskTimeseries_pb.google.protobuf.Timestamp
```

The corresponding proto file:

```
syntax = "proto3";

import "google/protobuf/timestamp.proto";

message MyMessage {
    google.protobuf.Timestamp timestamp = 1;
}
```

edward-bestx avatar Apr 22 '25 13:04 edward-bestx