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 .
20 #include <file/FDateFunctions.hxx>
21 #include <tools/date.hxx>
22 #include <tools/time.hxx>
23 #include <tools/datetime.hxx>
24 #include <osl/diagnose.h>
26 using namespace connectivity
;
27 using namespace connectivity::file
;
29 ORowSetValue
OOp_DayOfWeek::operate(const ORowSetValue
& lhs
) const
35 css::util::Date aD
= lhs
.getDate();
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 css::util::Date aD
= lhs
.getDate();
73 return static_cast<sal_Int16
>(aD
.Day
);
76 ORowSetValue
OOp_DayOfYear::operate(const ORowSetValue
& lhs
) const
81 css::util::Date aD
= lhs
.getDate();
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 css::util::Date aD
= lhs
.getDate();
92 return static_cast<sal_Int16
>(aD
.Month
);
95 ORowSetValue
OOp_DayName::operate(const ORowSetValue
& lhs
) const
101 css::util::Date aD
= lhs
.getDate();
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 css::util::Date aD
= lhs
.getDate();
182 ORowSetValue
OOp_Quarter::operate(const ORowSetValue
& lhs
) const
188 css::util::Date aD
= lhs
.getDate();
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 css::util::Date aD
= lhs
[nSize
- 1].getDate();
206 Date
aDate(aD
.Day
, aD
.Month
, aD
.Year
);
208 sal_Int16 nStartDay
= SUNDAY
;
209 if (nSize
== 2 && !lhs
[0].isNull())
210 nStartDay
= lhs
[0].getInt16();
212 return static_cast<sal_Int16
>(aDate
.GetWeekOfYear(static_cast<DayOfWeek
>(nStartDay
)));
215 ORowSetValue
OOp_Year::operate(const ORowSetValue
& lhs
) const
220 css::util::Date aD
= lhs
.getDate();
224 ORowSetValue
OOp_Hour::operate(const ORowSetValue
& lhs
) const
229 css::util::Time aT
= lhs
.getTime();
230 return static_cast<sal_Int16
>(aT
.Hours
);
233 ORowSetValue
OOp_Minute::operate(const ORowSetValue
& lhs
) const
238 css::util::Time aT
= lhs
.getTime();
239 return static_cast<sal_Int16
>(aT
.Minutes
);
242 ORowSetValue
OOp_Second::operate(const ORowSetValue
& lhs
) const
247 css::util::Time aT
= lhs
.getTime();
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 aCurDate
.GetUNODate();
260 ORowSetValue
OOp_CurTime::operate(const std::vector
<ORowSetValue
>& lhs
) const
263 return ORowSetValue();
265 tools::Time
aCurTime(tools::Time::SYSTEM
);
266 return aCurTime
.GetUNOTime();
269 ORowSetValue
OOp_Now::operate(const std::vector
<ORowSetValue
>& lhs
) const
272 return ORowSetValue();
274 DateTime
aCurTime(DateTime::SYSTEM
);
275 return aCurTime
.GetUNODateTime();
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */