/src/libreoffice/connectivity/source/drivers/file/FDateFunctions.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
25 | | |
26 | | using namespace connectivity; |
27 | | using namespace connectivity::file; |
28 | | |
29 | | ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const |
30 | 0 | { |
31 | 0 | if (lhs.isNull()) |
32 | 0 | return lhs; |
33 | | |
34 | 0 | sal_Int32 nRet = 0; |
35 | 0 | css::util::Date aD = lhs.getDate(); |
36 | 0 | Date aDate(aD.Day, aD.Month, aD.Year); |
37 | 0 | DayOfWeek eDayOfWeek = aDate.GetDayOfWeek(); |
38 | 0 | switch (eDayOfWeek) |
39 | 0 | { |
40 | 0 | case MONDAY: |
41 | 0 | nRet = 2; |
42 | 0 | break; |
43 | 0 | case TUESDAY: |
44 | 0 | nRet = 3; |
45 | 0 | break; |
46 | 0 | case WEDNESDAY: |
47 | 0 | nRet = 4; |
48 | 0 | break; |
49 | 0 | case THURSDAY: |
50 | 0 | nRet = 5; |
51 | 0 | break; |
52 | 0 | case FRIDAY: |
53 | 0 | nRet = 6; |
54 | 0 | break; |
55 | 0 | case SATURDAY: |
56 | 0 | nRet = 7; |
57 | 0 | break; |
58 | 0 | case SUNDAY: |
59 | 0 | nRet = 1; |
60 | 0 | break; |
61 | 0 | default: |
62 | 0 | OSL_FAIL("Error in enum values for date"); |
63 | 0 | } |
64 | 0 | return nRet; |
65 | 0 | } |
66 | | |
67 | | ORowSetValue OOp_DayOfMonth::operate(const ORowSetValue& lhs) const |
68 | 0 | { |
69 | 0 | if (lhs.isNull()) |
70 | 0 | return lhs; |
71 | | |
72 | 0 | css::util::Date aD = lhs.getDate(); |
73 | 0 | return static_cast<sal_Int16>(aD.Day); |
74 | 0 | } |
75 | | |
76 | | ORowSetValue OOp_DayOfYear::operate(const ORowSetValue& lhs) const |
77 | 0 | { |
78 | 0 | if (lhs.isNull()) |
79 | 0 | return lhs; |
80 | | |
81 | 0 | css::util::Date aD = lhs.getDate(); |
82 | 0 | Date aDate(aD.Day, aD.Month, aD.Year); |
83 | 0 | return static_cast<sal_Int16>(aDate.GetDayOfYear()); |
84 | 0 | } |
85 | | |
86 | | ORowSetValue OOp_Month::operate(const ORowSetValue& lhs) const |
87 | 0 | { |
88 | 0 | if (lhs.isNull()) |
89 | 0 | return lhs; |
90 | | |
91 | 0 | css::util::Date aD = lhs.getDate(); |
92 | 0 | return static_cast<sal_Int16>(aD.Month); |
93 | 0 | } |
94 | | |
95 | | ORowSetValue OOp_DayName::operate(const ORowSetValue& lhs) const |
96 | 0 | { |
97 | 0 | if (lhs.isNull()) |
98 | 0 | return lhs; |
99 | | |
100 | 0 | OUString sRet; |
101 | 0 | css::util::Date aD = lhs.getDate(); |
102 | 0 | Date aDate(aD.Day, aD.Month, aD.Year); |
103 | 0 | DayOfWeek eDayOfWeek = aDate.GetDayOfWeek(); |
104 | 0 | switch (eDayOfWeek) |
105 | 0 | { |
106 | 0 | case MONDAY: |
107 | 0 | sRet = "Monday"; |
108 | 0 | break; |
109 | 0 | case TUESDAY: |
110 | 0 | sRet = "Tuesday"; |
111 | 0 | break; |
112 | 0 | case WEDNESDAY: |
113 | 0 | sRet = "Wednesday"; |
114 | 0 | break; |
115 | 0 | case THURSDAY: |
116 | 0 | sRet = "Thursday"; |
117 | 0 | break; |
118 | 0 | case FRIDAY: |
119 | 0 | sRet = "Friday"; |
120 | 0 | break; |
121 | 0 | case SATURDAY: |
122 | 0 | sRet = "Saturday"; |
123 | 0 | break; |
124 | 0 | case SUNDAY: |
125 | 0 | sRet = "Sunday"; |
126 | 0 | break; |
127 | 0 | default: |
128 | 0 | OSL_FAIL("Error in enum values for date"); |
129 | 0 | } |
130 | 0 | return sRet; |
131 | 0 | } |
132 | | |
133 | | ORowSetValue OOp_MonthName::operate(const ORowSetValue& lhs) const |
134 | 0 | { |
135 | 0 | if (lhs.isNull()) |
136 | 0 | return lhs; |
137 | | |
138 | 0 | OUString sRet; |
139 | 0 | css::util::Date aD = lhs.getDate(); |
140 | 0 | switch (aD.Month) |
141 | 0 | { |
142 | 0 | case 1: |
143 | 0 | sRet = "January"; |
144 | 0 | break; |
145 | 0 | case 2: |
146 | 0 | sRet = "February"; |
147 | 0 | break; |
148 | 0 | case 3: |
149 | 0 | sRet = "March"; |
150 | 0 | break; |
151 | 0 | case 4: |
152 | 0 | sRet = "April"; |
153 | 0 | break; |
154 | 0 | case 5: |
155 | 0 | sRet = "May"; |
156 | 0 | break; |
157 | 0 | case 6: |
158 | 0 | sRet = "June"; |
159 | 0 | break; |
160 | 0 | case 7: |
161 | 0 | sRet = "July"; |
162 | 0 | break; |
163 | 0 | case 8: |
164 | 0 | sRet = "August"; |
165 | 0 | break; |
166 | 0 | case 9: |
167 | 0 | sRet = "September"; |
168 | 0 | break; |
169 | 0 | case 10: |
170 | 0 | sRet = "October"; |
171 | 0 | break; |
172 | 0 | case 11: |
173 | 0 | sRet = "November"; |
174 | 0 | break; |
175 | 0 | case 12: |
176 | 0 | sRet = "December"; |
177 | 0 | break; |
178 | 0 | } |
179 | 0 | return sRet; |
180 | 0 | } |
181 | | |
182 | | ORowSetValue OOp_Quarter::operate(const ORowSetValue& lhs) const |
183 | 0 | { |
184 | 0 | if (lhs.isNull()) |
185 | 0 | return lhs; |
186 | | |
187 | 0 | sal_Int32 nRet = 1; |
188 | 0 | css::util::Date aD = lhs.getDate(); |
189 | 0 | if (aD.Month >= 4 && aD.Month < 7) |
190 | 0 | nRet = 2; |
191 | 0 | else if (aD.Month >= 7 && aD.Month < 10) |
192 | 0 | nRet = 3; |
193 | 0 | else if (aD.Month >= 10 && aD.Month <= 12) |
194 | 0 | nRet = 4; |
195 | 0 | return nRet; |
196 | 0 | } |
197 | | |
198 | | ORowSetValue OOp_Week::operate(const std::vector<ORowSetValue>& lhs) const |
199 | 0 | { |
200 | 0 | if (lhs.empty() || lhs.size() > 2) |
201 | 0 | return ORowSetValue(); |
202 | | |
203 | 0 | size_t nSize = lhs.size(); |
204 | |
|
205 | 0 | css::util::Date aD = lhs[nSize - 1].getDate(); |
206 | 0 | Date aDate(aD.Day, aD.Month, aD.Year); |
207 | |
|
208 | 0 | sal_Int16 nStartDay = SUNDAY; |
209 | 0 | if (nSize == 2 && !lhs[0].isNull()) |
210 | 0 | nStartDay = lhs[0].getInt16(); |
211 | |
|
212 | 0 | return static_cast<sal_Int16>(aDate.GetWeekOfYear(static_cast<DayOfWeek>(nStartDay))); |
213 | 0 | } |
214 | | |
215 | | ORowSetValue OOp_Year::operate(const ORowSetValue& lhs) const |
216 | 0 | { |
217 | 0 | if (lhs.isNull()) |
218 | 0 | return lhs; |
219 | | |
220 | 0 | css::util::Date aD = lhs.getDate(); |
221 | 0 | return aD.Year; |
222 | 0 | } |
223 | | |
224 | | ORowSetValue OOp_Hour::operate(const ORowSetValue& lhs) const |
225 | 0 | { |
226 | 0 | if (lhs.isNull()) |
227 | 0 | return lhs; |
228 | | |
229 | 0 | css::util::Time aT = lhs.getTime(); |
230 | 0 | return static_cast<sal_Int16>(aT.Hours); |
231 | 0 | } |
232 | | |
233 | | ORowSetValue OOp_Minute::operate(const ORowSetValue& lhs) const |
234 | 0 | { |
235 | 0 | if (lhs.isNull()) |
236 | 0 | return lhs; |
237 | | |
238 | 0 | css::util::Time aT = lhs.getTime(); |
239 | 0 | return static_cast<sal_Int16>(aT.Minutes); |
240 | 0 | } |
241 | | |
242 | | ORowSetValue OOp_Second::operate(const ORowSetValue& lhs) const |
243 | 0 | { |
244 | 0 | if (lhs.isNull()) |
245 | 0 | return lhs; |
246 | | |
247 | 0 | css::util::Time aT = lhs.getTime(); |
248 | 0 | return static_cast<sal_Int16>(aT.Seconds); |
249 | 0 | } |
250 | | |
251 | | ORowSetValue OOp_CurDate::operate(const std::vector<ORowSetValue>& lhs) const |
252 | 0 | { |
253 | 0 | if (!lhs.empty()) |
254 | 0 | return ORowSetValue(); |
255 | | |
256 | 0 | Date aCurDate(Date::SYSTEM); |
257 | 0 | return aCurDate.GetUNODate(); |
258 | 0 | } |
259 | | |
260 | | ORowSetValue OOp_CurTime::operate(const std::vector<ORowSetValue>& lhs) const |
261 | 0 | { |
262 | 0 | if (!lhs.empty()) |
263 | 0 | return ORowSetValue(); |
264 | | |
265 | 0 | tools::Time aCurTime(tools::Time::SYSTEM); |
266 | 0 | return aCurTime.GetUNOTime(); |
267 | 0 | } |
268 | | |
269 | | ORowSetValue OOp_Now::operate(const std::vector<ORowSetValue>& lhs) const |
270 | 0 | { |
271 | 0 | if (!lhs.empty()) |
272 | 0 | return ORowSetValue(); |
273 | | |
274 | 0 | DateTime aCurTime(DateTime::SYSTEM); |
275 | 0 | return aCurTime.GetUNODateTime(); |
276 | 0 | } |
277 | | |
278 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |