// EXTERNAL INCLUDES
#ifdef APPCORE_WATCH_AVAILABLE
#include <appcore-watch/watch_app.h>
+#include <appcore-watch/watch_app_extension.h>
#endif
namespace Dali
return second;
}
+int WatchTime::GetMillisecond() const
+{
+ int millisecond;
+
+ watch_time_get_millisecond(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &millisecond);
+ return millisecond;
+}
+
+int WatchTime::GetYear() const
+{
+ int year;
+
+ watch_time_get_year(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &year);
+ return year;
+}
+
+int WatchTime::GetMonth() const
+{
+ int month;
+
+ watch_time_get_month(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &month);
+ return month;
+}
+
+int WatchTime::GetDay() const
+{
+ int day;
+
+ watch_time_get_day(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &day);
+ return day;
+}
+
+int WatchTime::GetDayOfWeek() const
+{
+ int dayOfWeek;
+
+ watch_time_get_day_of_week(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &dayOfWeek);
+ return dayOfWeek;
+}
+
+struct tm WatchTime::GetUtcTime() const
+{
+ struct tm UtcTime;
+
+ watch_time_get_utc_time(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &UtcTime);
+ return UtcTime;
+}
+
+time_t WatchTime::GetUtcTimeStamp() const
+{
+ time_t UtcTimeStamp;
+
+ watch_time_get_utc_timestamp(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &UtcTimeStamp);
+ return UtcTimeStamp;
+}
+
+const char* WatchTime::GetTimeZone() const
+{
+ char* timeZone;
+
+ watch_time_get_time_zone(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &timeZone);
+ return timeZone;
+}
+
+bool WatchTime::GetDaylightSavingTimeStatus() const
+{
+ bool daylight;
+
+ watch_time_get_daylight_time_status(reinterpret_cast<watch_time_h>(mImpl->mTimeHandle), &daylight);
+ return daylight;
+}
+
#else
WatchTime::WatchTime()
:mImpl(NULL)
return 0;
}
+int WatchTime::GetMillisecond() const
+{
+ return 0;
+}
+
+int WatchTime::GetYear() const
+{
+ return 0;
+}
+
+int WatchTime::GetMonth() const
+{
+ return 0;
+}
+
+int WatchTime::GetDay() const
+{
+ return 0;
+}
+
+int WatchTime::GetDayOfWeek() const
+{
+ return 0;
+}
+
+struct tm WatchTime::GetUtcTime() const
+{
+ time_t zero = time(0);
+ return *localtime(&zero);
+}
+
+time_t WatchTime::GetUtcTimeStamp() const
+{
+ return 0;
+}
+
+const char* WatchTime::GetTimeZone() const
+{
+ return 0;
+}
+
+bool WatchTime::GetDaylightSavingTimeStatus() const
+{
+ return 0;
+}
+
#endif
} // namespace Dali
*/
// EXTERNAL INCLUDES
+#include <time.h>
// INTERNAL INCLUDES
#include <dali/public-api/dali-core.h>
* @brief The WatchTime class is used to get time for the WatchApplication.
*
* A WatchTime has a time handle from watch application framework.
- * You can get time(hour, minute, second) on receiving timeTick signal
+ * You can get time(hour, minute, second, millisecond) and date(year, month, day)
+ * on receiving timeTick signal.
* @SINCE_1_1.37
*/
class DALI_IMPORT_API WatchTime
public:
/**
- * @brief Constructor
+ * @brief Constructor.
* @SINCE_1_1.37
*/
WatchTime();
/**
- * @brief Destructor
+ * @brief Destructor.
* @SINCE_1_1.37
*/
~WatchTime();
/**
- * @brief return current hour
+ * @brief Returns the current hour.
*
* @SINCE_1_1.37
- * @return the current hour
+ * @return The current hour
+ * @note The return value is always positive.
* @pre The WatchTime needs to be initialized.
*/
int GetHour() const;
/**
- * @brief return current hour24
+ * @brief Returns the current hour24.
*
* @SINCE_1_1.37
- * @return the current hour(the 24-hour clock)
+ * @return The current hour(the 24-hour clock)
+ * @note The return value is always positive.
* @pre The WatchTime needs to be initialized.
*/
int GetHour24() const;
/**
- * @brief return current minute
+ * @brief Returns the current minute.
*
* @SINCE_1_1.37
- * @return the current minute
+ * @return The current minute
+ * @note The return value is always positive.
* @pre The WatchTime needs to be initialized.
*/
int GetMinute() const;
/**
- * @brief return current second
+ * @brief Returns the current second.
*
* @SINCE_1_1.37
- * @return the current second
+ * @return The current second
+ * @note The return value is always positive.
* @pre The WatchTime needs to be initialized.
*/
int GetSecond() const;
+ /**
+ * @brief Returns the current millisecond.
+ *
+ * @SINCE_1_2_32
+ * @return The current millisecond
+ * @note The return value is always positive.
+ * @pre The WatchTime needs to be initialized.
+ */
+ int GetMillisecond() const;
+
+ /**
+ * @brief Returns the current year.
+ *
+ * @SINCE_1_2_32
+ * @return The current year
+ * @note The return value is always positive.
+ * @pre The WatchTime needs to be initialized.
+ */
+ int GetYear() const;
+
+ /**
+ * @brief Returns the current month.
+ *
+ * @SINCE_1_2_32
+ * @return The current month
+ * @note The return value is always positive.
+ * @pre The WatchTime needs to be initialized.
+ */
+ int GetMonth() const;
+
+ /**
+ * @brief Returns the current day.
+ *
+ * @SINCE_1_2_32
+ * @return The current day
+ * @note The return value is always positive.
+ * @pre The WatchTime needs to be initialized.
+ */
+ int GetDay() const;
+
+ /**
+ * @brief Returns the current day of week.
+ *
+ * @details The value returns from 1 (Sunday) to 7 (Saturday).
+ *
+ * @SINCE_1_2_32
+ * @return The current day of week
+ * @note The return value is always positive.
+ * @pre The WatchTime needs to be initialized.
+ */
+ int GetDayOfWeek() const;
+
+ /**
+ * @brief Returns the UTC time. (Coordinated Universal Time)
+ *
+ * @details Regarding struct tm (the return value), please refer to the site :
+ * http://www.cplusplus.com/reference/ctime/tm/
+ *
+ * @SINCE_1_2_32
+ * @return The UTC time
+ * @pre The WatchTime needs to be initialized.
+ */
+ struct tm GetUtcTime() const;
+
+ /**
+ * @brief Returns the UTC timestamp.
+ *
+ * @SINCE_1_2_32
+ * @return The UTC timestamp
+ * @pre The WatchTime needs to be initialized.
+ */
+ time_t GetUtcTimeStamp() const;
+
+ /**
+ * @brief Returns the ID of timezone.
+ *
+ * @details The timezone ID, according to the IANA(Internet Assigned Numbers Authority)
+ * If you want to see more information, please refer to the site :
+ * https://en.wikipedia.org/wiki/List_of_tz_database_time_zones/
+ *
+ * @SINCE_1_2_32
+ * @return The ID of timezone
+ * @pre The WatchTime needs to be initialized.
+ */
+ const char* GetTimeZone() const;
+
+ /**
+ * @brief Returns the daylight saving time status.
+ *
+ * @SINCE_1_2_32
+ * @return The Daylight Saving Time status
+ * @pre The WatchTime needs to be initialized.
+ */
+ bool GetDaylightSavingTimeStatus() const;
+
public: // Not intended for application developers
DALI_INTERNAL WatchTime(void *time_handle);
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali/dali.h>
+#include <dali-test-suite-utils.h>
+#include "public-api/dali-wearable.h"
+#include <appcore-watch/watch_app.h>
+#include <appcore-watch/watch_app_extension.h>
+#include <stdlib.h>
+#define TIMEZONE_BUFFER_MAX 102
+
+using namespace Dali;
+
+void utc_dali_watchtime_startup(void)
+{
+ test_return_value = TET_UNDEF;
+}
+
+void utc_dali_watchtime_cleanup(void)
+{
+ test_return_value = TET_PASS;
+}
+
+namespace
+{
+
+struct MyTestApp : public ConnectionTracker
+{
+ MyTestApp( WatchApplication& app)
+ : initCalled( false ),
+ mApplication( app )
+ {
+ mApplication.InitSignal().Connect( this, &MyTestApp::Create );
+ }
+
+ void Create(Application& app)
+ {
+ initCalled = true;
+ }
+
+ void Quit()
+ {
+ mApplication.Quit();
+ }
+
+ // Data
+ bool initCalled;
+ WatchApplication& mApplication;
+};
+
+} // unnamed namespace
+
+int UtcDaliWatchTimeNew(void)
+{
+ WatchTime watchTime;
+ WatchTime *watchTimeRef = &watchTime;
+
+ DALI_TEST_CHECK( watchTimeRef );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetHour(void)
+{
+ int ret, hour;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_hour(watch_time, &hour);
+
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetHour() == hour );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetHour24(void)
+{
+ int ret, hour24;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_hour24(watch_time, &hour24);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetHour24() == hour24 );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetMinute(void)
+{
+ int ret, minute;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_minute(watch_time, &minute);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetMinute() == minute );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetSecond(void)
+{
+ int ret, second;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_second(watch_time, &second);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetSecond() == second );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetMillisecond(void)
+{
+ int ret, millisecond;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_millisecond(watch_time, &millisecond);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetMillisecond() == millisecond );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetYear(void)
+{
+ int ret, year;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_year(watch_time, &year);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetYear() == year );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetMonth(void)
+{
+ int ret, month;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_month(watch_time, &month);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetMonth() == month );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetDay(void)
+{
+ int ret, day;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day(watch_time, &day);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetDay() == day );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetDayOfWeek(void)
+{
+ int ret, dayOfWeek;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day_of_week(watch_time, &dayOfWeek);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetDayOfWeek() == dayOfWeek );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetUtcTime(void)
+{
+ int ret;
+ struct tm *utcTime = (struct tm *)calloc( 1, sizeof( struct tm ) );
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day(watch_time, utcTime);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetUtcTime().tm_sec == (*utcTime).tm_sec );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetUtcTimeStamp(void)
+{
+ int ret;
+ time_t *timeStamp = (time_t *)calloc( 1, sizeof( time_t ) );
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day(watch_time, timeStamp);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetUtcTimeStamp() == *timeStamp );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetTimeZone(void)
+{
+ int ret;
+ char *timeZone[TIMEZONE_BUFFER_MAX] = {0,};
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day(watch_time, timeZone);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetTimeZone() == timeZone );
+
+ END_TEST;
+}
+
+int UtcDaliWatchTimeGetDaylightSavingTimeStatus(void)
+{
+ int ret;
+ bool daylight;
+ WatchTime watchTime;
+ watch_time_h watch_time = {0,};
+
+ ret = watch_time_get_current_time(&watch_time);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ ret = watch_time_get_day(watch_time, &daylight);
+ DALI_TEST_CHECK( ret == APP_ERROR_NONE );
+
+ DALI_TEST_CHECK( watchTime.GetDaylightSavingTimeStatus() == daylight );
+
+ END_TEST;
+}