912de49067cfd308ecc74d892391621695094fdb
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_DateTimeUtils.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
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.
16 //
17
18 /**
19  * @file                FUiCtrl_DateTimeUtils.cpp
20  * @brief               This is the implementation file for the _DateTimeUtils class.
21  */
22
23 #include <FBaseDateTime.h>
24 #include <FLclDateTimeSymbols.h>
25 #include "FUiCtrl_DateTimeUtils.h"
26 #include "FUi_ResourceManager.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Locales;
30 using namespace Tizen::Base::Collection;
31
32 namespace Tizen { namespace Ui { namespace Controls
33 {
34
35 _DateTimeUtils::~_DateTimeUtils(void)
36 {
37 }
38
39 _DateTimeUtils::_DateTimeUtils(void)
40 {
41 }
42
43 const String
44 _DateTimeUtils::GetMonthString(int month) const
45 {
46         String text;
47         text.Clear();
48
49         DateTimeSymbols dateSymbols;
50         dateSymbols.Construct(CALENDAR_GREGORIAN);
51
52         const IList* pListOfShortMonths = dateSymbols.GetShortMonths();
53         SysTryReturn(NID_LCL, (pListOfShortMonths != null), text, E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfShortMonths is null.");
54
55         String* pObj = null;
56         pObj = static_cast<String*>(const_cast<Object*>(pListOfShortMonths->GetAt(month - 1)));
57
58         if (pObj)
59         {
60                 text.Append(*pObj);
61         }
62
63         return text;
64 }
65
66 int
67 _DateTimeUtils::CalculateMaxDay(int displayYear, int month) const
68 {
69         int maxDay = 0;
70         switch (month)
71         {
72         case 1:
73                 // fall through
74         case 3:
75                 // fall through
76         case 5:
77                 // fall through
78         case 7:
79                 // fall through
80         case 8:
81                 // fall through
82         case 10:
83                 // fall through
84         case 12:
85                 maxDay = 31;
86                 break;
87
88         case 2:
89                 if (IsLeapYear(displayYear))
90                 {
91                         maxDay = 29;
92                 }
93                 else
94                 {
95                         maxDay = 28;
96                 }
97                 break;
98
99         default:
100                 maxDay = 30;
101                 break;
102         }
103         return maxDay;
104 }
105
106 bool
107 _DateTimeUtils::IsLeapYear(int year) const
108 {
109         return DateTime::IsLeapYear(year);
110 }
111
112 void
113 _DateTimeUtils::GetAmPm(String& timeFormat, _AmPmType amPmType) const
114 {
115         DateTimeSymbols dateSymbols;
116         dateSymbols.Construct(CALENDAR_GREGORIAN);
117
118         const IList* pListOfAmPm = dateSymbols.GetAmPm();
119         SysTryReturnVoidResult(NID_LCL, (pListOfAmPm != null), E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfAmPm is null.");
120
121         String* pObj = null;
122         pObj = static_cast<String*>(const_cast<Object*>(pListOfAmPm->GetAt(amPmType)));
123
124         if (pObj)
125         {
126                 timeFormat.Append(*pObj);
127         }
128
129         return;
130 }
131
132 const String
133 _DateTimeUtils::GetFullMonthString(int month) const
134 {
135         String text;
136         text.Clear();
137
138         DateTimeSymbols dateSymbols;
139         dateSymbols.Construct(CALENDAR_GREGORIAN);
140
141         const IList* pListOfFullMonths = dateSymbols.GetMonths();
142         SysTryReturn(NID_LCL, (pListOfFullMonths != null), text, E_SYSTEM, "[E_SYSTEM] A system error has occurred. pListOfFullMonths is null.");
143
144         String* pObj = null;
145         pObj = static_cast<String*>(const_cast<Object*>(pListOfFullMonths->GetAt(month - 1)));
146
147         if (pObj)
148         {
149                 text.Append(*pObj);
150         }
151
152         return text;
153 }
154 }}} // Tizen::Ui::Controls