There are several ways to get time in Tarantool
:
clock
modulefiber.time
functionos.date
But what is the correct way to work with dates?
Tarantool can be used in OLTP scenarios instead of relational databases, and such a solution will work many times faster. With Tarantool, you can replace the traditional bundle of database & cache and benefit from that by reducing operational costs. Tarantool is tolerant to write-heavy load.
It’s made more complicated by the fact that dates are also days of the week, like Monday or Friday, even though Excel doesn’t explicitly store that information in the cells. Here is the definitive guide to working with dates and times in Excel…
Python makes dealing with dates and time very easy, all we have to do is import a module named DateTime that comes along with python. It is a more efficient way to work with date without the need of being explicitly programmed.
Unfortunately, dates and times are often imported into worksheets as text. Most of the assorted functions like MONTH and HOUR are reasonably intelligent about converting on the fly.
For the first, there are several routines for Unix epoch:
os.time()
— classic Lua time function. Kinda slow and not very efficient. Not recommended to use inside tarantool for getting current epoch, but of course will work. May be used for getting epoch of arbitrary date (within local timezone). ex:os.time({ year = 2020, month = 6, day = 4 })
will produce 1591261200
, which is 12:00:00 in my GMT+3 timezone
clock.time()
(and clock.time64()
) — High resolution timer, almost raw binding to clock_gettime
. More information may be taken from doc
fiber.time()
(and also fiber.time64()
) — Cached version of clock.time. Updated every event loop iteration. Recommended for use if absolute precision of clock is not required.For converting epoch into different formats and timezones there are variants:
os.date("<format>" [, epoch ])
— Convert epoch into local timezone.os.date("!<format>" [, epoch ])
(note !
prefix) — Convert epoch into GMT timezone.os.date('*t')
for local and os.date('!*t')
for UTCicu-date
may be considered it you need to work with different timezones and/or formats.For example, if you need UTC time, it's ok to use cached fiber.time
with os.date
:
local fiber = require 'fiber'
os.date("!%Y-%m-%dT%H:%M:%SZ", fiber.time())
will return something like 2020-06-04T11:48:54Z
independently on timezone
It depends on your task.
If it's important for you to manipulate with timezones/formats etc. I suggest to use icu-data library (https://github.com/tarantool/icu-date)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With