Hi.
I want to define my own data types that could be used with Crystal primitive types interchangeably
for instance I want to be able to do the following
types.cr
file
struct Epoch;
def to_time; end
def other_func; end
end
alias E = Epoch
models.cr
file
struct Model
property x : Epoch = 1589831432
end
m = Model.new
puts m.x.to_time
puts m.x -> should give me 1589831432
so basically what I want is that is the new Epoch datatype to be initialized with Int64 directly
and then I can have other functions inside my Epoch
struct that can do other conversions
like convert it to UTC time, etc
How can I achieve something like this ?
Please note , this example is not about timestamps only , my intention is having a datatype that looks like
Int32 or Int64 or whatever but have custom functions where I can do my own conversions