Merge lp:~rpadovani/ubuntu-calculator-app/1214395 into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk

Proposed by Riccardo Padovani
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 158
Merged at revision: 151
Proposed branch: lp:~rpadovani/ubuntu-calculator-app/1214395
Merge into: lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
Diff against target: 584 lines (+79/-200)
9 files modified
Simple/CalcKeyboard.qml (+0/-1)
Simple/CalcLabel.qml (+14/-35)
Simple/KeyboardButton.qml (+0/-1)
Simple/Screen.qml (+27/-30)
Simple/SimplePage.qml (+8/-17)
Storage.qml (+5/-2)
bignumber.js (+9/-8)
dateutils.js (+0/-99)
engine.js (+16/-7)
To merge this branch: bzr merge lp:~rpadovani/ubuntu-calculator-app/1214395
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Nekhelesh Ramananthan (community) Needs Information
Mihir Soni Needs Fixing
Review via email: mp+184440@code.launchpad.net

Commit message

New design guideline

Description of the change

Implementation of new design guideline:
- One pencil icon acting as toggle to change between edit and normal view for labels
- Restrict the number of characters for labelling to 12 characters, header to 20 characters.
- Restrict the number of digits of calculation to 11 digits.
- Time of calc is now inline with title label
- Removed Timer and DateUtils that are no longer required with new design
- Removed font.family, no longer necessary

Fixed #1219718
Fixed #1214395
Fixed #1222144

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
150. By Riccardo Padovani

Update label

151. By Riccardo Padovani

New time format

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

Thank you for your fix, it needs some changes as follow :

1.When we try to edit header it overlaps edit icon & cursor.
2.We have to keep only date on right side ( No few seconds ago)
3.Dates should be visible when user start calculation (Need some inputs from boiko,dpm or popey)

review: Needs Fixing
152. By Riccardo Padovani

Fixed two issues with new design, removed Timer and DateUtils

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

Hi Mihir, thanks for your review.
I fixed 1 and 2, but I'm not sure to have understand about three, we need a clock updated every minute to show current hour? I think is not a good idea...

Revision history for this message
Mihir Soni (mihirsoni) wrote :

Ricacardo , This is what we had discussion in our last design meeting still we need inputs.
Also, we have to make our result to 11 Digits inclusive of exponential.
We have to confirm this things first and then we can move further.

Thank you.

Revision history for this message
Mihir Soni (mihirsoni) wrote :

Sorry , Third might be my misunderstanding. We can skip that..Can we make our result to 11 digits ? so that

153. By Riccardo Padovani

Activated the exp result

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

I have updated bignumber.js to have exp result when the lenght of result is > 11, but I have a doubt on how to limit the lenght of exp result to 11 digits, so I have ask to the developer.

See https://github.com/MikeMcl/bignumber.js/issues/12

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
154. By Riccardo Padovani

Set max lenght for exponential form

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Thanks to the fast answer of the dev I have implemented it.

Now I think is all ok.

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Mihir Soni (mihirsoni) wrote :

Hi Riccardo , this is awesome work and it's working superb on my machine.

Could you do one small change :-

1.Operands labels are length of 11 only , can we make underline accordingly , it looks too messy you can find in attached screenshot.

review: Needs Fixing
Revision history for this message
Mihir Soni (mihirsoni) wrote :

Riccardo , I did some more testing and found a bug :-

Steps to reproduce :-

Start new calculation with 89*89 press (=)

Output should be 7921 , but current output is 7921.000000

Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

I have 2 questions, the first being why do you explicitly state the font family? Isnt the Ubuntu font the default? (This is more a question since I do know it either)

font.family: "Ubuntu"

Also why do you Text {} instead of Label {} to display the date or anything? I think since Label is part of the SDK, it will automatically follow the SDK design styles. Correct me if I am wrong.

review: Needs Information
Revision history for this message
Nekhelesh Ramananthan (nik90) wrote :

I meant above that I *did not* know it either.

Revision history for this message
Riccardo Padovani (rpadovani) wrote :

Thanks for your observation Nik, I removed all font.family, I think they were there since there wasn't a theme.
Also, I changed Text in Label, but have a different theme from SDK.

Mihir, I have fixed the bug

155. By Riccardo Padovani

Bugfixes

156. By Riccardo Padovani

Minor bugfixes

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
157. By Riccardo Padovani

Update to MAX_LENGHT

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

48 + width: row.width-operatorLabel.width-formulaLabel.width

Can you just add some spacing between the operators?

review: Needs Fixing
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

92 + width: parent.width - units.gu(1)/2

isn't it the same as: parent.width - units.gu(0.5)?

review: Needs Fixing
Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

114 + width: parent.width / 20 * 11

That's a misterious value, would it be possible to have at least an explanation on what this value means?

review: Needs Fixing
158. By Riccardo Padovani

Updated some widths

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

Looks good to me now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Simple/CalcKeyboard.qml'
--- Simple/CalcKeyboard.qml 2013-06-11 19:33:52 +0000
+++ Simple/CalcKeyboard.qml 2013-09-11 10:39:56 +0000
@@ -30,7 +30,6 @@
30 visible: formulaView.__wasAtYBegining && formulaView.__displaceDist > units.gu(2)30 visible: formulaView.__wasAtYBegining && formulaView.__displaceDist > units.gu(2)
31 font.pixelSize: units.gu(2)31 font.pixelSize: units.gu(2)
32 text: formulaView.__toBeRefresh ? i18n.tr("Release to start new calculation") : i18n.tr("Pull to start new calculation")32 text: formulaView.__toBeRefresh ? i18n.tr("Release to start new calculation") : i18n.tr("Pull to start new calculation")
33 font.family: "Ubuntu"
34 anchors.horizontalCenter: parent.horizontalCenter33 anchors.horizontalCenter: parent.horizontalCenter
35 color: '#757373'34 color: '#757373'
36 }35 }
3736
=== modified file 'Simple/CalcLabel.qml'
--- Simple/CalcLabel.qml 2013-09-04 15:20:51 +0000
+++ Simple/CalcLabel.qml 2013-09-11 10:39:56 +0000
@@ -43,31 +43,10 @@
43 id: row43 id: row
44 height: numbersHeight44 height: numbersHeight
45 width: parent.width45 width: parent.width
46 Item {46 anchors.left: parent.left
47 id: editIcon47
48 height: parent.height48 Item {
49 width: units.gu(3)49 width: row.width - operatorLabel.width - formulaLabel.width
50
51 Image {
52 anchors.verticalCenter: parent.verticalCenter
53 source: Qt.resolvedUrl("images/edit.png")
54 visible: root.numbers || root.operation
55 }
56
57 MouseArea {
58 anchors.fill: parent
59 onClicked: {
60 if (root.numbers || root.operation) {
61 numberName.focus = true;
62 numberName.forceActiveFocus();
63 calcKeyboardVisible = false;
64 }
65 }
66 }
67 }
68
69 Item {
70 width: row.width-editIcon.width-operatorLabel.width-formulaLabel.width
71 height: parent.height50 height: parent.height
7251
73 TextField {52 TextField {
@@ -79,11 +58,11 @@
79 background: Item {}58 background: Item {}
80 }59 }
8160
82 visible: root.numbers || root.operation
83
84 onActiveFocusChanged: {61 onActiveFocusChanged: {
85 if (numberName.activeFocus)62 if (numberName.activeFocus) {
63 labelVisible = true
86 calcKeyboardVisible = false64 calcKeyboardVisible = false
65 }
87 }66 }
8867
89 readOnly: labelReadOnly68 readOnly: labelReadOnly
@@ -91,12 +70,14 @@
91 color: "#FEFEFE"70 color: "#FEFEFE"
92 onTextChanged: { labelText = numberName.text }71 onTextChanged: { labelText = numberName.text }
93 hasClearButton: false72 hasClearButton: false
73 maximumLength: 12
9474
95 InverseMouseArea {75 InverseMouseArea {
96 onClicked: {76 onClicked: {
97 root.forceActiveFocus();77 root.forceActiveFocus();
98 numberName.focus = false;78 numberName.focus = false;
99 mouse.accepted = false;79 mouse.accepted = false;
80 labelVisible = false;
100 calcKeyboardVisible = true;81 calcKeyboardVisible = true;
101 }82 }
102 anchors.fill: parent;83 anchors.fill: parent;
@@ -106,23 +87,22 @@
106 }87 }
10788
108 Image {89 Image {
109 visible: numberName.focus && (root.numbers || root.operation)90 visible: labelVisible
110 anchors.bottom: parent.bottom91 anchors.bottom: parent.bottom
111 source: Qt.resolvedUrl("images/dot.png")92 source: Qt.resolvedUrl("images/dot.png")
112 fillMode: Image.Tile93 fillMode: Image.Tile
113 width: parent.width-units.gu(1)94 width: parent.width - units.gu(0.5)
114 height: units.gu(1)/295 height: units.gu(0.5)
115 }96 }
116 }97 }
11798
118 Label {99 Label {
119 id: operatorLabel100 id: operatorLabel
120 width: units.dp(2)101 width: units.gu(2)
121 anchors.verticalCenter: parent.verticalCenter102 anchors.verticalCenter: parent.verticalCenter
122 font.pixelSize: FontUtils.sizeToPixels("medium")103 font.pixelSize: FontUtils.sizeToPixels("medium")
123 color: "#FEFEFE"104 color: "#FEFEFE"
124 text: root.operation105 text: root.operation
125 font.family: "Ubuntu"
126 }106 }
127 Label {107 Label {
128 id: formulaLabel108 id: formulaLabel
@@ -132,7 +112,7 @@
132 property bool isLast: root.isLast112 property bool isLast: root.isLast
133113
134 objectName: "formulaLabel"114 objectName: "formulaLabel"
135 width: parent.width / 2115 width: parent.width / 1.5
136 color: numbersColor116 color: numbersColor
137 anchors.bottom: parent.bottom117 anchors.bottom: parent.bottom
138 font.pixelSize: numbersHeight118 font.pixelSize: numbersHeight
@@ -140,7 +120,6 @@
140 horizontalAlignment: Text.AlignRight120 horizontalAlignment: Text.AlignRight
141 // If is a new calculation or if last calculation as been deleted print 0, else the number121 // If is a new calculation or if last calculation as been deleted print 0, else the number
142 text: ((isLast && !newCalculation) || (root.numbers === "" && formulaView.headerItem.state !== "newPush")) ? "0" : root.numbers122 text: ((isLast && !newCalculation) || (root.numbers === "" && formulaView.headerItem.state !== "newPush")) ? "0" : root.numbers
143 font.family: "Ubuntu"
144 }123 }
145 }124 }
146}125}
147126
=== modified file 'Simple/KeyboardButton.qml'
--- Simple/KeyboardButton.qml 2013-06-11 19:33:52 +0000
+++ Simple/KeyboardButton.qml 2013-09-11 10:39:56 +0000
@@ -46,7 +46,6 @@
46 anchors.centerIn: parent46 anchors.centerIn: parent
47 color: "#7474AC"47 color: "#7474AC"
48 font.pixelSize: (calcGridUnit*3)48 font.pixelSize: (calcGridUnit*3)
49 font.family: "Ubuntu"
50 font.bold: true49 font.bold: true
51 }50 }
5251
5352
=== modified file 'Simple/Screen.qml'
--- Simple/Screen.qml 2013-09-10 17:00:58 +0000
+++ Simple/Screen.qml 2013-09-11 10:39:56 +0000
@@ -30,10 +30,10 @@
3030
31 property var ops31 property var ops
32 property bool newCalculation: false32 property bool newCalculation: false
33 property bool labelVisible: false
33 signal useAnswer(string answerToUse, string formulaData)34 signal useAnswer(string answerToUse, string formulaData)
34 signal labelTextUpdated(int idx, string newText)35 signal labelTextUpdated(int idx, string newText)
35 signal mainLabelUpdated(int idx, string newText)36 signal mainLabelUpdated(int idx, string newText)
36 signal dateUpdate(int idx)
37 signal removeItem()37 signal removeItem()
3838
39 Item {39 Item {
@@ -62,7 +62,6 @@
62 color: "#9094AA"62 color: "#9094AA"
63 text: _content.x > root.width / 3 ? "Release To Delete" : "Pull To Delete"63 text: _content.x > root.width / 3 ? "Release To Delete" : "Pull To Delete"
64 font.italic: true64 font.italic: true
65 font.family: "Ubuntu"
66 }65 }
67 }66 }
68 }67 }
@@ -94,7 +93,6 @@
94 color: "#9094AA"93 color: "#9094AA"
95 text: _content.x < -root.width / 3 ? "Release To Delete" : "Pull To Delete"94 text: _content.x < -root.width / 3 ? "Release To Delete" : "Pull To Delete"
96 font.italic: true95 font.italic: true
97 font.family: "Ubuntu"
98 }96 }
99 }97 }
100 }98 }
@@ -114,7 +112,6 @@
114 Text {112 Text {
115 width: parent.width113 width: parent.width
116 horizontalAlignment: Text.AlignHCenter114 horizontalAlignment: Text.AlignHCenter
117 font.family: "Ubuntu"
118 color: "#FFFFFF"115 color: "#FFFFFF"
119116
120 text: i18n.tr("Delete this calculation?")117 text: i18n.tr("Delete this calculation?")
@@ -145,28 +142,11 @@
145 id: inputs142 id: inputs
146 anchors.top: parent.top143 anchors.top: parent.top
147 anchors.topMargin: units.gu(2)144 anchors.topMargin: units.gu(2)
148 width: parent.width - units.gu(4)145 width: parent.width - units.gu(3)
149 anchors.centerIn: parent146 anchors.centerIn: parent
150147
151 // Every five minutes update date label148 //Edit Button icon and time in parent line
152 Timer {149 Item {
153 interval: 300000
154 repeat: true
155 running: true
156 onTriggered: root.dateUpdate(index)
157 }
158
159 Text {
160 id: dateLabel
161 width: parent.width
162 color: "#9094AA"
163 text: dateText
164 font.italic: true
165 font.family: "Ubuntu"
166 }
167
168 //Edit Button icon in parent line
169 Row{
170 id: row150 id: row
171 height: units.gu(4)151 height: units.gu(4)
172 width: parent.width152 width: parent.width
@@ -185,12 +165,13 @@
185 onClicked: {165 onClicked: {
186 title.focus = true;166 title.focus = true;
187 title.forceActiveFocus();167 title.forceActiveFocus();
168 labelVisible = true
188 calcKeyboardVisible = false;169 calcKeyboardVisible = false;
189 }170 }
190 }171 }
191 }172 }
192 Item {173 Item {
193 width: parent.width174 width: parent.width / 2
194 height: parent.height175 height: parent.height
195176
196 TextField {177 TextField {
@@ -198,6 +179,7 @@
198 objectName: "title"179 objectName: "title"
199 width: parent.width180 width: parent.width
200 anchors.verticalCenter: parent.verticalCenter181 anchors.verticalCenter: parent.verticalCenter
182 x: units.gu(3)
201 // removes ubuntu shape183 // removes ubuntu shape
202 style: TextFieldStyle {184 style: TextFieldStyle {
203 background: Item {}185 background: Item {}
@@ -208,15 +190,20 @@
208 hasClearButton: false190 hasClearButton: false
209 font.pixelSize: FontUtils.sizeToPixels("medium")191 font.pixelSize: FontUtils.sizeToPixels("medium")
210192
193 maximumLength: 20;
194
211 onActiveFocusChanged: {195 onActiveFocusChanged: {
212 if (title.activeFocus)196 if (title.activeFocus) {
213 calcKeyboardVisible = false197 labelVisible = true;
198 calcKeyboardVisible = false;
199 }
214 }200 }
215201
216 InverseMouseArea {202 InverseMouseArea {
217 onClicked: {203 onClicked: {
218 title.focus = false;204 title.focus = false;
219 mouse.accepted = false;205 mouse.accepted = false;
206 labelVisible = false;
220 calcKeyboardVisible = true;207 calcKeyboardVisible = true;
221 }208 }
222 anchors.fill: parent;209 anchors.fill: parent;
@@ -226,14 +213,24 @@
226 }213 }
227214
228 Image {215 Image {
229 visible: title.focus216 visible: labelVisible
230 anchors.bottom: parent.bottom217 anchors.bottom: parent.bottom
218 x: units.gu(3)
231 source: Qt.resolvedUrl("images/dot.png")219 source: Qt.resolvedUrl("images/dot.png")
232 fillMode: Image.Tile220 fillMode: Image.Tile
233 width: parent.width-units.gu(1)221 width: parent.width - units.gu(1.5)
234 height: units.gu(1)/2222 height: units.gu(0.5)
235 }223 }
236 }224 }
225
226 Label {
227 id: dateLabel
228 height: parent.height
229 anchors.right: parent.right
230 color: "#9094AA"
231 text: dateText
232 font.capitalization: Font.AllUppercase
233 }
237 }234 }
238235
239 Repeater{236 Repeater{
240237
=== modified file 'Simple/SimplePage.qml'
--- Simple/SimplePage.qml 2013-09-10 17:00:58 +0000
+++ Simple/SimplePage.qml 2013-09-11 10:39:56 +0000
@@ -20,7 +20,6 @@
20import Ubuntu.Components 0.120import Ubuntu.Components 0.1
21import "../engine.js" as CALC21import "../engine.js" as CALC
22import "../formula.js" as F22import "../formula.js" as F
23import "../dateutils.js" as DateUtils
2423
25Page {24Page {
2625
@@ -139,7 +138,7 @@
139 if (memory.get(0).mainLabel.length === 0)138 if (memory.get(0).mainLabel.length === 0)
140 memory.get(0).mainLabel = '';139 memory.get(0).mainLabel = '';
141 memory.get(0).isLastItem = false140 memory.get(0).isLastItem = false
142 memory.get(0).dateText = i18n.tr("A few seconds ago...")141 memory.get(0).dateText = Qt.formatDateTime(currentDate, i18n.tr("dd MMM yy, hh:mm"))
143 memory.get(0).timeStamp = currentDate.getTime()142 memory.get(0).timeStamp = currentDate.getTime()
144 memory.setProperty(0, "timeStamp", currentDate.getTime());143 memory.setProperty(0, "timeStamp", currentDate.getTime());
145 memory.insert(0,{'dbId': -1, 'dateText': "", 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true, 'mainLabel': ''});144 memory.insert(0,{'dbId': -1, 'dateText': "", 'operators': [{_text:'', _operation:'', _number:''}], 'isLastItem': true, 'mainLabel': ''});
@@ -149,11 +148,13 @@
149 }148 }
150 }149 }
151150
152 function showError() {151
153 animateError.start()152// Only for Scientific Calculator
154 }153// function showError() {
155154// animateError.start()
156 PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100}155// }
156
157// PropertyAnimation {id: animateError; target: formulaView; properties: "color"; from: "#FFA0A0"; to: "#FFFFFF"; duration: 100}
157158
158 remove: Transition{159 remove: Transition{
159 NumberAnimation {property: "opacity"; to: 0; duration: 200 }160 NumberAnimation {property: "opacity"; to: 0; duration: 200 }
@@ -196,16 +197,6 @@
196 memory.get(index).mainLabel = newText;197 memory.get(index).mainLabel = newText;
197 }198 }
198199
199 // Update date label
200 onDateUpdate: {
201 // If is in database
202 if (memory.get(index).dbId !== -1)
203 memory.get(index).dateText = DateUtils.formatRelativeTime(i18n, storage.fromIdToDate(memory.get(index).dbId));
204 // If is in memory but not in database
205 else if (memory.get(index).timeStamp)
206 memory.get(index).dateText = DateUtils.formatRelativeTime(i18n, memory.get(index).timeStamp);
207 }
208
209 onLabelTextUpdated: {200 onLabelTextUpdated: {
210 if(index === 0){201 if(index === 0){
211 screenFormula[idx]._text = newText;202 screenFormula[idx]._text = newText;
212203
=== modified file 'Storage.qml'
--- Storage.qml 2013-08-29 13:15:11 +0000
+++ Storage.qml 2013-09-11 10:39:56 +0000
@@ -18,7 +18,6 @@
1818
19import QtQuick 2.019import QtQuick 2.0
20import QtQuick.LocalStorage 2.020import QtQuick.LocalStorage 2.0
21import "./dateutils.js" as DateUtils
2221
23Item {22Item {
24 property var db: null23 property var db: null
@@ -83,7 +82,7 @@
83 for(var i=res.rows.length - 1; i >= 0; i--){82 for(var i=res.rows.length - 1; i >= 0; i--){
84 var obj = JSON.parse(res.rows.item(i).calc);83 var obj = JSON.parse(res.rows.item(i).calc);
85 obj.dbId = res.rows.item(i).id;84 obj.dbId = res.rows.item(i).id;
86 obj.dateText = DateUtils.formatRelativeTime(i18n, res.rows.item(i).insertDate);85 obj.dateText = Qt.formatDateTime(parseDate(res.rows.item(i).insertDate), i18n.tr("dd MMM yy, hh:mm"))
8786
88 if (!('mainLabel' in obj))87 if (!('mainLabel' in obj))
89 obj.mainLabel = ''88 obj.mainLabel = ''
@@ -94,6 +93,10 @@
94 );93 );
95 }94 }
9695
96 function parseDate(dateAsStr) {
97 return new Date(dateAsStr);
98 }
99
97 function saveCalculations(calculations){100 function saveCalculations(calculations){
98 openDB();101 openDB();
99 var res;102 var res;
100103
=== modified file 'bignumber.js'
--- bignumber.js 2013-07-16 17:28:19 +0000
+++ bignumber.js 2013-09-11 10:39:56 +0000
@@ -55,8 +55,9 @@
55 TO_EXP_NEG = -7, // 0 to -MAX55 TO_EXP_NEG = -7, // 0 to -MAX
5656
57 // The exponent value at and above which toString returns exponential notation.57 // The exponent value at and above which toString returns exponential notation.
58 // Number type: 2158 // Number type: 11
59 TO_EXP_POS = 21, // 0 to MAX59 // Default: 21
60 TO_EXP_POS = 11, // 0 to MAX
6061
61 // RANGE : [MIN_EXP, MAX_EXP]62 // RANGE : [MIN_EXP, MAX_EXP]
6263
@@ -158,9 +159,9 @@
158 if ( j = new RegExp( '^' + i + '(?:\\.' + i + ')?$', 'i' ).test(n) ) {159 if ( j = new RegExp( '^' + i + '(?:\\.' + i + ')?$', 'i' ).test(n) ) {
159160
160 if ( isNum ) {161 if ( isNum ) {
161 if ( n.replace('.', '').length > 15 ) {162 if ( n.replace('.', '').length > 11 ) {
162163
163 // 'new BigNumber() number type has more than 15 significant digits: {n}'164 // 'new BigNumber() number type has more than 11 significant digits: {n}'
164 ifExceptionsThrow( n, 0 )165 ifExceptionsThrow( n, 0 )
165 }166 }
166167
@@ -230,10 +231,10 @@
230 i = n.length231 i = n.length
231 }232 }
232233
233 // Disallow numbers over 15 digits if number type.234 // Disallow numbers over 11 digits if number type.
234 if ( b = n.length, isNum && b > 15 ) {235 if ( b = n.length, isNum && b > 11 ) {
235236
236 // 'new BigNumber() number type has more than 15 significant digits: {n}'237 // 'new BigNumber() number type has more than 11 significant digits: {n}'
237 ifExceptionsThrow( n, 0 )238 ifExceptionsThrow( n, 0 )
238 }239 }
239240
@@ -411,7 +412,7 @@
411 ( isRange ? ' non-zero' : 'n' ) + ' integer';412 ( isRange ? ' non-zero' : 'n' ) + ' integer';
412413
413 error = ( [414 error = ( [
414 method + ' number type has more than 15 significant digits',415 method + ' number type has more than 11 significant digits',
415 method + ' not a base ' + j + ' number',416 method + ' not a base ' + j + ' number',
416 method + ' base' + error,417 method + ' base' + error,
417 method + ' not a number' ][i] ||418 method + ' not a number' ][i] ||
418419
=== removed file 'dateutils.js'
--- dateutils.js 2013-07-30 17:06:03 +0000
+++ dateutils.js 1970-01-01 00:00:00 +0000
@@ -1,99 +0,0 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This file is part of ubuntu-rssreader-app.
5 *
6 * ubuntu-calculator-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * ubuntu-calculator-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19.pragma library
20
21var SECONDS_LIMIT = 60 * 1000; // used as reference
22var MINUTES_LIMIT = 60 * SECONDS_LIMIT; // print minutes up to 1h
23var HOURS_LIMIT = 12 * MINUTES_LIMIT; // print hours up to 12h
24var DAY_LIMIT = 24 * MINUTES_LIMIT; // print '<val> days ago' up to 30 days back
25var DAYS_LIMIT = 30 * DAY_LIMIT; // print '<val> days ago' up to 30 days back
26
27function parseDate(dateAsStr) {
28 return new Date(dateAsStr);
29}
30
31function formatRelativeTime(i18n, dateAsStr) {
32 // fallback if none of the other formatters matched
33 function defaultFallbackFormat(then) {
34 return Qt.formatDateTime(then, i18n.tr("MMMM d"))
35 }
36
37 // Simple matches all diffs < limit, formats using the format function.
38 function SimpleFormatter(limit, format) {
39 this.matches = function (now, then, diff) { return diff < limit }
40 this.format = format
41 }
42
43 // Matches yesterday date
44 function YesterdayFormatter() {
45 this.matches = function (now, then, diff) {
46 return diff < DAY_LIMIT && now.getDate() !== then.getDate();
47 }
48 this.format = function (now, then, diff) {
49 return i18n.tr("Yesterday at %1").arg(
50 Qt.formatDateTime(then, i18n.tr("h:mm AP")))
51 }
52 }
53
54 // Matches up to 7 days ago (formats date as a weekday + time)
55 function WeekFormatter() {
56 this.matches = function (now, then, diff) {
57 return diff < 7 * DAY_LIMIT
58 }
59 this.format = function (now, then, diff) {
60 return Qt.formatDateTime(then, i18n.tr("ddd, h:mm AP"));
61 }
62 }
63
64 // An array of formatting object processed from 0 up to a matching object.
65 // If none of the object matches a default fallback formatter will be used.
66 var FORMATTERS = [
67 new SimpleFormatter(SECONDS_LIMIT, function (now, then, diff) { return i18n.tr("A few seconds ago...") }),
68 new SimpleFormatter(MINUTES_LIMIT, function (now, then, diff) {
69 var val = Math.floor(diff / SECONDS_LIMIT)
70 return i18n.tr("%1 minute ago", "%1 minutes ago", val).arg(val)
71 }),
72 new SimpleFormatter(HOURS_LIMIT, function (now, then, diff) {
73 var val = Math.floor(diff / MINUTES_LIMIT)
74 return i18n.tr("%1 hour ago", "%1 hours ago", val).arg(val)
75 }),
76 new YesterdayFormatter(),
77 new WeekFormatter(),
78 new SimpleFormatter(DAYS_LIMIT, function (now, then, diff) {
79 var val = Math.floor(diff / DAY_LIMIT)
80 return i18n.tr("%1 day ago", "%1 days ago", val).arg(val)
81 })
82 ]
83
84 function formatDiff(now, then, diff) {
85 for (var i=0; i<FORMATTERS.length; ++i) {
86 var formatter = FORMATTERS[i]
87 if (formatter.matches(now, then, diff)) {
88 return formatter.format(now, then, diff)
89 }
90 }
91 return defaultFallbackFormat(then)
92 }
93
94 var now = new Date();
95 var then = parseDate(dateAsStr);
96 var diff = now - then;
97 var formattedDiff = formatDiff(now, then, diff);
98 return formattedDiff;
99}
1000
=== modified file 'engine.js'
--- engine.js 2013-07-16 17:28:19 +0000
+++ engine.js 2013-09-11 10:39:56 +0000
@@ -23,7 +23,9 @@
2323
24// ----------------------------------------24// ----------------------------------------
25// constants (const keyword is not working)25// constants (const keyword is not working)
26var MAX_DECIMAL = 13; // Number of maximum decimal positions26var MAX_DECIMAL = 5; // Number of maximum decimal positions
27var PRECISION = 8 // Max lenght of result in exponential mode
28var MAX_LENGHT = 100000000000 // Highest number before exponential mode
2729
28var RAD = 0, DEG = 1, GRAD = 2; //Trigonometric functions30var RAD = 0, DEG = 1, GRAD = 2; //Trigonometric functions
2931
@@ -544,27 +546,34 @@
544546
545 op: function op(type, lhs, rhs) {547 op: function op(type, lhs, rhs) {
546 if (lhs !== null) {548 if (lhs !== null) {
549 var result;
547 switch (type) {550 switch (type) {
548 case T_PLUS:551 case T_PLUS:
549 return lhs.value.plus(rhs.value);552 result = lhs.value.plus(rhs.value);
553 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
550554
551 case T_MINUS:555 case T_MINUS:
552 return lhs.value.minus(rhs.value);556 result = lhs.value.minus(rhs.value);
557 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
553558
554 case T_TIMES:559 case T_TIMES:
555 return lhs.value.times(rhs.value);560 result = lhs.value.times(rhs.value);
561 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
556562
557 case T_DIV:563 case T_DIV:
558 return lhs.value.div(rhs.value);564 result = lhs.value.div(rhs.value);
565 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
559566
560 case T_MOD:567 case T_MOD:
561 if (rhs.value === 0.)568 if (rhs.value === 0.)
562 throw new DivisionByZeroError('modulo division by zero');569 throw new DivisionByZeroError('modulo division by zero');
563570
564 return lhs.value.mod(rhs.value);571 result = lhs.value.mod(rhs.value);
572 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
565573
566 case T_POW:574 case T_POW:
567 return lhs.value.pow(rhs.value);575 result = lhs.value.pow(rhs.value);
576 return result > MAX_LENGHT ? result.toPrecision(PRECISION) : result;
568 }577 }
569578
570 // throw?579 // throw?

Subscribers

People subscribed via source and target branches