xref: /trunk/main/connectivity/source/inc/file/FDateFunctions.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_FILE_FDATEFUNCTIONS_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_FILE_FDATEFUNCTIONS_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "file/fcode.hxx"
32*cdf0e10cSrcweir #include "file/filedllapi.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir namespace connectivity
35*cdf0e10cSrcweir {
36*cdf0e10cSrcweir     class OSQLParseNode;
37*cdf0e10cSrcweir     namespace file
38*cdf0e10cSrcweir     {
39*cdf0e10cSrcweir         /** DAYOFWEEK(date)
40*cdf0e10cSrcweir             Returns the weekday index for date (1 = Sunday, 2 = Monday, ... 7 = Saturday). These index values correspond to the ODBC standard.
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir         > SELECT DAYOFWEEK('1998-02-03');
43*cdf0e10cSrcweir                 -> 3
44*cdf0e10cSrcweir         */
45*cdf0e10cSrcweir         class OOp_DayOfWeek : public OUnaryOperator
46*cdf0e10cSrcweir         {
47*cdf0e10cSrcweir         protected:
48*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
49*cdf0e10cSrcweir         };
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir         /** DAYOFMONTH(date)
52*cdf0e10cSrcweir             Returns the day of the month for date, in the range 1 to 31:
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir         > SELECT DAYOFMONTH('1998-02-03');
55*cdf0e10cSrcweir                 -> 3
56*cdf0e10cSrcweir         */
57*cdf0e10cSrcweir         class OOp_DayOfMonth : public OUnaryOperator
58*cdf0e10cSrcweir         {
59*cdf0e10cSrcweir         protected:
60*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
61*cdf0e10cSrcweir         };
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir         /** DAYOFYEAR(date)
64*cdf0e10cSrcweir             Returns the day of the year for date, in the range 1 to 366:
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir         > SELECT DAYOFYEAR('1998-02-03');
67*cdf0e10cSrcweir                 -> 34
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         */
70*cdf0e10cSrcweir         class OOp_DayOfYear : public OUnaryOperator
71*cdf0e10cSrcweir         {
72*cdf0e10cSrcweir         protected:
73*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
74*cdf0e10cSrcweir         };
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         /** MONTH(date)
77*cdf0e10cSrcweir             Returns the month for date, in the range 1 to 12:
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir         > SELECT MONTH('1998-02-03');
80*cdf0e10cSrcweir                 -> 2
81*cdf0e10cSrcweir         */
82*cdf0e10cSrcweir         class OOp_Month : public OUnaryOperator
83*cdf0e10cSrcweir         {
84*cdf0e10cSrcweir         protected:
85*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
86*cdf0e10cSrcweir         };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir         /** DAYNAME(date)
89*cdf0e10cSrcweir             Returns the name of the weekday for date:
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         > SELECT DAYNAME('1998-02-05');
92*cdf0e10cSrcweir                 -> 'Thursday'
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         */
95*cdf0e10cSrcweir         class OOp_DayName : public OUnaryOperator
96*cdf0e10cSrcweir         {
97*cdf0e10cSrcweir         protected:
98*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
99*cdf0e10cSrcweir         };
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         /** MONTHNAME(date)
102*cdf0e10cSrcweir             Returns the name of the month for date:
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir         > SELECT MONTHNAME('1998-02-05');
105*cdf0e10cSrcweir                 -> 'February'
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         */
108*cdf0e10cSrcweir         class OOp_MonthName : public OUnaryOperator
109*cdf0e10cSrcweir         {
110*cdf0e10cSrcweir         protected:
111*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
112*cdf0e10cSrcweir         };
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         /** QUARTER(date)
115*cdf0e10cSrcweir             Returns the quarter of the year for date, in the range 1 to 4:
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir         > SELECT QUARTER('98-04-01');
118*cdf0e10cSrcweir                 -> 2
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir         */
121*cdf0e10cSrcweir         class OOp_Quarter : public OUnaryOperator
122*cdf0e10cSrcweir         {
123*cdf0e10cSrcweir         protected:
124*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
125*cdf0e10cSrcweir         };
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir         /** WEEK(date)
128*cdf0e10cSrcweir             WEEK(date,first)
129*cdf0e10cSrcweir                 With a single argument, returns the week for date, in the range 0 to 53 (yes, there may be the beginnings of a week 53), for locations where Sunday is the first day of the week. The two-argument form of WEEK() allows you to specify whether the week starts on Sunday or Monday and whether the return value should be in the range 0-53 or 1-52. Here is a table for how the second argument works:
130*cdf0e10cSrcweir                 Value   Meaning
131*cdf0e10cSrcweir                 0   Week starts on Sunday and return value is in range 0-53
132*cdf0e10cSrcweir                 1   Week starts on Monday and return value is in range 0-53
133*cdf0e10cSrcweir                 2   Week starts on Sunday and return value is in range 1-53
134*cdf0e10cSrcweir                 3   Week starts on Monday and return value is in range 1-53 (ISO 8601)
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir             > SELECT WEEK('1998-02-20');
137*cdf0e10cSrcweir                     -> 7
138*cdf0e10cSrcweir             > SELECT WEEK('1998-02-20',0);
139*cdf0e10cSrcweir                     -> 7
140*cdf0e10cSrcweir             > SELECT WEEK('1998-02-20',1);
141*cdf0e10cSrcweir                     -> 8
142*cdf0e10cSrcweir             > SELECT WEEK('1998-12-31',1);
143*cdf0e10cSrcweir                     -> 53
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir         */
146*cdf0e10cSrcweir         class OOp_Week : public ONthOperator
147*cdf0e10cSrcweir         {
148*cdf0e10cSrcweir         protected:
149*cdf0e10cSrcweir             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
150*cdf0e10cSrcweir         };
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         /** YEAR(date)
153*cdf0e10cSrcweir             Returns the year for date, in the range 1000 to 9999:
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir         > SELECT YEAR('98-02-03');
156*cdf0e10cSrcweir                 -> 1998
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         class OOp_Year : public OUnaryOperator
159*cdf0e10cSrcweir         {
160*cdf0e10cSrcweir         protected:
161*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
162*cdf0e10cSrcweir         };
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir         /** HOUR(time)
165*cdf0e10cSrcweir             Returns the hour for time, in the range 0 to 23:
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         > SELECT HOUR('10:05:03');
168*cdf0e10cSrcweir                 -> 10
169*cdf0e10cSrcweir         */
170*cdf0e10cSrcweir         class OOp_Hour : public OUnaryOperator
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir         protected:
173*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
174*cdf0e10cSrcweir         };
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         /** MINUTE(time)
177*cdf0e10cSrcweir             Returns the minute for time, in the range 0 to 59:
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir         > SELECT MINUTE('98-02-03 10:05:03');
180*cdf0e10cSrcweir                 -> 5
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         */
183*cdf0e10cSrcweir         class OOp_Minute : public OUnaryOperator
184*cdf0e10cSrcweir         {
185*cdf0e10cSrcweir         protected:
186*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
187*cdf0e10cSrcweir         };
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         /** SECOND(time)
190*cdf0e10cSrcweir             Returns the second for time, in the range 0 to 59:
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir         > SELECT SECOND('10:05:03');
193*cdf0e10cSrcweir                 -> 3
194*cdf0e10cSrcweir         */
195*cdf0e10cSrcweir         class OOp_Second : public OUnaryOperator
196*cdf0e10cSrcweir         {
197*cdf0e10cSrcweir         protected:
198*cdf0e10cSrcweir             virtual ORowSetValue operate(const ORowSetValue& lhs) const;
199*cdf0e10cSrcweir         };
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir         /** CURDATE()
202*cdf0e10cSrcweir             CURRENT_DATE
203*cdf0e10cSrcweir                 Returns today's date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context:
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir             > SELECT CURDATE();
206*cdf0e10cSrcweir                     -> '1997-12-15'
207*cdf0e10cSrcweir         */
208*cdf0e10cSrcweir         class OOp_CurDate : public ONthOperator
209*cdf0e10cSrcweir         {
210*cdf0e10cSrcweir         protected:
211*cdf0e10cSrcweir             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
212*cdf0e10cSrcweir         };
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir         /** CURTIME()
215*cdf0e10cSrcweir             CURRENT_TIME
216*cdf0e10cSrcweir                 Returns the current time as a value in 'HH:MM:SS' or HHMMSS format, depending on whether the function is used in a string or numeric context:
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir             > SELECT CURTIME();
219*cdf0e10cSrcweir                     -> '23:50:26'
220*cdf0e10cSrcweir         */
221*cdf0e10cSrcweir         class OOp_CurTime : public ONthOperator
222*cdf0e10cSrcweir         {
223*cdf0e10cSrcweir         protected:
224*cdf0e10cSrcweir             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
225*cdf0e10cSrcweir         };
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir         /** NOW()
228*cdf0e10cSrcweir             Returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context:
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir             > SELECT NOW();
231*cdf0e10cSrcweir                     -> '1997-12-15 23:50:26'
232*cdf0e10cSrcweir         */
233*cdf0e10cSrcweir         class OOp_Now : public ONthOperator
234*cdf0e10cSrcweir         {
235*cdf0e10cSrcweir         protected:
236*cdf0e10cSrcweir             virtual ORowSetValue operate(const ::std::vector<ORowSetValue>& lhs) const;
237*cdf0e10cSrcweir         };
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir #endif // _CONNECTIVITY_FILE_FCODE_HXX_
242*cdf0e10cSrcweir 
243