Merge "Refactory NumberSymbols." into tizen_2.2
[platform/framework/native/appfw.git] / src / locales / FLclDateTimeFormatter.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FLclDateTimeFormatter.cpp
19  * @brief       This is the implementation file for DateTimeFormatter class.
20  */
21
22 // Includes
23 #include <FBaseSysLog.h>
24 #include <FLclDateTimeFormatter.h>
25 #include <FLclNumberFormatter.h>
26 #include "FLcl_DateTimeFormatterImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Base::Utility;
31
32 namespace Tizen { namespace Locales
33 {
34 /////////////////////////////////////////////////////////////////////////////////////////////////////
35 // Static Methods
36
37 DateTimeFormatter::DateTimeFormatter(void)
38         : __pNumberFormat(null)
39         , __pCalendar(null)
40         , __pDateTimeFormatterImpl(null)
41 {
42 }
43
44 DateTimeFormatter::~DateTimeFormatter(void)
45 {
46         delete __pDateTimeFormatterImpl;
47 }
48
49 DateTimeFormatter*
50 DateTimeFormatter::CreateDateFormatterN(DateTimeStyle style)
51 {
52         if (style == DATE_TIME_STYLE_NONE)
53         {
54                 style = DATE_TIME_STYLE_DEFAULT;
55         }
56
57         return _DateTimeFormatterImpl::CreateInstanceN(style, DATE_TIME_STYLE_NONE);
58 }
59
60
61 DateTimeFormatter*
62 DateTimeFormatter::CreateDateFormatterN(const Locale& locale, DateTimeStyle style)
63 {
64         if (style == DATE_TIME_STYLE_NONE)
65         {
66                 style = DATE_TIME_STYLE_DEFAULT;
67         }
68
69         return _DateTimeFormatterImpl::CreateInstanceN(locale, style, DATE_TIME_STYLE_NONE);
70 }
71
72
73 DateTimeFormatter*
74 DateTimeFormatter::CreateTimeFormatterN(DateTimeStyle style)
75 {
76         if (style == DATE_TIME_STYLE_NONE)
77         {
78                 style = DATE_TIME_STYLE_DEFAULT;
79         }
80
81         return _DateTimeFormatterImpl::CreateInstanceN(DATE_TIME_STYLE_NONE, style);
82 }
83
84
85 DateTimeFormatter*
86 DateTimeFormatter::CreateTimeFormatterN(const Locale& locale, DateTimeStyle style)
87 {
88         if (style == DATE_TIME_STYLE_NONE)
89         {
90                 style = DATE_TIME_STYLE_DEFAULT;
91         }
92
93         return _DateTimeFormatterImpl::CreateInstanceN(locale, DATE_TIME_STYLE_NONE, style);
94 }
95
96
97 DateTimeFormatter*
98 DateTimeFormatter::CreateDateTimeFormatterN(DateTimeStyle dateStyle, DateTimeStyle timeStyle)
99 {
100         if (dateStyle == DATE_TIME_STYLE_NONE)
101         {
102                 dateStyle = DATE_TIME_STYLE_DEFAULT;
103         }
104
105         if (timeStyle == DATE_TIME_STYLE_NONE)
106         {
107                 timeStyle = DATE_TIME_STYLE_DEFAULT;
108         }
109
110         return _DateTimeFormatterImpl::CreateInstanceN(dateStyle, timeStyle);
111 }
112
113
114 DateTimeFormatter*
115 DateTimeFormatter::CreateDateTimeFormatterN(const Locale& locale, DateTimeStyle dateStyle, DateTimeStyle timeStyle)
116 {
117         if (dateStyle == DATE_TIME_STYLE_NONE)
118         {
119                 dateStyle = DATE_TIME_STYLE_DEFAULT;
120         }
121
122         if (timeStyle == DATE_TIME_STYLE_NONE)
123         {
124                 timeStyle = DATE_TIME_STYLE_DEFAULT;
125         }
126
127         return _DateTimeFormatterImpl::CreateInstanceN(locale, dateStyle, timeStyle);
128 }
129
130
131 result
132 DateTimeFormatter::Format(const DateTime& date, String& strBuf) const
133 {
134         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
135         return __pDateTimeFormatterImpl->Format(date, strBuf);
136 }
137
138 result
139 DateTimeFormatter::Format(const Calendar& calendar, String& strBuf) const
140 {
141         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
142         return __pDateTimeFormatterImpl->Format(calendar, strBuf);
143 }
144
145 result
146 DateTimeFormatter::ApplyPattern(const String& pattern)
147 {
148         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
149         SysTryReturnResult(NID_LCL, !pattern.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. Input pattern is empty");
150
151         return __pDateTimeFormatterImpl->ApplyPattern(pattern);
152 }
153
154
155 String
156 DateTimeFormatter::GetPattern(void) const
157 {
158         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
159         return __pDateTimeFormatterImpl->GetPattern();
160 }
161
162
163 const DateTimeSymbols*
164 DateTimeFormatter::GetDateTimeSymbols(void) const
165 {
166         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
167         return __pDateTimeFormatterImpl->GetDateTimeSymbols();
168 }
169
170
171 void
172 DateTimeFormatter::SetDateTimeSymbols(const DateTimeSymbols& newSymbols)
173 {
174         SysAssertf(__pDateTimeFormatterImpl != null, "Not yet constructed! Construct() should be called before use.");
175         __pDateTimeFormatterImpl->SetDateTimeSymbols(newSymbols);
176 }
177
178
179 };
180 };      // Tizen::Locales
181