DateTime.from_unix!(-100000, :microsecond)
The zero_pad function should ignore the negative sign when adding zeros.
I'm happy to take this if no one is already?
Please do!
Great! I'll get started.
If this is still open, I'd like to pick this up.
@vishaldeepak I'm working on this today. If I make no progress will let you know. :+1:
If I'm understanding correctly, the actual issue is that calling DateTime.from_unix/2 with a negative value (which is not a multiple of 1_000_000), and :microsecond unit returns a DateTime struct with a negative microsecond value. e.g.
iex(1)> DateTime.from_unix!(-1, :microsecond)
#DateTime<1970-01-01 00:00:00.0000-1Z>
when we would expect the following:
iex(1)> DateTime.from_unix!(-1, :microsecond)
#DateTime<1969-12-31 23:59:59.999999Z>
I have a fix for this which I'll submit tomorrow. If I haven't understood this correctly, or there's a good reason to keep the negative microsecond output please let me know!
No, there is no reason to keep it negative.