LibreOffice Module connectivity (master) 1
FDateFunctions.cxx
Go to the documentation of this file.
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
21#include <tools/date.hxx>
22#include <tools/time.hxx>
23#include <tools/datetime.hxx>
24#include <osl/diagnose.h>
25
26using namespace connectivity;
27using namespace connectivity::file;
28
29ORowSetValue OOp_DayOfWeek::operate(const ORowSetValue& lhs) const
30{
31 if (lhs.isNull())
32 return lhs;
33
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)
39 {
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");
63 }
64 return nRet;
65}
66
68{
69 if (lhs.isNull())
70 return lhs;
71
72 css::util::Date aD = lhs.getDate();
73 return static_cast<sal_Int16>(aD.Day);
74}
75
77{
78 if (lhs.isNull())
79 return lhs;
80
81 css::util::Date aD = lhs.getDate();
82 Date aDate(aD.Day, aD.Month, aD.Year);
83 return static_cast<sal_Int16>(aDate.GetDayOfYear());
84}
85
87{
88 if (lhs.isNull())
89 return lhs;
90
91 css::util::Date aD = lhs.getDate();
92 return static_cast<sal_Int16>(aD.Month);
93}
94
96{
97 if (lhs.isNull())
98 return lhs;
99
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)
105 {
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");
129 }
130 return sRet;
131}
132
134{
135 if (lhs.isNull())
136 return lhs;
137
138 OUString sRet;
139 css::util::Date aD = lhs.getDate();
140 switch (aD.Month)
141 {
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;
178 }
179 return sRet;
180}
181
183{
184 if (lhs.isNull())
185 return lhs;
186
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;
196}
197
198ORowSetValue OOp_Week::operate(const std::vector<ORowSetValue>& lhs) const
199{
200 if (lhs.empty() || lhs.size() > 2)
201 return ORowSetValue();
202
203 size_t nSize = lhs.size();
204
205 css::util::Date aD = lhs[nSize - 1].getDate();
206 Date aDate(aD.Day, aD.Month, aD.Year);
207
208 sal_Int16 nStartDay = SUNDAY;
209 if (nSize == 2 && !lhs[0].isNull())
210 nStartDay = lhs[0].getInt16();
211
212 return static_cast<sal_Int16>(aDate.GetWeekOfYear(static_cast<DayOfWeek>(nStartDay)));
213}
214
216{
217 if (lhs.isNull())
218 return lhs;
219
220 css::util::Date aD = lhs.getDate();
221 return aD.Year;
222}
223
225{
226 if (lhs.isNull())
227 return lhs;
228
229 css::util::Time aT = lhs.getTime();
230 return static_cast<sal_Int16>(aT.Hours);
231}
232
234{
235 if (lhs.isNull())
236 return lhs;
237
238 css::util::Time aT = lhs.getTime();
239 return static_cast<sal_Int16>(aT.Minutes);
240}
241
243{
244 if (lhs.isNull())
245 return lhs;
246
247 css::util::Time aT = lhs.getTime();
248 return static_cast<sal_Int16>(aT.Seconds);
249}
250
251ORowSetValue OOp_CurDate::operate(const std::vector<ORowSetValue>& lhs) const
252{
253 if (!lhs.empty())
254 return ORowSetValue();
255
256 Date aCurDate(Date::SYSTEM);
257 return aCurDate.GetUNODate();
258}
259
260ORowSetValue OOp_CurTime::operate(const std::vector<ORowSetValue>& lhs) const
261{
262 if (!lhs.empty())
263 return ORowSetValue();
264
266 return aCurTime.GetUNOTime();
267}
268
269ORowSetValue OOp_Now::operate(const std::vector<ORowSetValue>& lhs) const
270{
271 if (!lhs.empty())
272 return ORowSetValue();
273
274 DateTime aCurTime(DateTime::SYSTEM);
275 return aCurTime.GetUNODateTime();
276}
277
278/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::util::DateTime GetUNODateTime() const
sal_uInt16 GetDayOfYear() const
sal_uInt16 GetWeekOfYear(DayOfWeek eStartDay=MONDAY, sal_Int16 nMinimumNumberOfDaysInWeek=4) const
css::util::Date GetUNODate() const
DayOfWeek GetDayOfWeek() const
css::util::Time getTime() const
Definition: FValue.cxx:1951
css::util::Date getDate() const
Definition: FValue.cxx:1893
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
virtual ORowSetValue operate(const std::vector< ORowSetValue > &lhs) const override
virtual ORowSetValue operate(const ORowSetValue &lhs) const override
css::util::Time GetUNOTime() const
DayOfWeek
SATURDAY
TUESDAY
WEDNESDAY
FRIDAY
THURSDAY
MONDAY
SUNDAY