@@ -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
-
@@ -155,12 +155,14 @@ Functions
155
155
- 0
156
156
157
157
* - tzoffset
158
- - Time zone offset from UTC, in minutes. If both ``tzoffset `` and ``tz `` are specified, ``tz `` has the preference and the ``tzoffset `` value is ignored.
158
+ - Time zone offset from UTC, in minutes. If both ``tzoffset `` and
159
+ ``tz `` are specified, ``tz `` has the preference and the ``tzoffset ``
160
+ value is ignored. See a section :ref: `timezone <timezone >`.
159
161
- number
160
162
- 0
161
163
162
164
* - tz
163
- - Time zone name according to the ` tz database < https://en.wikipedia.org/wiki/Tz_database >`__ .
165
+ - Time zone name according to the Time Zone Database, see a section :ref: ` timezone < timezone >` .
164
166
- string
165
167
- -
166
168
@@ -327,7 +329,8 @@ Functions
327
329
- 1970-01-01T03:00:00.125+0300
328
330
...
329
331
330
- tarantool> dt = datetime.parse('01:01:01', {format ='%H:%M:%S'})
332
+ tarantool> dt = datetime.parse('01:01:01 MSK', {format ='%H:%M:%S %Z'})
333
+
331
334
---
332
335
...
333
336
@@ -346,6 +349,11 @@ Functions
346
349
- 5
347
350
...
348
351
352
+ tarantool> dt.tz
353
+ ---
354
+ - MSK
355
+ ...
356
+
349
357
.. _datetime-interval-is_interval :
350
358
351
359
.. function :: datetime.interval.is_interval([value])
@@ -497,9 +505,21 @@ Properties
497
505
498
506
Since: :doc: `2.11.0 </release/2.11.0 >`
499
507
500
- An array of timezone names and abbreviations.
508
+ A Lua table that maps timezone names (like ``Europe/Moscow ``) and
509
+ timezone abbreviations (like ``MSK ``) to its index and vice-versa,
510
+ see a section :ref: `timezone <timezone >`.
501
511
512
+ .. code-block :: tarantoolsession
502
513
514
+ tarantool> datetime.TZ['Europe/Moscow']
515
+ ---
516
+ - 947
517
+ ...
518
+
519
+ tarantool> datetime.TZ[947]
520
+ ---
521
+ - Europe/Moscow
522
+ ...
503
523
504
524
.. _datetime-module-api-reference-objects :
505
525
@@ -522,6 +542,8 @@ datetime_object
522
542
Modify an existing datetime object by adding values of the input argument.
523
543
See also: :ref: `interval_arithm `.
524
544
545
+ При вычислении :add/:sub и установленном tzindex вычисление производится с учётом tzdata.
546
+
525
547
:param table input: an :ref: `interval object <interval_obj >` or an equivalent table (see **Example #1 **)
526
548
:param string adjust: defines how to round days in a month after an arithmetic operation.
527
549
Possible values: ``none ``, ``last ``, ``excess `` (see **Example #2 **). Defaults to ``none ``.
@@ -703,6 +725,8 @@ datetime_object
703
725
Modify an existing datetime object by subtracting values of the input argument.
704
726
See also: :ref: `interval_arithm `.
705
727
728
+ При вычислении :add/:sub и установленном tzindex вычисление производится с учётом tzdata.
729
+
706
730
:param table input: an :ref: `interval object <interval_obj >` or an equivalent table (see **Example **)
707
731
:param string adjust: defines how to round days in a month after an arithmetic operation.
708
732
Possible values: ``none ``, ``last ``, ``excess ``. Defaults to ``none ``.
@@ -762,37 +786,41 @@ datetime_object
762
786
- Description
763
787
764
788
* - nsec
765
- - Nanoseconds
789
+ - Nanoseconds. Number.
766
790
767
791
* - sec
768
- - Seconds
792
+ - Seconds. Number.
769
793
770
794
* - min
771
- - Minutes
795
+ - Minutes. Number.
772
796
773
797
* - hour
774
- - Hours
798
+ - Hours. Number.
775
799
776
800
* - day
777
- - Day number
801
+ - Day number.
778
802
779
803
* - month
780
- - Month number
804
+ - Month number.
781
805
782
806
* - year
783
- - Year
807
+ - Year. Number.
784
808
785
809
* - wday
786
- - Days since the beginning of the week
810
+ - Days since the beginning of the week. Number.
787
811
788
812
* - yday
789
- - Days since the beginning of the year
813
+ - Days since the beginning of the year. Number.
790
814
791
815
* - isdst
792
- - Is the DST (Daylight saving time) applicable for the date. Boolean.
816
+ - Is the DST (Daylight Saving Time) applicable for the date,
817
+ see a section :ref: `timezone <timezone >`. Boolean.
793
818
794
819
* - tzoffset
795
- - Time zone offset from UTC
820
+ - Time zone offset from UTC, see a section :ref: `timezone <timezone >`. Number.
821
+
822
+ * - tz
823
+ - Time zone name or abbreviation, see a section :ref: `timezone <timezone >`. String.
796
824
797
825
:return: table with the date and time parameters
798
826
:rtype: table
@@ -809,20 +837,22 @@ datetime_object
809
837
day = 20,
810
838
month = 8,
811
839
year = 2021,
840
+ tz = 'MAGT',
812
841
}
813
842
---
814
843
...
815
844
816
845
tarantool> dt:totable()
817
846
---
818
- - sec: 20
847
+ - tz: 'MAGT'
848
+ sec: 20
819
849
min: 25
820
850
yday: 232
821
851
day: 20
822
852
nsec: 0
823
853
isdst: false
824
854
wday: 6
825
- tzoffset: 0
855
+ tzoffset: 600
826
856
month: 8
827
857
year: 2021
828
858
hour: 18
@@ -1080,11 +1110,69 @@ This section describes how the ``datetime`` module supports leap seconds:
1080
1110
- 1970-01-01T00:01:00Z
1081
1111
...
1082
1112
1113
+ .. _timezone :
1114
+
1115
+ Time zones
1116
+ ----------
1117
+
1118
+ Full support has been added since :doc: `2.11.0 </release/2.11.0 >`.
1119
+
1120
+ Tarantool uses `Time Zone Database <https://www.iana.org/time-zones >`__
1121
+ (also known as Olson database and supported by IANA) for timezone support.
1122
+ You can use the Lua module :ref: `tarantool <tarantool-module >` to get a used version of ``tzdata ``.
1123
+
1124
+ Every datetime object has three fields that represents timezone support:
1125
+ ``tz ``, ``tzoffset `` and ``isdst ``:
1126
+
1127
+ * The field ``isdst `` is calculated using tzindex and attributes of the selected
1128
+ timezone in the Olson DB timezone.
1129
+
1130
+ .. code-block :: tarantoolsession
1131
+
1132
+ tarantool> require('datetime').parse('2004-06-01T00:00 Europe/Moscow').isdst
1133
+ ---
1134
+ - true
1135
+ ...
1136
+
1137
+ * The field ``tz `` field can be set to timezone name or timezone abbreviation. Timezone name
1138
+ is a human-readable timezone names, basing on the Time Zone Database, for example "Europe/Moscow".
1139
+ Timezone abbreviation represents time zones by `alphabetic abbreviations <https://www.timeanddate.com/time/zones/ >`__
1140
+ such as "EST", "WST", and "CST". Both timezone names and abbreviations are available
1141
+ via bidirectional array :ref: `datetime.TZ <datetime-tz >`.
1142
+
1143
+ * The field ``tzoffset `` is calculated automatically using current Olson rule i.e.
1144
+ it would take into consideration summer time, leap year and leap seconds information
1145
+ when timezone name is set. However, field ``tzoffset `` can be set manually when appropriate timezone
1146
+ is not available.
1147
+
1148
+ The fields ``tz ``, ``tzoffset `` can be set :ref: `datetime.new() <datetime-new >`,
1149
+ :ref: `datetime.parse() <datetime-parse >` and :ref: `datetime_object:set() <datetime-set >`.
1150
+
1083
1151
Limitations
1084
1152
-----------
1085
1153
1086
1154
The supported date range is from ``-5879610-06-22 `` to ``+5879611-07-11 ``.
1087
1155
1156
+ There were moments in a past history, when local mean time in some partcular zone
1157
+ used timezone offset not representable in a whole minutes, but rather in seconds,
1158
+ i.e. in Moscow before 1918 there used to be offset +2 hours 31 minutes and 19 seconds.
1159
+ Please see Olson dump for this period:
1160
+
1161
+ .. code-block :: console
1162
+
1163
+ $ ./src/lib/tzcode/install/usr/bin/zdump -c1880,1918 -i Europe/Moscow
1164
+
1165
+ TZ="Europe/Moscow"
1166
+ - - +023017 MMT
1167
+ 1916-07-03 00:01:02 +023119 MMT
1168
+ 1917-07-02 00 +033119 MST 1
1169
+ 1917-12-27 23 +023119 MMT
1170
+
1171
+ Modern ``tzdata `` rules do not use such tiny fraction, and all timezones differ
1172
+ to UTC in units measured in minutes, not seconds. Tarantool datetime module uses
1173
+ minutes internally as units for ``tzoffset `` so there is some loss of precision
1174
+ if you try to operate with such ancient timestamps.
1175
+
1088
1176
References
1089
1177
----------
1090
1178
0 commit comments