[Tarantool-patches] [PATCH resend v2 10/11] lua, datetime: unixtime, timestamp setters in datetime.lua

Oleg Babin olegrok at tarantool.org
Sat Jul 31 09:31:36 MSK 2021


On 31.07.2021 02:11, Timur Safin wrote:
> Hello Oleg,
>
> :
> :
> : Unixtime and timestamp is great but they loss precision. I think it
> : should be possible
> :
> : go get timestamp with nanoseconds precision since datetime has
> : nanoseconds precision.
>
> I'm not quite get it. Do you want to have nanoseconds exported via newindex?
> For direct assignments? It's not useful because of available .nsec field.
> Or may be you meant something else?
>
> :
> :
> : Also still it's hard how to convert timestamp to datetime value back.
>
> Timestamp is something secs.nsec, what looks complicated? I'm confused.
> Could you please elaborate?

I expected something like.

tarantool> clock.time64()
---
- 1627712632369020000
...


This timestamp is in nanoseconds. It's unsigned long long value.

I tried to do something for datetime...

sec * 1e9 + nsec, but sec is null while nsec is not:

```

tarantool> dt.sec
---
- null
...

```


timestamp + nsec works in quite strage way:

```

tarantool> dt.timestamp * (1e9 * 1ULL) + dt.nsec
---
- 1627712485108074000
...

```

(I need to cast to ULL here to avoid precision lost).

But maybe my question is not relevant. There is a way to get nanoseconds 
timestamp.

I just need to write some simple helper for my app. It's ok.



More information about the Tarantool-patches mailing list