2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FUiCtrl_DateTimeUtils.cpp
20 * @brief This is the implementation file for the _DateTimeUtils class.
23 #include <FBaseDateTime.h>
24 #include <FLclDateTimeSymbols.h>
25 #include <FLclLocaleManager.h>
26 #include <FLclDateTimeFormatter.h>
27 #include <FSysSettingInfo.h>
28 #include "FUiCtrl_DateTimeUtils.h"
29 #include "FUiCtrl_DateTimeDefine.h"
30 #include "FUi_ResourceManager.h"
32 using namespace Tizen::Base;
33 using namespace Tizen::Locales;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::System;
37 namespace Tizen { namespace Ui { namespace Controls
40 _DateTimeUtils::~_DateTimeUtils(void)
44 _DateTimeUtils::_DateTimeUtils(void)
49 _DateTimeUtils::GetMonthString(int month) const
55 DateTimeSymbols dateSymbols;
56 r = dateSymbols.Construct(CALENDAR_GREGORIAN);
60 text.Append(GetEnglishMonthString(month));
64 const IList* pListOfShortMonths = dateSymbols.GetShortMonths();
65 SysTryReturn(NID_UI_CTRL, (pListOfShortMonths != null), text, E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfShortMonths is null.");
68 pObj = static_cast<String*>(const_cast<Object*>(pListOfShortMonths->GetAt(month - 1)));
79 _DateTimeUtils::GetEnglishMonthString(int month) const
140 _DateTimeUtils::CalculateMaxDay(int displayYear, int month) const
162 if (IsLeapYear(displayYear))
180 _DateTimeUtils::IsLeapYear(int year) const
182 return DateTime::IsLeapYear(year);
186 _DateTimeUtils::GetAmPm(String& timeFormat, _AmPmType amPmType) const
188 result r = E_SUCCESS;
189 DateTimeSymbols dateSymbols;
191 r = dateSymbols.Construct(CALENDAR_GREGORIAN);
195 if (amPmType == AM_TYPE)
197 timeFormat.Append("AM");
201 timeFormat.Append("PM");
206 const IList* pListOfAmPm = dateSymbols.GetAmPm();
207 SysTryReturnVoidResult(NID_UI_CTRL, (pListOfAmPm != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfAmPm is null.");
210 pObj = static_cast<String*>(const_cast<Object*>(pListOfAmPm->GetAt(amPmType)));
214 timeFormat.Append(*pObj);
221 _DateTimeUtils::GetFullMonthString(int month) const
226 DateTimeSymbols dateSymbols;
227 dateSymbols.Construct(CALENDAR_GREGORIAN);
229 const IList* pListOfFullMonths = dateSymbols.GetMonths();
230 SysTryReturn(NID_LCL, (pListOfFullMonths != null), text, E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfFullMonths is null.");
233 pObj = static_cast<String*>(const_cast<Object*>(pListOfFullMonths->GetAt(month - 1)));
244 _DateTimeUtils::GetLocaleDateFormat(void) const
246 result r = E_SUCCESS;
248 LocaleManager localeManager;
249 int localeDateFormat = 0;
251 r = localeManager.Construct();
252 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, localeDateFormat, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
254 Locale systemLocale = localeManager.GetSystemLocale();
256 DateTimeFormatter* pDateFormatter = DateTimeFormatter::CreateDateFormatterN(systemLocale, DATE_TIME_STYLE_LONG);
258 SysTryReturn(NID_UI_CTRL, pDateFormatter != null, localeDateFormat, r, "[%s] Propagating.", GetErrorMessage(r));
260 String formatString = pDateFormatter->GetPattern();
261 formatString.ToLowerCase();
263 delete pDateFormatter;
264 pDateFormatter = null;
266 int stringLength = formatString.GetLength();
267 String parsedString = L"";
269 for (int i = 0; i < stringLength; i++)
272 r = formatString.GetCharAt(i, ch);
273 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, localeDateFormat, r, "[%s] Propagating.", GetErrorMessage(r));
275 if (ch == 'd' && !parsedString.Contains(L"DD"))
277 parsedString.Append(L"DD");
279 else if (ch == 'm' && !parsedString.Contains(L"MM"))
281 parsedString.Append(L"MM");
283 else if (ch == 'y' && !parsedString.Contains(L"YYYY"))
285 parsedString.Append(L"YYYY");
288 if (parsedString.GetLength() == LOCALE_DATE_FORMAT_STRING_LENGTH)
294 if (parsedString.Equals(L"DDMMYYYY", false))
296 localeDateFormat = DATE_FORMAT_DDMMYYYY;
298 else if (parsedString.Equals(L"MMDDYYYY", false))
300 localeDateFormat = DATE_FORMAT_MMDDYYYY;
302 else if (parsedString.Equals(L"YYYYMMDD", false))
304 localeDateFormat = DATE_FORMAT_YYYYMMDD;
306 else if (parsedString.Equals(L"YYYYDDMM", false))
308 localeDateFormat = DATE_FORMAT_YYYYDDMM;
311 return localeDateFormat;
314 }}} // Tizen::Ui::Controls