2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include <Commons/Exception.h>
26 #include <API/TimeUtil/TZDateProperties.h>
28 #include <unicode/ustring.h>
29 #include <unicode/timezone.h>
30 #include <unicode/calendar.h>
31 #include <unicode/strenum.h>
32 #include <unicode/datefmt.h>
35 #include "TimeUtilTools.h"
37 using namespace TizenApis::Api::TimeUtil;
38 using namespace WrtDeviceApis;
55 void TimeUtil::setCurrentTZDate(const TZDateProperties &tzdate){
56 ThrowMsg(Commons::UnsupportedException, "Not support to set current DateTime");
59 std::string TimeUtil::getLocalTimezone() {
61 UnicodeString idResult;
62 UChar *result = (UChar*)malloc(sizeof(UChar)*1024);
63 int32_t result_capacity = 1024;
65 UErrorCode ec = U_ZERO_ERROR;
67 TimeZone* zone = TimeZone::createDefault();
70 len = ID.extract(result, result_capacity, ec);
77 std::string s_result = Util.strtoutf8(result);
78 LogDebug("result : " << s_result);
86 } catch (Commons::PlatformException) {
87 LogError("can't get the local timezone's name");
96 ThrowMsg(Commons::PlatformException, "Can't get Local Timezone");
101 std::string TimeUtil::getUTCTimezone() {
103 UnicodeString idResult;
104 UChar *result = (UChar*)malloc(sizeof(UChar)*1024);
105 int32_t result_capacity = 1024;
107 UErrorCode ec = U_ZERO_ERROR;
110 const TimeZone *UTCTimezone = TimeZone::getGMT();
111 UTCTimezone->getID(ID);
112 len = ID.extract(result, result_capacity, ec);
117 std::string s_result = Util.strtoutf8(result);
123 LogDebug("result : " << s_result);
126 } catch(Commons::PlatformException) {
127 LogError("can't get the UTC timezone's name");
134 ThrowMsg(Commons::PlatformException, "Can't get UTC Timezone");
138 std::vector<std::string> TimeUtil::getAvailableTimezones(){
139 UErrorCode ec = U_ZERO_ERROR;
140 StringEnumeration * tzen = TimeZone::createEnumeration();
141 const char *str = NULL;
142 int32_t count = tzen->count(ec);
143 std::vector<std::string> timezones;
145 LogDebug("count: " << count);
151 int32_t resultLen = 0;
153 str = tzen->next(&resultLen, ec);
155 std::string timezone = str;
156 timezones.push_back(timezone);
159 }while((str!=NULL) && (i < count));
161 ThrowMsg(Commons::PlatformException, "Can't get timezones list");
166 std::string TimeUtil::getDateFormat(const bool b_shortFormat) {
175 std::string TimeUtil::getTimeFormat(){