2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 /*jslint devel: true*/
27 (function () { // strict mode wrapper
33 * Returns date in format YYYY/MM/DD
35 * @returns {String} formatted
37 getShortDate: function Helpers_getShortDate(dateObj) {
41 yyyy = dateObj.getFullYear().toString();
42 mm = (dateObj.getMonth() + 1).toString(); // January === 0
43 dd = dateObj.getDate().toString();
45 console.error('error', e);
48 // return in format yyyy/mm/dd
49 return yyyy + '/' + (mm[1] ?
51 '0' + mm[0]) + '/' + (dd[1] ? dd : '0' + dd[0]);
54 * Returns date in format DD short_month YYYY
56 * @returns {String} formatted
58 toNativeDate: function Helpers_toNativeDate(dateObj) {
59 var date = dateObj.toDateString().split(" ");
60 return date[2] + ' ' + date[1] + ' ' + date[3];
63 * Returns time in format HH:mm or hh:mm ap
65 * @returns {String} formatted
67 toNativeTime: function Helpers_toNativeDate(dateObj) {
69 if (tizen.time.getTimeFormat().indexOf('ap') !== -1) {
70 hours = dateObj.getHours();
71 apHours = hours % 12 < 10 ? '0' + hours % 12 : hours % 12;
73 return apHours.toString().replace("00", "12") + ':' +
74 (dateObj.getMinutes() < 10 ? "0" + dateObj.getMinutes() :
75 dateObj.getMinutes()) + (hours > 11 ? ' PM' : ' AM');
77 return dateObj.toTimeString().substring(0, 5);
80 * Seconds to hours converter
85 secondsToHours: function Helpers_secondsToHours(seconds) {
87 str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60);
88 seconds = parseInt(seconds / 60, 10);
90 str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60) + str;
91 seconds = parseInt(seconds / 60, 10);
93 str = ((seconds % 24 < 10) ? '0' : '') + (seconds % 24) + str;
94 seconds = parseInt(seconds / 24, 10);
99 * Returns scroll position of the given scroll view.
100 * @param {object} element ScrollView element
101 * @returns {number} scroll position
103 getScrollPosition: function Helpers_getScrollPosition(element) {
104 return element.scrollview('getScrollPosition').y;
108 * Scrolls given jQuery ScrollView to given Y position.
109 * @param {object} element ScrollView element to be scrolled.
110 * @param {number} position Y position to scroll to
112 scrollTo: function Helpers_scrollTo(element, position) {
113 // don't allow scrolling too much
115 element.children().first().outerHeight(true) -
117 if (maxPosition < 0) {
120 if (position > maxPosition) {
121 position = maxPosition;
127 element.scrollview('scrollTo', 0, -position);