1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "file/FDateFunctions.hxx"
31 #include <tools/date.hxx>
32 #include <tools/time.hxx>
33 #include <tools/datetime.hxx>
35 using namespace connectivity
;
36 using namespace connectivity::file
;
37 //------------------------------------------------------------------
38 ORowSetValue
OOp_DayOfWeek::operate(const ORowSetValue
& lhs
) const
44 ::com::sun::star::util::Date aD
= lhs
;
45 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
46 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
71 OSL_FAIL("Error in enum values for date");
75 //------------------------------------------------------------------
76 ORowSetValue
OOp_DayOfMonth::operate(const ORowSetValue
& lhs
) const
81 ::com::sun::star::util::Date aD
= lhs
;
82 return static_cast<sal_Int16
>(aD
.Day
);
84 //------------------------------------------------------------------
85 ORowSetValue
OOp_DayOfYear::operate(const ORowSetValue
& lhs
) const
90 ::com::sun::star::util::Date aD
= lhs
;
91 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
92 return static_cast<sal_Int16
>(aDate
.GetDayOfYear());
94 //------------------------------------------------------------------
95 ORowSetValue
OOp_Month::operate(const ORowSetValue
& lhs
) const
100 ::com::sun::star::util::Date aD
= lhs
;
101 return static_cast<sal_Int16
>(aD
.Month
);
103 //------------------------------------------------------------------
104 ORowSetValue
OOp_DayName::operate(const ORowSetValue
& lhs
) const
109 ::rtl::OUString sRet
;
110 ::com::sun::star::util::Date aD
= lhs
;
111 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
112 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
116 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Monday"));
119 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tuesday"));
122 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Wednesday"));
125 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Thursday"));
128 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Friday"));
131 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Saturday"));
134 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Sunday"));
137 OSL_FAIL("Error in enum values for date");
141 //------------------------------------------------------------------
142 ORowSetValue
OOp_MonthName::operate(const ORowSetValue
& lhs
) const
147 ::rtl::OUString sRet
;
148 ::com::sun::star::util::Date aD
= lhs
;
152 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("January"));
155 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("February"));
158 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("March"));
161 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("April"));
164 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("May"));
167 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("June"));
170 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("July"));
173 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("August"));
176 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("September"));
179 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("October"));
182 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("November"));
185 sRet
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("December"));
190 //------------------------------------------------------------------
191 ORowSetValue
OOp_Quarter::operate(const ORowSetValue
& lhs
) const
197 ::com::sun::star::util::Date aD
= lhs
;
198 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
199 if ( aD
.Month
>= 4 && aD
.Month
< 7 )
201 else if ( aD
.Month
>= 7 && aD
.Month
< 10 )
203 else if ( aD
.Month
>= 10 && aD
.Month
<= 12 )
207 //------------------------------------------------------------------
208 ORowSetValue
OOp_Week::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
210 if ( lhs
.empty() || lhs
.size() > 2 )
211 return ORowSetValue();
213 size_t nSize
= lhs
.size();
215 ::com::sun::star::util::Date aD
= lhs
[nSize
-1];
216 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
218 sal_Int16 nStartDay
= SUNDAY
;
219 if ( nSize
== 2 && !lhs
[0].isNull() )
222 return static_cast<sal_Int16
>(aDate
.GetWeekOfYear(static_cast<DayOfWeek
>(nStartDay
)));
224 // -----------------------------------------------------------------------------
225 ORowSetValue
OOp_Year::operate(const ORowSetValue
& lhs
) const
230 ::com::sun::star::util::Date aD
= lhs
;
231 return static_cast<sal_Int16
>(aD
.Year
);
233 //------------------------------------------------------------------
234 ORowSetValue
OOp_Hour::operate(const ORowSetValue
& lhs
) const
239 ::com::sun::star::util::Time aT
= lhs
;
240 return static_cast<sal_Int16
>(aT
.Hours
);
242 //------------------------------------------------------------------
243 ORowSetValue
OOp_Minute::operate(const ORowSetValue
& lhs
) const
248 ::com::sun::star::util::Time aT
= lhs
;
249 return static_cast<sal_Int16
>(aT
.Minutes
);
251 //------------------------------------------------------------------
252 ORowSetValue
OOp_Second::operate(const ORowSetValue
& lhs
) const
257 ::com::sun::star::util::Time aT
= lhs
;
258 return static_cast<sal_Int16
>(aT
.Seconds
);
260 //------------------------------------------------------------------
261 ORowSetValue
OOp_CurDate::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
264 return ORowSetValue();
266 Date
aCurDate( Date::SYSTEM
);
267 return ::com::sun::star::util::Date(aCurDate
.GetDay(),aCurDate
.GetMonth(),aCurDate
.GetYear());
269 //------------------------------------------------------------------
270 ORowSetValue
OOp_CurTime::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
273 return ORowSetValue();
275 Time
aCurTime( Time::SYSTEM
);
276 return ::com::sun::star::util::Time(aCurTime
.Get100Sec(),aCurTime
.GetSec(),aCurTime
.GetMin(),aCurTime
.GetHour());
278 //------------------------------------------------------------------
279 ORowSetValue
OOp_Now::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
282 return ORowSetValue();
284 DateTime
aCurTime( DateTime::SYSTEM
);
285 return ::com::sun::star::util::DateTime(aCurTime
.Get100Sec(),aCurTime
.GetSec(),aCurTime
.GetMin(),aCurTime
.GetHour(),
286 aCurTime
.GetDay(),aCurTime
.GetMonth(),aCurTime
.GetYear());
288 //------------------------------------------------------------------
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */