@@ -50,7 +50,7 @@ Below is a list of ``datetime`` functions, properties, and related objects.
50
50
-
51
51
52
52
* - :ref: `datetime.TZ <datetime-tz >`
53
- - An array of timezone names and abbreviations
53
+ - A Lua table that maps timezone names and abbreviations to its index and vice-versa.
54
54
55
55
* - **Methods **
56
56
-
@@ -327,7 +327,8 @@ Functions
327
327
- 1970-01-01T03:00:00.125+0300
328
328
...
329
329
330
- tarantool> dt = datetime.parse('01:01:01', {format ='%H:%M:%S'})
330
+ tarantool> dt = datetime.parse('01:01:01 MSK', {format ='%H:%M:%S %Z'})
331
+
331
332
---
332
333
...
333
334
@@ -346,6 +347,11 @@ Functions
346
347
- 5
347
348
...
348
349
350
+ tarantool> dt.tz
351
+ ---
352
+ - MSK
353
+ ...
354
+
349
355
.. _datetime-interval-is_interval :
350
356
351
357
.. function :: datetime.interval.is_interval([value])
@@ -497,9 +503,20 @@ Properties
497
503
498
504
Since: :doc: `2.11.0 </release/2.11.0 >`
499
505
500
- An array of timezone names and abbreviations.
506
+ A Lua table that maps timezone names (like ``Europe/Moscow ``) and
507
+ timezone abbreviations (like ``MSK ``) to its index and vice-versa.
501
508
509
+ .. code-block :: tarantoolsession
502
510
511
+ tarantool> datetime.TZ['Europe/Moscow']
512
+ ---
513
+ - 947
514
+ ...
515
+
516
+ tarantool> datetime.TZ[947]
517
+ ---
518
+ - Europe/Moscow
519
+ ...
503
520
504
521
.. _datetime-module-api-reference-objects :
505
522
@@ -522,6 +539,8 @@ datetime_object
522
539
Modify an existing datetime object by adding values of the input argument.
523
540
See also: :ref: `interval_arithm `.
524
541
542
+ При вычислении :add/:sub и установленном tzindex вычисление производится с учётом tzdata.
543
+
525
544
:param table input: an :ref: `interval object <interval_obj >` or an equivalent table (see **Example #1 **)
526
545
:param string adjust: defines how to round days in a month after an arithmetic operation.
527
546
Possible values: ``none ``, ``last ``, ``excess `` (see **Example #2 **). Defaults to ``none ``.
@@ -703,6 +722,8 @@ datetime_object
703
722
Modify an existing datetime object by subtracting values of the input argument.
704
723
See also: :ref: `interval_arithm `.
705
724
725
+ При вычислении :add/:sub и установленном tzindex вычисление производится с учётом tzdata.
726
+
706
727
:param table input: an :ref: `interval object <interval_obj >` or an equivalent table (see **Example **)
707
728
:param string adjust: defines how to round days in a month after an arithmetic operation.
708
729
Possible values: ``none ``, ``last ``, ``excess ``. Defaults to ``none ``.
@@ -789,10 +810,14 @@ datetime_object
789
810
- Days since the beginning of the year
790
811
791
812
* - isdst
792
- - Is the DST (Daylight saving time) applicable for the date. Boolean.
813
+ - Is the DST (Daylight Saving Time) applicable for the date,
814
+ see a section :ref: `timezone <timezone >`. Boolean.
793
815
794
816
* - tzoffset
795
- - Time zone offset from UTC
817
+ - Time zone offset from UTC, see a section :ref: `timezone <timezone >`. Number.
818
+
819
+ * - tz
820
+ - Time zone name or abbreviation, see a section :ref: `timezone <timezone >`. String.
796
821
797
822
:return: table with the date and time parameters
798
823
:rtype: table
@@ -1080,11 +1105,69 @@ This section describes how the ``datetime`` module supports leap seconds:
1080
1105
- 1970-01-01T00:01:00Z
1081
1106
...
1082
1107
1108
+ .. _timezone :
1109
+
1110
+ Time zones
1111
+ ----------
1112
+
1113
+ Full support has been added since :doc: `2.11.0 </release/2.11.0 >`.
1114
+
1115
+ Tarantool uses `Time Zone Database <https://www.iana.org/time-zones >`__
1116
+ (also known as Olson database and supported by IANA) for timezone support.
1117
+ You can use the Lua module :ref: `tarantool <tarantool-module >` to get a used version of ``tzdata ``.
1118
+
1119
+ Every datetime object has three fields that represents timezone support:
1120
+ ``tz ``, ``tzoffset `` and ``isdst ``:
1121
+
1122
+ * The field ``isdst `` is calculated using tzindex and attributes of the selected
1123
+ timezone in the Olson DB timezone.
1124
+
1125
+ .. code-block :: tarantoolsession
1126
+
1127
+ tarantool> require('datetime').parse('2004-06-01T00:00 Europe/Moscow').isdst
1128
+ ---
1129
+ - true
1130
+ ...
1131
+
1132
+ * The field ``tz `` field can be set to timezone name or timezone abbreviation. Timezone name
1133
+ is a human-readable timezone names, basing on the Time Zone Database, for example "Europe/Moscow".
1134
+ Timezone abbreviation represents time zones by `alphabetic abbreviations <https://www.timeanddate.com/time/zones/ >`__
1135
+ such as "EST", "WST", and "CST". Both timezone names and abbreviations are available
1136
+ via bidirectional array :ref: `datetime.TZ <datetime-tz >`.
1137
+
1138
+ * The field ``tzoffset `` is calculated automatically using current Olson rule i.e.
1139
+ it would take into consideration summer time, leap year and leap seconds information
1140
+ when timezone name is set. However, field ``tzoffset `` can be set manually when appropriate timezone
1141
+ is not available.
1142
+
1143
+ The fields ``tz ``, ``tzoffset `` can be set :ref: `datetime.new() <datetime-new >`,
1144
+ :ref: `datetime.parse() <datetime-parse >` and :ref: `datetime_object:set() <datetime-set >`.
1145
+
1083
1146
Limitations
1084
1147
-----------
1085
1148
1086
1149
The supported date range is from ``-5879610-06-22 `` to ``+5879611-07-11 ``.
1087
1150
1151
+ There were moments in a past history, when local mean time in some partcular zone
1152
+ used timezone offset not representable in a whole minutes, but rather in seconds,
1153
+ i.e. in Moscow before 1918 there used to be offset +2 hours 31 minutes and 19 seconds.
1154
+ Please see Olson dump for this period:
1155
+
1156
+ .. code-block :: console
1157
+
1158
+ $ ./src/lib/tzcode/install/usr/bin/zdump -c1880,1918 -i Europe/Moscow
1159
+
1160
+ TZ="Europe/Moscow"
1161
+ - - +023017 MMT
1162
+ 1916-07-03 00:01:02 +023119 MMT
1163
+ 1917-07-02 00 +033119 MST 1
1164
+ 1917-12-27 23 +023119 MMT
1165
+
1166
+ Modern ``tzdata `` rules do not use such tiny fraction, and all timezones differ
1167
+ to UTC in units measured in minutes, not seconds. Tarantool datetime module uses
1168
+ minutes internally as units for ``tzoffset `` so there is some loss of precision
1169
+ if you try to operate with such ancient timestamps.
1170
+
1088
1171
References
1089
1172
----------
1090
1173
0 commit comments