tarantool / tarantool-python

Python client library for Tarantool
https://www.tarantool.io
BSD 2-Clause "Simplified" License
101 stars 46 forks source link

Support datetime interval extended type and arithmetic #230

Closed DifferentialOrange closed 2 years ago

DifferentialOrange commented 2 years ago

msgpack: support datetime interval extended type

Tarantool supports datetime interval type since version 2.10.0 [1]. This patch introduced the support of Tarantool interval type in msgpack decoders and encoders.

Tarantool datetime interval objects are decoded to tarantool.Interval type. tarantool.Interval may be encoded to Tarantool interval objects.

You can create tarantool.Interval objects either from msgpack data or by using the same API as in Tarantool:

di = tarantool.Interval(year=-1, month=2, day=3,
                        hour=4, minute=-5, sec=6,
                        nsec=308543321,
                        adjust=tarantool.IntervalAdjust.NONE)

Its attributes (same as in init API) are exposed, so you can use them if needed.

datetime, numpy and pandas tools doesn't seem to be sufficient to cover all adjust cases supported by Tarantool.

This patch does not yet introduce the support of datetime interval arithmetic.

  1. https://github.com/tarantool/tarantool/issues/5941

Part of #229

msgpack: support datetime interval arithmetic

Support datetime and interval arithmetic with the same rules as in Tarantool [1].

Valid operations:

Since tarantool.Interval could contain month and year fields and such operations could be ambiguous, you can use adjust field to tune the logic.

Tarantool does not yet correctly support subtraction of datetime objects with different timezones [2] and addition of intervals to datetimes with non-fixed offset timezones [3]. tarantool-python implementation support them, but it could be reworked later if core team choose another solution.

  1. https://github.com/tarantool/tarantool/wiki/Datetime-Internals#interval-arithmetic
  2. https://github.com/tarantool/tarantool/issues/7698
  3. https://github.com/tarantool/tarantool/issues/7700

Closes #229