-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
timetz
262 lines (208 loc) · 4.44 KB
/
timetz
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# LogicTest: default parallel-stmts distsql
# Note that the odd '0000-01-01 hh:mi:ss +0000 +0000' result format is an
# artifact of how pq displays TIMETZs.
query T
SELECT '12:00:00':::TIMETZ;
----
0000-01-01 12:00:00 +0000 +0000
query T
SELECT '12:00:00.456':::TIMETZ;
----
0000-01-01 12:00:00.456 +0000 +0000
query T
SELECT '12:00:00.456789':::TIMETZ;
----
0000-01-01 12:00:00.456789 +0000 +0000
query T
SELECT '12:00:00.456789+00':::TIMETZ;
----
0000-01-01 12:00:00.456789 +0000 +0000
query T
SELECT '12:00:00.456789-07':::TIMETZ;
----
0000-01-01 19:00:00.456789 +0000 +0000
query T
SELECT '23:59:59.999999-10':::TIMETZ;
----
0000-01-01 09:59:59.999999 +0000 +0000
statement error could not parse
SELECT '24:00:00':::TIMETZ;
query T
SELECT TIMETZ '12:00:00-07';
----
0000-01-01 19:00:00 +0000 +0000
# Casting
query T
SELECT '12:00:00-07'::TIMETZ;
----
0000-01-01 19:00:00 +0000 +0000
query T
select '12:00:00-07':::STRING::TIMETZ;
----
0000-01-01 19:00:00 +0000 +0000
query T
select '22:00:00-07':::STRING::TIMETZ;
----
0000-01-01 05:00:00 +0000 +0000
query T
SELECT '09:00:00.456-07' COLLATE de::TIMETZ;
----
0000-01-01 16:00:00.456 +0000 +0000
query T
SELECT '2017-01-01 12:00:00-07':::TIMESTAMPTZ::TIMETZ;
----
0000-01-01 19:00:00 +0000 +0000
query T
select '12:00:00-07:00'::TIMETZ::STRING;
----
12:00:00-07:00
# Comparison
query B
select '12:00:00+00':::TIMETZ = '12:00:00+00':::TIMETZ
----
true
query B
select '12:00:00-06':::TIMETZ = '12:00:00-07':::TIMETZ
----
false
query B
select '12:00:00+00':::TIMETZ >= '12:00:00+00':::TIMETZ
----
true
query B
select '12:00:00+00':::TIMETZ <= '12:00:00+00':::TIMETZ
----
true
query B
SELECT '12:00:00+01:00':::TIMETZ < '11:59:59.999999+00':::TIMETZ
----
true
query B
SELECT '12:00:00+01:00':::TIMETZ < '11:59:59.999999+02':::TIMETZ
----
false
query B
SELECT '12:00:00+01:00':::TIMETZ > '11:59:59.999999+02':::TIMETZ
----
true
query B
SELECT '12:00:00-05':::TIMETZ IN ('12:00:00');
----
false
query B
SELECT '12:00:00-05':::TIMETZ IN ('12:00:00-05');
----
true
query B
SELECT '12:00:00-05':::TIMETZ IN ('12:00:00-07');
----
false
query B
SELECT '12:00:00-05':::TIMETZ IN ('11:00:00-06');
----
true
# Arithmetic
query T
SELECT '12:00:00-01':::TIMETZ + '1s':::INTERVAL
----
0000-01-01 13:00:01 +0000 +0000
query T
SELECT '23:59:59+00':::TIMETZ + '1s':::INTERVAL
----
0000-01-01 00:00:00 +0000 +0000
query T
SELECT '12:00:00-07':::TIMETZ + '1d':::INTERVAL
----
0000-01-01 19:00:00 +0000 +0000
query T
SELECT '1s':::INTERVAL + '12:00:00+03':::TIMETZ
----
0000-01-01 09:00:01 +0000 +0000
query T
SELECT '12:00:00-07':::TIMETZ - '1s':::INTERVAL
----
0000-01-01 18:59:59 +0000 +0000
query T
SELECT '12:00:00-07':::TIMETZ - '1d':::INTERVAL
----
0000-01-01 19:00:00 +0000 +0000
query T
SELECT '12:00:00-07':::TIMETZ - '11:59:59':::TIME
----
0000-01-01 07:00:01 +0000 +0000
query T
SELECT '11:59:59+00':::TIMETZ - '12:00:00':::TIME
----
0000-01-01 23:59:59 +0000 +0000
query T
SELECT '00:00:59+07':::TIMETZ + '12:00:00':::TIME
----
0000-01-01 05:00:59 +0000 +0000
query T
SELECT '2017-01-01':::DATE + '12:00:00-03':::TIMETZ
----
2017-01-01 15:00:00 +0000 +0000
query T
SELECT '12:00:00+03':::TIMETZ + '2017-01-01':::DATE
----
2017-01-01 09:00:00 +0000 +0000
# Storage
statement ok
CREATE TABLE timetzs (t timetz PRIMARY KEY)
statement ok
INSERT INTO timetzs VALUES
('00:00:00-07'),
('00:00:00.000001+06'),
('11:59:59.999999+10'),
('12:00:00-05'),
('12:00:00.000001-05'),
('23:59:59.999999+00')
query T
SELECT * FROM timetzs ORDER BY t
----
0000-01-01 18:00:00.000001 +0000 +0000
0000-01-01 01:59:59.999999 +0000 +0000
0000-01-01 07:00:00 +0000 +0000
0000-01-01 17:00:00 +0000 +0000
0000-01-01 17:00:00.000001 +0000 +0000
0000-01-01 23:59:59.999999 +0000 +0000
statement ok
CREATE TABLE tzarrays (timetzs TIMETZ[])
statement ok
INSERT INTO tzarrays VALUES
(ARRAY[]),
(ARRAY['00:00:00-07']),
(ARRAY['00:00:00-07', '12:00:00.000001-07']),
('{13:00:00-07}'::TIMETZ[])
query T rowsort
SELECT * FROM tzarrays
----
{}
{07:00:00+00:00}
{07:00:00+00:00,19:00:00.000001+00:00}
{20:00:00+00:00}
# Built-ins
query I
SELECT extract(hour from timetz '12:01:02.345678-07')
----
12
query I
SELECT extract(minute from timetz '12:01:02.345678+03')
----
1
query I
SELECT extract(second from timetz '12:01:02.345678-06')
----
2
query I
SELECT extract(millisecond from timetz '12:01:02.345678+00')
----
345
query I
SELECT extract(microsecond from timetz '12:01:02.345678-05')
----
345678
query I
SELECT extract(epoch from timetz '12:00:00+04')
----
43200