tdf#150789 - FILEOPEN PPTX: fix text in SmartArt vertically off
[LibreOffice.git] / connectivity / source / drivers / file / FDateFunctions.cxx
blob1be992d4b6724b917995ccece7a135f4408cb14e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
31 if (lhs.isNull())
32 return lhs;
34 sal_Int32 nRet = 0;
35 css::util::Date aD = lhs.getDate();
36 Date aDate(aD.Day, aD.Month, aD.Year);
37 DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
38 switch (eDayOfWeek)
40 case MONDAY:
41 nRet = 2;
42 break;
43 case TUESDAY:
44 nRet = 3;
45 break;
46 case WEDNESDAY:
47 nRet = 4;
48 break;
49 case THURSDAY:
50 nRet = 5;
51 break;
52 case FRIDAY:
53 nRet = 6;
54 break;
55 case SATURDAY:
56 nRet = 7;
57 break;
58 case SUNDAY:
59 nRet = 1;
60 break;
61 default:
62 OSL_FAIL("Error in enum values for date");
64 return nRet;
67 ORowSetValue OOp_DayOfMonth::operate(const ORowSetValue& lhs) const
69 if (lhs.isNull())
70 return lhs;
72 css::util::Date aD = lhs.getDate();
73 return static_cast<sal_Int16>(aD.Day);
76 ORowSetValue OOp_DayOfYear::operate(const ORowSetValue& lhs) const
78 if (lhs.isNull())
79 return lhs;
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
88 if (lhs.isNull())
89 return lhs;
91 css::util::Date aD = lhs.getDate();
92 return static_cast<sal_Int16>(aD.Month);
95 ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const
97 if (lhs.isNull())
98 return lhs;
100 OUString sRet;
101 css::util::Date aD = lhs.getDate();
102 Date aDate(aD.Day, aD.Month, aD.Year);
103 DayOfWeek eDayOfWeek = aDate.GetDayOfWeek();
104 switch (eDayOfWeek)
106 case MONDAY:
107 sRet = "Monday";
108 break;
109 case TUESDAY:
110 sRet = "Tuesday";
111 break;
112 case WEDNESDAY:
113 sRet = "Wednesday";
114 break;
115 case THURSDAY:
116 sRet = "Thursday";
117 break;
118 case FRIDAY:
119 sRet = "Friday";
120 break;
121 case SATURDAY:
122 sRet = "Saturday";
123 break;
124 case SUNDAY:
125 sRet = "Sunday";
126 break;
127 default:
128 OSL_FAIL("Error in enum values for date");
130 return sRet;
133 ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const
135 if (lhs.isNull())
136 return lhs;
138 OUString sRet;
139 css::util::Date aD = lhs.getDate();
140 switch (aD.Month)
142 case 1:
143 sRet = "January";
144 break;
145 case 2:
146 sRet = "February";
147 break;
148 case 3:
149 sRet = "March";
150 break;
151 case 4:
152 sRet = "April";
153 break;
154 case 5:
155 sRet = "May";
156 break;
157 case 6:
158 sRet = "June";
159 break;
160 case 7:
161 sRet = "July";
162 break;
163 case 8:
164 sRet = "August";
165 break;
166 case 9:
167 sRet = "September";
168 break;
169 case 10:
170 sRet = "October";
171 break;
172 case 11:
173 sRet = "November";
174 break;
175 case 12:
176 sRet = "December";
177 break;
179 return sRet;
182 ORowSetValue OOp_Quarter::operate(const ORowSetValue& lhs) const
184 if (lhs.isNull())
185 return lhs;
187 sal_Int32 nRet = 1;
188 css::util::Date aD = lhs.getDate();
189 if (aD.Month >= 4 && aD.Month < 7)
190 nRet = 2;
191 else if (aD.Month >= 7 && aD.Month < 10)
192 nRet = 3;
193 else if (aD.Month >= 10 && aD.Month <= 12)
194 nRet = 4;
195 return nRet;
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
217 if (lhs.isNull())
218 return lhs;
220 css::util::Date aD = lhs.getDate();
221 return aD.Year;
224 ORowSetValue OOp_Hour::operate(const ORowSetValue& lhs) const
226 if (lhs.isNull())
227 return lhs;
229 css::util::Time aT = lhs.getTime();
230 return static_cast<sal_Int16>(aT.Hours);
233 ORowSetValue OOp_Minute::operate(const ORowSetValue& lhs) const
235 if (lhs.isNull())
236 return lhs;
238 css::util::Time aT = lhs.getTime();
239 return static_cast<sal_Int16>(aT.Minutes);
242 ORowSetValue OOp_Second::operate(const ORowSetValue& lhs) const
244 if (lhs.isNull())
245 return lhs;
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
253 if (!lhs.empty())
254 return ORowSetValue();
256 Date aCurDate(Date::SYSTEM);
257 return aCurDate.GetUNODate();
260 ORowSetValue OOp_CurTime::operate(const std::vector<ORowSetValue>& lhs) const
262 if (!lhs.empty())
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
271 if (!lhs.empty())
272 return ORowSetValue();
274 DateTime aCurTime(DateTime::SYSTEM);
275 return aCurTime.GetUNODateTime();
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */