Merge lp:~rpadovani/ubuntu-calculator-app/fix-for-1156520 into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Padovani
Status: Merged
Approved by: Dalius
Approved revision: 35
Merged at revision: 35
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/fix-for-1156520
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 199 lines (+117/-3)
5 files modified
Simple/Memory.qml (+1/-0)
Simple/Screen.qml (+19/-0)
Simple/SimplePage.qml (+15/-3)
Storage.qml (+75/-0)
debian/changelog (+7/-0)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/fix-for-1156520
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Dalius (community) Approve
Review via email: mp+154431@code.launchpad.net

Commit message

Fixed bug 1156520:
- added label for date
- added function to convert timestamp in a string

Description of the change

Fixed bug 1156520:
- added label for date
- added function to convert timestamp in a string

To post a comment you must log in.
Revision history for this message
Dalius (dalius-sandbox) wrote :

We will definitely have problems with l10n with this but we can address that later.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

FAILED: Autolanding.
No commit message was specified in the merge proposal. Hit 'Add commit message' on the merge proposal web page or follow the link below. You can approve the merge proposal yourself to rerun.
https://code.launchpad.net/~rpadovani/ubuntu-calculator-app/fix-for-1156520/+merge/154431/+edit-commit-message

review: Needs Fixing (continuous-integration)
Revision history for this message
Riccardo Padovani (rpadovani) wrote :

> FAILED: Autolanding.
> No commit message was specified in the merge proposal. Hit 'Add commit
> message' on the merge proposal web page or follow the link below. You can
> approve the merge proposal yourself to rerun.
> https://code.launchpad.net/~rpadovani/ubuntu-calculator-app/fix-
> for-1156520/+merge/154431/+edit-commit-message

Done...

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Simple/Memory.qml'
2--- Simple/Memory.qml 2013-03-19 09:51:33 +0000
3+++ Simple/Memory.qml 2013-03-20 16:34:23 +0000
4@@ -8,5 +8,6 @@
5 isLastItem: true
6 operators: []
7 mainLabel: ''
8+ dateText: ''
9 }
10 }
11
12=== modified file 'Simple/Screen.qml'
13--- Simple/Screen.qml 2013-03-19 09:51:33 +0000
14+++ Simple/Screen.qml 2013-03-20 16:34:23 +0000
15@@ -13,12 +13,14 @@
16 signal useAnswer(string answerToUse, string formulaData)
17 signal labelTextUpdated(int idx, string newText)
18 signal mainLabelUpdated(int idx, string newText)
19+ signal dateUpdate(int idx)
20 signal removeItem()
21
22 Rectangle{
23 id: _content
24 width: parent.width
25 height: inputs.height+units.gu(2)
26+
27 Column {
28 id: inputs
29 anchors.top: parent.top
30@@ -26,6 +28,23 @@
31 width: parent.width - units.gu(4)
32 anchors.centerIn: parent
33
34+ // Every five minutes update date label
35+ Timer {
36+ interval: 300000
37+ repeat: true
38+ running: true
39+ onTriggered: root.dateUpdate(index)
40+ }
41+
42+ Text {
43+ id: dateLabel
44+ width: parent.width
45+ color: "#757373"
46+ text: dateText
47+ font.italic: true
48+ font.family: "Ubuntu"
49+ }
50+
51 TextField{
52 width: parent.width
53 ItemStyle.delegate: Item{} // removes ubuntu shape
54
55=== modified file 'Simple/SimplePage.qml'
56--- Simple/SimplePage.qml 2013-03-19 17:52:36 +0000
57+++ Simple/SimplePage.qml 2013-03-20 16:34:23 +0000
58@@ -154,11 +154,13 @@
59 function addCurrentToMemory() {
60 if (screenFormula[screenFormula.length-1]._operation === '=') {
61 var currentDate = new Date();
62- if (memory.get(0).mainLabel.length == 0)
63- memory.get(0).mainLabel = currentDate.toString();
64+ if (memory.get(0).mainLabel.length === 0)
65+ memory.get(0).mainLabel = '';
66 memory.get(0).isLastItem = false
67+ memory.get(0).dateText = "Few seconds ago..."
68+ memory.get(0).timeStamp = currentDate.getTime()
69 memory.setProperty(0, "timeStamp", currentDate.getTime());
70- memory.insert(0,{'dbId': -1, 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true, 'mainLabel': ''});
71+ memory.insert(0,{'dbId': -1, 'dateText': "", 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true, 'mainLabel': ''});
72 positionViewAtBeginning();
73 }
74 }
75@@ -207,6 +209,16 @@
76 memory.get(index).mainLabel = newText;
77 }
78
79+ // Update date label
80+ onDateUpdate: {
81+ // If is in database
82+ if (memory.get(index).dbId !== -1)
83+ memory.get(index).dateText = storage.fromDateToString(storage.fromIdToDate(memory.get(index).dbId));
84+ // If is in memory but not in database
85+ else if (memory.get(index).timeStamp)
86+ memory.get(index).dateText = storage.fromDateToString(memory.get(index).timeStamp);
87+ }
88+
89 onLabelTextUpdated: {
90 if(index === 0){
91 screenFormula[idx]._text = newText;
92
93=== modified file 'Storage.qml'
94--- Storage.qml 2013-03-19 09:51:33 +0000
95+++ Storage.qml 2013-03-20 16:34:23 +0000
96@@ -35,8 +35,11 @@
97 for(var i=res.rows.length - 1; i >= 0; i--){
98 var obj = JSON.parse(res.rows.item(i).calc);
99 obj.dbId = res.rows.item(i).id;
100+ obj.dateText = fromDateToString(res.rows.item(i).insertDate);
101+
102 if (!('mainLabel' in obj))
103 obj.mainLabel = ''
104+
105 callback(obj);
106 }
107 }
108@@ -66,4 +69,76 @@
109 tx.executeSql('DELETE FROM Calculations WHERE id = ?', [calc.dbId]);
110 });
111 }
112+
113+ /*
114+ * Function fromDateToString
115+ *
116+ * Given an input object recovers its timestamp and
117+ * returns a string based on how much time has passed
118+ */
119+ function fromDateToString(time) {
120+ time = new Date(time);
121+ var now = new Date();
122+ var string;
123+
124+ // Create a string with minutes :MM AM/PM
125+ var minutes = ":";
126+ minutes += time.getMinutes() < 10 ? "0" : "";
127+ minutes += time.getMinutes() + " "
128+ minutes += time.getHours() > 12 ? "PM" : "AM";
129+
130+ var weekdays = ["Sun","Mon","Tue", "Wed", "Thu", "Fry", "Sat"];
131+ var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
132+
133+ // Today
134+ if (now.getDate() - time.getDate() === 0 && now.getMonth() === time.getMonth()) {
135+ // Between 0 & 59 minutes
136+ if (now.getHours() - time.getHours() < 1 || (now.getHours() - time.getHours() === 1 && time.getMinutes() > now.getMinutes())) {
137+ // This is for different hours ex datestamp 11:58 now 12:02
138+ string = now.getMinutes() - time.getMinutes() > 0 ? now.getMinutes() - time.getMinutes() : now.getMinutes() - time.getMinutes() + 60;
139+ string += " minutes ago";
140+
141+ // Less than two minutes
142+ if (now.getMinutes() - time.getMinutes() <= 1 && now.getMinutes() - time.getMinutes() >= 0 )
143+ string = "Few seconds ago...";
144+
145+ return string;
146+ }
147+
148+ // > 1 hour ago
149+ string = now.getHours() - time.getHours() + " hour";
150+ string += now.getHours() - time.getHours() > 1 ? "s" : "";
151+ return string + " ago";
152+ } // End today
153+
154+ // Between yesterday and one week ago
155+ if (now.getDate() - time.getDate() > 0 && now.getDate() - time.getDate() < 7 && now.getMonth() === time.getMonth()) {
156+ string = now.getDate() - time.getDate() === 1 ? "Yesterday" : weekdays[time.getDay()];
157+ string += ", ";
158+ string += time.getHours() > 12 ? time.getHours() - 12 : time.getHours();
159+ string += minutes;
160+
161+ return string;
162+ }
163+
164+ // More than one week ago
165+ string = months[time.getMonth()];
166+ string += " " + weekdays[time.getDay()] + ", ";
167+ string += time.getHours() > 12 ? time.getHours() - 12 : time.getHours();
168+ string += minutes;
169+ return string;
170+ }
171+
172+ // Function to have time from an ID
173+ function fromIdToDate (dbId) {
174+ var time;
175+ openDB();
176+ db.transaction(
177+ function(tx){
178+ var res = tx.executeSql('SELECT insertDate FROM Calculations WHERE id = ?', dbId);
179+ time = res.rows.item(0).insertDate;
180+ }
181+ );
182+ return time;
183+ }
184 }
185
186=== modified file 'debian/changelog'
187--- debian/changelog 2013-02-12 16:27:14 +0000
188+++ debian/changelog 2013-03-20 16:34:23 +0000
189@@ -1,3 +1,10 @@
190+ubuntu-calculator-app (0.1ubuntu1) UNRELEASED; urgency=low
191+
192+ * Fixing bug 1156520
193+ * Added a function to convert date to string
194+
195+ -- Riccardo Padovani <rpadovani@ubuntu-it.org> Wed, 20 Mar 2013 17:26:30 +0100
196+
197 ubuntu-calculator-app (0.1) raring; urgency=low
198
199 * Initial release

Subscribers

People subscribed via source and target branches