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

Timur Safin tsafin at tarantool.org
Sat Jul 31 12:54:19 MSK 2021


: From: Oleg Babin <olegrok at tarantool.org>
: Subject: Re: [Tarantool-patches] [PATCH resend v2 10/11] lua, datetime:
: unixtime, timestamp setters in datetime.lua
: 
: 
: 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.

There are nanoseconds / microseconds / milliseconds getters in datetime
object, which operate on the original uint64_t. Do you want them to make
read-write, not read-only?

tarantool> T = date '1970-01-01'
---
...

tarantool> T.timestamp
---
- 0
...

tarantool> T.nanoseconds
---
- 0
...

tarantool> T2000 = date '2000-01-01'
---
...

tarantool> T.nanoseconds
---
- 0
...

tarantool> T2000.timestamp
---
- 946684800
...

tarantool> T2000.nanoseconds
---
- 946684800000000000
...

tarantool> T2000.secs
---
- 946684800
...

tarantool> ffi = require 'ffi'
---
...

tarantool> ffi.typeof(T2000.nanoseconds)
---
- ctype<int64_t>
...

Regards,
Timur



More information about the Tarantool-patches mailing list