1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "file/FDateFunctions.hxx"
28cdf0e10cSrcweir #include <tools/date.hxx>
29cdf0e10cSrcweir #include <tools/time.hxx>
30cdf0e10cSrcweir #include <tools/datetime.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace connectivity;
33cdf0e10cSrcweir using namespace connectivity::file;
34cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const35cdf0e10cSrcweir ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 	if ( lhs.isNull() )
38cdf0e10cSrcweir 		return lhs;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 	sal_Int32 nRet = 0;
41cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
42cdf0e10cSrcweir 	Date aDate(aD.Day,aD.Month,aD.Year);
43cdf0e10cSrcweir 	DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
44cdf0e10cSrcweir 	switch(eDayOfWeek)
45cdf0e10cSrcweir 	{
46cdf0e10cSrcweir 		case MONDAY:
47cdf0e10cSrcweir 			nRet = 2;
48cdf0e10cSrcweir 			break;
49cdf0e10cSrcweir 		case TUESDAY:
50cdf0e10cSrcweir 			nRet = 3;
51cdf0e10cSrcweir 			break;
52cdf0e10cSrcweir 		case WEDNESDAY:
53cdf0e10cSrcweir 			nRet = 4;
54cdf0e10cSrcweir 			break;
55cdf0e10cSrcweir 		case THURSDAY:
56cdf0e10cSrcweir 			nRet = 5;
57cdf0e10cSrcweir 			break;
58cdf0e10cSrcweir 		case FRIDAY:
59cdf0e10cSrcweir 			nRet = 6;
60cdf0e10cSrcweir 			break;
61cdf0e10cSrcweir 		case SATURDAY:
62cdf0e10cSrcweir 			nRet = 7;
63cdf0e10cSrcweir 			break;
64cdf0e10cSrcweir 		case SUNDAY:
65cdf0e10cSrcweir 			nRet = 1;
66cdf0e10cSrcweir 			break;
67cdf0e10cSrcweir 		default:
68cdf0e10cSrcweir 			OSL_ENSURE(0,"Error in enum values for date");
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 	return nRet;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const73cdf0e10cSrcweir ORowSetValue OOp_DayOfMonth::operate(const ORowSetValue& lhs) const
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	if ( lhs.isNull() )
76cdf0e10cSrcweir 		return lhs;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
79cdf0e10cSrcweir 	return static_cast<sal_Int16>(aD.Day);
80cdf0e10cSrcweir }
81cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const82cdf0e10cSrcweir ORowSetValue OOp_DayOfYear::operate(const ORowSetValue& lhs) const
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	if ( lhs.isNull() )
85cdf0e10cSrcweir 		return lhs;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
88cdf0e10cSrcweir 	Date aDate(aD.Day,aD.Month,aD.Year);
89cdf0e10cSrcweir 	return static_cast<sal_Int16>(aDate.GetDayOfYear());
90cdf0e10cSrcweir }
91cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const92cdf0e10cSrcweir ORowSetValue OOp_Month::operate(const ORowSetValue& lhs) const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	if ( lhs.isNull() )
95cdf0e10cSrcweir 		return lhs;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
98cdf0e10cSrcweir 	return static_cast<sal_Int16>(aD.Month);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const101cdf0e10cSrcweir ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	if ( lhs.isNull() )
104cdf0e10cSrcweir 		return lhs;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	::rtl::OUString sRet;
107cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
108cdf0e10cSrcweir 	Date aDate(aD.Day,aD.Month,aD.Year);
109cdf0e10cSrcweir 	DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
110cdf0e10cSrcweir 	switch(eDayOfWeek)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		case MONDAY:
113cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Monday"));
114cdf0e10cSrcweir 			break;
115cdf0e10cSrcweir 		case TUESDAY:
116cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tuesday"));
117cdf0e10cSrcweir 			break;
118cdf0e10cSrcweir 		case WEDNESDAY:
119cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wednesday"));
120cdf0e10cSrcweir 			break;
121cdf0e10cSrcweir 		case THURSDAY:
122cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thursday"));
123cdf0e10cSrcweir 			break;
124cdf0e10cSrcweir 		case FRIDAY:
125cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Friday"));
126cdf0e10cSrcweir 			break;
127cdf0e10cSrcweir 		case SATURDAY:
128cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Saturday"));
129cdf0e10cSrcweir 			break;
130cdf0e10cSrcweir 		case SUNDAY:
131cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Sunday"));
132cdf0e10cSrcweir 			break;
133cdf0e10cSrcweir 		default:
134cdf0e10cSrcweir 			OSL_ENSURE(0,"Error in enum values for date");
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 	return sRet;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const139cdf0e10cSrcweir ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	if ( lhs.isNull() )
142cdf0e10cSrcweir 		return lhs;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	::rtl::OUString sRet;
145cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
146cdf0e10cSrcweir 	switch(aD.Month)
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir 		case 1:
149cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("January"));
150cdf0e10cSrcweir 			break;
151cdf0e10cSrcweir 		case 2:
152cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("February"));
153cdf0e10cSrcweir 			break;
154cdf0e10cSrcweir 		case 3:
155cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("March"));
156cdf0e10cSrcweir 			break;
157cdf0e10cSrcweir 		case 4:
158cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("April"));
159cdf0e10cSrcweir 			break;
160cdf0e10cSrcweir 		case 5:
161cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("May"));
162cdf0e10cSrcweir 			break;
163cdf0e10cSrcweir 		case 6:
164cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("June"));
165cdf0e10cSrcweir 			break;
166cdf0e10cSrcweir 		case 7:
167cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("July"));
168cdf0e10cSrcweir 			break;
169cdf0e10cSrcweir 		case 8:
170cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("August"));
171cdf0e10cSrcweir 			break;
172cdf0e10cSrcweir 		case 9:
173cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("September"));
174cdf0e10cSrcweir 			break;
175cdf0e10cSrcweir 		case 10:
176cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("October"));
177cdf0e10cSrcweir 			break;
178cdf0e10cSrcweir 		case 11:
179cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("November"));
180cdf0e10cSrcweir 			break;
181cdf0e10cSrcweir 		case 12:
182cdf0e10cSrcweir 			sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("December"));
183cdf0e10cSrcweir 			break;
184cdf0e10cSrcweir 	}
185cdf0e10cSrcweir 	return sRet;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const188cdf0e10cSrcweir ORowSetValue OOp_Quarter::operate(const ORowSetValue& lhs) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	if ( lhs.isNull() )
191cdf0e10cSrcweir 		return lhs;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	sal_Int32 nRet = 1;
194cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
195cdf0e10cSrcweir 	Date aDate(aD.Day,aD.Month,aD.Year);
196cdf0e10cSrcweir 	if ( aD.Month >= 4 && aD.Month < 7 )
197cdf0e10cSrcweir 		nRet = 2;
198cdf0e10cSrcweir 	else if ( aD.Month >= 7 && aD.Month < 10 )
199cdf0e10cSrcweir 		nRet = 3;
200cdf0e10cSrcweir 	else if ( aD.Month >= 10 && aD.Month <= 12 )
201cdf0e10cSrcweir 		nRet = 4;
202cdf0e10cSrcweir 	return nRet;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const205cdf0e10cSrcweir ORowSetValue OOp_Week::operate(const ::std::vector<ORowSetValue>& lhs) const
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	if ( lhs.empty() || lhs.size() > 2 )
208cdf0e10cSrcweir 		return ORowSetValue();
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	size_t nSize = lhs.size();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs[nSize-1];
213cdf0e10cSrcweir 	Date aDate(aD.Day,aD.Month,aD.Year);
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	sal_Int16 nStartDay = SUNDAY;
216cdf0e10cSrcweir 	if ( nSize == 2 && !lhs[0].isNull() )
217cdf0e10cSrcweir 		nStartDay = lhs[0];
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	return static_cast<sal_Int16>(aDate.GetWeekOfYear(static_cast<DayOfWeek>(nStartDay)));
220cdf0e10cSrcweir }
221cdf0e10cSrcweir // -----------------------------------------------------------------------------
operate(const ORowSetValue & lhs) const222cdf0e10cSrcweir ORowSetValue OOp_Year::operate(const ORowSetValue& lhs) const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir 	if ( lhs.isNull() )
225cdf0e10cSrcweir 		return lhs;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	::com::sun::star::util::Date aD = lhs;
228cdf0e10cSrcweir 	return static_cast<sal_Int16>(aD.Year);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const231cdf0e10cSrcweir ORowSetValue OOp_Hour::operate(const ORowSetValue& lhs) const
232cdf0e10cSrcweir {
233cdf0e10cSrcweir 	if ( lhs.isNull() )
234cdf0e10cSrcweir 		return lhs;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	::com::sun::star::util::Time aT = lhs;
237cdf0e10cSrcweir 	return static_cast<sal_Int16>(aT.Hours);
238cdf0e10cSrcweir }
239cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const240cdf0e10cSrcweir ORowSetValue OOp_Minute::operate(const ORowSetValue& lhs) const
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	if ( lhs.isNull() )
243cdf0e10cSrcweir 		return lhs;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	::com::sun::star::util::Time aT = lhs;
246cdf0e10cSrcweir 	return static_cast<sal_Int16>(aT.Minutes);
247cdf0e10cSrcweir }
248cdf0e10cSrcweir //------------------------------------------------------------------
operate(const ORowSetValue & lhs) const249cdf0e10cSrcweir ORowSetValue OOp_Second::operate(const ORowSetValue& lhs) const
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	if ( lhs.isNull() )
252cdf0e10cSrcweir 		return lhs;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 	::com::sun::star::util::Time aT = lhs;
255cdf0e10cSrcweir 	return static_cast<sal_Int16>(aT.Seconds);
256cdf0e10cSrcweir }
257cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const258cdf0e10cSrcweir ORowSetValue OOp_CurDate::operate(const ::std::vector<ORowSetValue>& lhs) const
259cdf0e10cSrcweir {
260cdf0e10cSrcweir 	if ( !lhs.empty() )
261cdf0e10cSrcweir 		return ORowSetValue();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	Date aCurDate;
264cdf0e10cSrcweir 	return ::com::sun::star::util::Date(aCurDate.GetDay(),aCurDate.GetMonth(),aCurDate.GetYear());
265cdf0e10cSrcweir }
266cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const267cdf0e10cSrcweir ORowSetValue OOp_CurTime::operate(const ::std::vector<ORowSetValue>& lhs) const
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	if ( !lhs.empty() )
270cdf0e10cSrcweir 		return ORowSetValue();
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	Time aCurTime;
273cdf0e10cSrcweir 	return ::com::sun::star::util::Time(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour());
274cdf0e10cSrcweir }
275cdf0e10cSrcweir //------------------------------------------------------------------
operate(const::std::vector<ORowSetValue> & lhs) const276cdf0e10cSrcweir ORowSetValue OOp_Now::operate(const ::std::vector<ORowSetValue>& lhs) const
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	if ( !lhs.empty() )
279cdf0e10cSrcweir 		return ORowSetValue();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	DateTime aCurTime;
282cdf0e10cSrcweir 	return ::com::sun::star::util::DateTime(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour(),
283cdf0e10cSrcweir 											aCurTime.GetDay(),aCurTime.GetMonth(),aCurTime.GetYear());
284cdf0e10cSrcweir }
285cdf0e10cSrcweir //------------------------------------------------------------------
286