# Timestamps in \[MsgPack.jl\](https://github.com/JuliaIO/MsgPack.jl)

**URL:** <https://discourse.julialang.org/t/timestamps-in-msgpack-jl-https-github-com-juliaio-msgpack-jl/40255>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 27, 2020, 2:00pm UTC](https://discourse.julialang.org/t/timestamps-in-msgpack-jl-https-github-com-juliaio-msgpack-jl/40255 "2020-05-27T14:00:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)\
**Post date:** [May 27, 2020, 2:00pm UTC](https://discourse.julialang.org/t/timestamps-in-msgpack-jl-https-github-com-juliaio-msgpack-jl/40255/1 "2020-05-27T14:00:41Z")

</div>

Hey 🙂

I’m using MsgPack.jl and trying to add an ExtentionType ([Link](https://juliaio.github.io/MsgPack.jl/latest/#MessagePack-Extension-Functionality-1)). But I want to define my one deserialization as defined [here](https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type).

I hope someone knows how it works 👍

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [May 29, 2020, 12:22am UTC](https://discourse.julialang.org/t/timestamps-in-msgpack-jl-https-github-com-juliaio-msgpack-jl/40255/2 "2020-05-29T00:22:34Z")

</div>

I don’t quite understand what you want to do, but something you can do is

```julia
using MsgPack, Dates
using Dates: Nanosecond

# Define how to serialize `Dates.Nanosecond`
MsgPack.msgpack_type(::Type{Nanosecond}) = MsgPack.IntegerType()
MsgPack.from_msgpack(::Type{Nanosecond}, x::Integer) = Nanosecond(x)
MsgPack.to_msgpack(::MsgPack.IntegerType, x::Nanosecond) = x.value

# Define some kind of timestamp object...
struct MyTimestamp
   time::Nanosecond
end

# Tell MsgPack how to serialize it
MsgPack.msgpack_type(::Type{MyTimestamp}) = MsgPack.StructType()

# Give it a try
a = MyTimestamp(Nanosecond(100))
bytes = pack(a)
unpack(bytes, MyTimestamp) == a # returns `true`

```

I’m not sure that’s helpful but I figured I’d mention it, since I just learned about it today ([Add `msgpack_type(::Type{TimeSpan})` by ericphanson · Pull Request #45 · beacon-biosignals/Onda.jl · GitHub](https://github.com/beacon-biosignals/Onda.jl/pull/45)).
