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