2 * Copyright (c) 2013, Intel Corporation.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 function datetimePanelInit() {
11 var clockTimer = null;
12 var timeChanged = false;
13 var timezoneChanged = false;
15 /* Display Settings Panel */
16 $('#page_datetime').on('pageshow', function() {
17 console.log('Date and time settings entered');
21 $('#input_time').on('change', function(event, data) {
23 var time = this.value;
24 console.log('time value changed: ' + time);
29 $('#input_time').on('focus', function(event, data) {
34 $('#input_date').on('change', function(event, data) {
36 var date = this.value;
37 console.log('date value changed: ' + date);
41 $('#select_timezone').on('change', function(event, data) {
42 /* ignore change due to getLocalTimezone() */
43 if (data === false) return;
45 timezoneChanged = true;
46 var timezone = this.value;
47 console.log('timezone value changed: ' + timezone);
51 $('#button_datetime_apply').on('click', function(event, data) {
56 if (timezoneChanged) {
57 timezoneChanged = false;
58 updateSystemTimezone();
65 $('#button_datetime_cancel').on('click', function(event, data) {
69 $('#page_datetime_button_back').on('click', function() {
74 function datetimePageReload() {
77 timezoneChanged = false;
82 console.log('Local datetime is ' + current.toISOString());
84 timeStr = datetimeGetStr(current.getHours()) + ':';
85 timeStr += datetimeGetStr(current.getMinutes()) + ':';
86 timeStr += datetimeGetStr(current.getSeconds());
87 $('#input_time').val(timeStr);
89 dateStr = datetimeGetStr(current.getFullYear()) + '-';
90 dateStr += datetimeGetStr(current.getMonth()) + '-';
91 dateStr += datetimeGetStr(current.getDate());
92 $('#input_date').val(dateStr);
97 var alltimezones = tizen.time.getAvailableTimezones();
98 console.log('Supports ' + alltimezones.length + ' time zones.');
99 console.log('Local timezone: ' + tizen.time.getLocalTimezone());
100 if (alltimezones.length > 0) {
101 $('#select_timezone').empty();
102 for (var i = 0; i < alltimezones.length; i++) {
103 $('#select_timezone').append(new Option(alltimezones[i], alltimezones[i]));
106 $('#select_timezone').val(tizen.time.getLocalTimezone()).trigger('change', false);
110 function datetimeShowOption() {
111 $('#button_datetime_apply').show();
112 $('#button_datetime_cancel').show();
115 function datetimeHideOption() {
116 $('#button_datetime_apply').hide();
117 $('#button_datetime_cancel').hide();
120 function datetimeStartTimer() {
121 console.log('Start clock timer');
122 clockTimer = setInterval(dateTimeUpdateClock, 1000);
125 function datetimeStopTimer() {
127 console.log('Stop clock timer');
128 clearInterval(clockTimer);
132 function dateTimeUpdateClock() {
133 var current = new Date();
135 var timeStr = datetimeGetStr(current.getHours()) + ':';
136 timeStr += datetimeGetStr(current.getMinutes()) + ':';
137 timeStr += datetimeGetStr(current.getSeconds());
138 $('#input_time').val(timeStr);
141 function updateSystemTime() {
142 var time = $('#input_date').val() + ' ' + $('#input_time').val();
144 /* settings daemon expects number of seconds since midnight Jan 1, 1970 */
145 var epoch_time = new Date(time).getTime() / 1000;
146 console.log('System time set to: ' + time + ' or ' + epoch_time + ' seconds since 1/1/1970');
148 settings.datetime.setTime(epoch_time, function() {
149 console.log('System time set successfully');
151 showMsg('Error', 'Cannot set system time: ' + e);
155 function updateSystemTimezone() {
156 var value = $('#select_timezone').val();
157 settings.datetime.setTimezone(value, function() {
158 console.log('System timezone is set to: ' + value);
160 showMsg('Error', 'Cannot set system timezone: ' + e);
164 function datetimeGetStr(value) {
165 if (0 < value && value < 10) {