1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FDateFunctions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "file/FDateFunctions.hxx"
35 #include <tools/date.hxx>
36 #include <tools/time.hxx>
37 #include <tools/datetime.hxx>
39 using namespace connectivity
;
40 using namespace connectivity::file
;
41 //------------------------------------------------------------------
42 ORowSetValue
OOp_DayOfWeek::operate(const ORowSetValue
& lhs
) const
48 ::com::sun::star::util::Date aD
= lhs
;
49 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
50 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
75 OSL_ENSURE(0,"Error in enum values for date");
79 //------------------------------------------------------------------
80 ORowSetValue
OOp_DayOfMonth::operate(const ORowSetValue
& lhs
) const
85 ::com::sun::star::util::Date aD
= lhs
;
86 return static_cast<sal_Int16
>(aD
.Day
);
88 //------------------------------------------------------------------
89 ORowSetValue
OOp_DayOfYear::operate(const ORowSetValue
& lhs
) const
94 ::com::sun::star::util::Date aD
= lhs
;
95 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
96 return static_cast<sal_Int16
>(aDate
.GetDayOfYear());
98 //------------------------------------------------------------------
99 ORowSetValue
OOp_Month::operate(const ORowSetValue
& lhs
) const
104 ::com::sun::star::util::Date aD
= lhs
;
105 return static_cast<sal_Int16
>(aD
.Month
);
107 //------------------------------------------------------------------
108 ORowSetValue
OOp_DayName::operate(const ORowSetValue
& lhs
) const
113 ::rtl::OUString sRet
;
114 ::com::sun::star::util::Date aD
= lhs
;
115 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
116 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
120 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Monday"));
123 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tuesday"));
126 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wednesday"));
129 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thursday"));
132 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Friday"));
135 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Saturday"));
138 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Sunday"));
141 OSL_ENSURE(0,"Error in enum values for date");
145 //------------------------------------------------------------------
146 ORowSetValue
OOp_MonthName::operate(const ORowSetValue
& lhs
) const
151 ::rtl::OUString sRet
;
152 ::com::sun::star::util::Date aD
= lhs
;
156 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("January"));
159 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("February"));
162 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("March"));
165 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("April"));
168 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("May"));
171 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("June"));
174 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("July"));
177 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("August"));
180 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("September"));
183 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("October"));
186 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("November"));
189 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("December"));
194 //------------------------------------------------------------------
195 ORowSetValue
OOp_Quarter::operate(const ORowSetValue
& lhs
) const
201 ::com::sun::star::util::Date aD
= lhs
;
202 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
203 if ( aD
.Month
>= 4 && aD
.Month
< 7 )
205 else if ( aD
.Month
>= 7 && aD
.Month
< 10 )
207 else if ( aD
.Month
>= 10 && aD
.Month
<= 12 )
211 //------------------------------------------------------------------
212 ORowSetValue
OOp_Week::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
214 if ( lhs
.empty() || lhs
.size() > 2 )
215 return ORowSetValue();
217 size_t nSize
= lhs
.size();
219 ::com::sun::star::util::Date aD
= lhs
[nSize
-1];
220 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
222 sal_Int16 nStartDay
= SUNDAY
;
223 if ( nSize
== 2 && !lhs
[0].isNull() )
226 return static_cast<sal_Int16
>(aDate
.GetWeekOfYear(static_cast<DayOfWeek
>(nStartDay
)));
228 // -----------------------------------------------------------------------------
229 ORowSetValue
OOp_Year::operate(const ORowSetValue
& lhs
) const
234 ::com::sun::star::util::Date aD
= lhs
;
235 return static_cast<sal_Int16
>(aD
.Year
);
237 //------------------------------------------------------------------
238 ORowSetValue
OOp_Hour::operate(const ORowSetValue
& lhs
) const
243 ::com::sun::star::util::Time aT
= lhs
;
244 return static_cast<sal_Int16
>(aT
.Hours
);
246 //------------------------------------------------------------------
247 ORowSetValue
OOp_Minute::operate(const ORowSetValue
& lhs
) const
252 ::com::sun::star::util::Time aT
= lhs
;
253 return static_cast<sal_Int16
>(aT
.Minutes
);
255 //------------------------------------------------------------------
256 ORowSetValue
OOp_Second::operate(const ORowSetValue
& lhs
) const
261 ::com::sun::star::util::Time aT
= lhs
;
262 return static_cast<sal_Int16
>(aT
.Seconds
);
264 //------------------------------------------------------------------
265 ORowSetValue
OOp_CurDate::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
268 return ORowSetValue();
271 return ::com::sun::star::util::Date(aCurDate
.GetDay(),aCurDate
.GetMonth(),aCurDate
.GetYear());
273 //------------------------------------------------------------------
274 ORowSetValue
OOp_CurTime::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
277 return ORowSetValue();
280 return ::com::sun::star::util::Time(aCurTime
.Get100Sec(),aCurTime
.GetSec(),aCurTime
.GetMin(),aCurTime
.GetHour());
282 //------------------------------------------------------------------
283 ORowSetValue
OOp_Now::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
286 return ORowSetValue();
289 return ::com::sun::star::util::DateTime(aCurTime
.Get100Sec(),aCurTime
.GetSec(),aCurTime
.GetMin(),aCurTime
.GetHour(),
290 aCurTime
.GetDay(),aCurTime
.GetMonth(),aCurTime
.GetYear());
292 //------------------------------------------------------------------