1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "file/FDateFunctions.hxx"
22 #include <tools/date.hxx>
23 #include <tools/time.hxx>
24 #include <tools/datetime.hxx>
26 using namespace connectivity
;
27 using namespace connectivity::file
;
29 ORowSetValue
OOp_DayOfWeek::operate(const ORowSetValue
& lhs
) const
35 ::com::sun::star::util::Date aD
= lhs
;
36 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
37 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
62 OSL_FAIL("Error in enum values for date");
67 ORowSetValue
OOp_DayOfMonth::operate(const ORowSetValue
& lhs
) const
72 ::com::sun::star::util::Date aD
= lhs
;
73 return static_cast<sal_Int16
>(aD
.Day
);
76 ORowSetValue
OOp_DayOfYear::operate(const ORowSetValue
& lhs
) const
81 ::com::sun::star::util::Date aD
= lhs
;
82 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
83 return static_cast<sal_Int16
>(aDate
.GetDayOfYear());
86 ORowSetValue
OOp_Month::operate(const ORowSetValue
& lhs
) const
91 ::com::sun::star::util::Date aD
= lhs
;
92 return static_cast<sal_Int16
>(aD
.Month
);
95 ORowSetValue
OOp_DayName::operate(const ORowSetValue
& lhs
) const
101 ::com::sun::star::util::Date aD
= lhs
;
102 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
103 DayOfWeek eDayOfWeek
= aDate
.GetDayOfWeek();
128 OSL_FAIL("Error in enum values for date");
133 ORowSetValue
OOp_MonthName::operate(const ORowSetValue
& lhs
) const
139 ::com::sun::star::util::Date aD
= lhs
;
182 ORowSetValue
OOp_Quarter::operate(const ORowSetValue
& lhs
) const
188 ::com::sun::star::util::Date aD
= lhs
;
189 if ( aD
.Month
>= 4 && aD
.Month
< 7 )
191 else if ( aD
.Month
>= 7 && aD
.Month
< 10 )
193 else if ( aD
.Month
>= 10 && aD
.Month
<= 12 )
198 ORowSetValue
OOp_Week::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
200 if ( lhs
.empty() || lhs
.size() > 2 )
201 return ORowSetValue();
203 size_t nSize
= lhs
.size();
205 ::com::sun::star::util::Date aD
= lhs
[nSize
-1];
206 Date
aDate(aD
.Day
,aD
.Month
,aD
.Year
);
208 sal_Int16 nStartDay
= SUNDAY
;
209 if ( nSize
== 2 && !lhs
[0].isNull() )
212 return static_cast<sal_Int16
>(aDate
.GetWeekOfYear(static_cast<DayOfWeek
>(nStartDay
)));
215 ORowSetValue
OOp_Year::operate(const ORowSetValue
& lhs
) const
220 ::com::sun::star::util::Date aD
= lhs
;
221 return static_cast<sal_Int16
>(aD
.Year
);
224 ORowSetValue
OOp_Hour::operate(const ORowSetValue
& lhs
) const
229 ::com::sun::star::util::Time aT
= lhs
;
230 return static_cast<sal_Int16
>(aT
.Hours
);
233 ORowSetValue
OOp_Minute::operate(const ORowSetValue
& lhs
) const
238 ::com::sun::star::util::Time aT
= lhs
;
239 return static_cast<sal_Int16
>(aT
.Minutes
);
242 ORowSetValue
OOp_Second::operate(const ORowSetValue
& lhs
) const
247 ::com::sun::star::util::Time aT
= lhs
;
248 return static_cast<sal_Int16
>(aT
.Seconds
);
251 ORowSetValue
OOp_CurDate::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
254 return ORowSetValue();
256 Date
aCurDate( Date::SYSTEM
);
257 return ::com::sun::star::util::Date(aCurDate
.GetDay(),aCurDate
.GetMonth(),aCurDate
.GetYear());
260 ORowSetValue
OOp_CurTime::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
263 return ORowSetValue();
265 Time
aCurTime( Time::SYSTEM
);
266 return ::com::sun::star::util::Time(aCurTime
.GetNanoSec(),
267 aCurTime
.GetSec(), aCurTime
.GetMin(), aCurTime
.GetHour(),
271 ORowSetValue
OOp_Now::operate(const ::std::vector
<ORowSetValue
>& lhs
) const
274 return ORowSetValue();
276 DateTime
aCurTime( DateTime::SYSTEM
);
277 return ::com::sun::star::util::DateTime(aCurTime
.GetNanoSec(),
278 aCurTime
.GetSec(), aCurTime
.GetMin(), aCurTime
.GetHour(),
279 aCurTime
.GetDay(), aCurTime
.GetMonth(), aCurTime
.GetYear(),
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */