Merge lp:~nik90/ubuntu-clock-app/correct-time-locale into lp:ubuntu-clock-app

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 12
Proposed branch: lp:~nik90/ubuntu-clock-app/correct-time-locale
Merge into: lp:ubuntu-clock-app
Diff against target: 107 lines (+42/-37)
1 file modified
app/clock/Clock.qml (+42/-37)
To merge this branch: bzr merge lp:~nik90/ubuntu-clock-app/correct-time-locale
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Needs Fixing
Victor Thompson Approve
David Planella Pending
Ubuntu Clock Developers Pending
Review via email: mp+225005@code.launchpad.net

Commit message

Returns the clock time in the proper user locale.

Description of the change

Returns the clock time in the proper user locale.

By using Qt.formatTime(new Date()), we allow Qt to return the time in locale set by the user. So the clock app does not control whether it is returned in 12-hour or 24-hour, but rather the locale dictates that.

However the designers stated that they want the time to be centered in bold text while the "am/pm" text should be shown beneath it if the locale uses the 12-hour format. I used Qt.locale().pmText and Qt.locale().amText to detect if there are "am/pm" strings in the clock time and if they are present then format the time accordingly to show it as defined by the designers.

All this is done without affecting the locale set by the user.

@victor, one reason why we do is that during my discussing with david, he informed me that time in certain locales are shown as hh.mm in which cases using ":" to split the string will fail. As a result, I resorted to showing the time including the separator in one color and then showing the "am/pm" text below using the qt locale variable.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :

FAILED: Continuous integration, rev:12
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~nik90/ubuntu-clock-app/correct-time-locale/+merge/225005/+edit-commit-message

http://91.189.93.70:8080/job/ubuntu-clock-dev-ubuntu-clock-app-utopic-3.0-ci/5/
Executed test runs:
    FAILURE: http://91.189.93.70:8080/job/generic-mediumtests-utopic/724/console
    FAILURE: http://91.189.93.70:8080/job/ubuntu-clock-dev-ubuntu-clock-app-utopic-3.0-utopic-amd64-ci/5/console

Click here to trigger a rebuild:
http://91.189.93.70:8080/job/ubuntu-clock-dev-ubuntu-clock-app-utopic-3.0-ci/5/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

1. Currently the time does not show in the 12 hour locale. Please make the following change:

bzr diff
=== modified file 'app/clock/Clock.qml'
--- app/clock/Clock.qml 2014-06-30 13:39:47 +0000
+++ app/clock/Clock.qml 2014-06-30 22:42:42 +0000
@@ -95,11 +95,11 @@
                 }
                 else if(time.search(Qt.locale().amText) !== -1) {
                     // 12 hour format detected with the localised AM text
- return time.split(Qt.locale().amText)[0].slice(end-1)
+ return time.split(Qt.locale().amText)[0]
                 }
                 else {
                     // 12 hour format detected with the localised PM text
- return time.split(Qt.locale().pmText)[0].slice(end-1)
+ return time.split(Qt.locale().pmText)[0]
                 }
             }
         }

2. Each of places you check for amText/pmText would be simplified if you changed from doing this:

if (not AM and not PM)
else if (AM)
else

to be

if (AM)
else if (PM)
else // assumed to be 24 hour

3. Wouldn't it still be possible to parse the time separator and have it displayed in a different color?

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

> 1. Currently the time does not show in the 12 hour locale. Please make the
> following change:
>
> bzr diff
> === modified file 'app/clock/Clock.qml'
> --- app/clock/Clock.qml 2014-06-30 13:39:47 +0000
> +++ app/clock/Clock.qml 2014-06-30 22:42:42 +0000
> @@ -95,11 +95,11 @@
> }
> else if(time.search(Qt.locale().amText) !== -1) {
> // 12 hour format detected with the localised AM text
> - return time.split(Qt.locale().amText)[0].slice(end-1)
> + return time.split(Qt.locale().amText)[0]
> }
> else {
> // 12 hour format detected with the localised PM text
> - return time.split(Qt.locale().pmText)[0].slice(end-1)
> + return time.split(Qt.locale().pmText)[0]
> }
> }
> }

Are you sure? The slice(end-1) is only there to remove the gap between "01:00" and "AM" in the string "01:00 AM" which causes the text to be off centered. So after splitting it and taking [0], the string is "01:00 " with a space at the end which I then slice of.

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

> 2. Each of places you check for amText/pmText would be simplified if you
> changed from doing this:
>
> if (not AM and not PM)
> else if (AM)
> else
>
> to be
>
> if (AM)
> else if (PM)
> else // assumed to be 24 hour
>

Done

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

>3. Wouldn't it still be possible to parse the time separator and have it displayed in a different >color?

I am unable to think of a logic which will work across all locales. Previously we used the colon ":" to do the splitting which fails in other locales. May be we can come up with a regex expression which doesn't depend on the time separator.

Somehow I feel this solution in the MP is more fail proof due to its simplicity while we stand on the shoulders of Qt locale(). Surprisingly Qt.locale() does not have a property for time separator. Otherwise I would have used that.

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
Victor Thompson (vthompson) wrote :

> > 1. Currently the time does not show in the 12 hour locale. Please make the
> > following change:
> >
> > bzr diff
> > === modified file 'app/clock/Clock.qml'
> > --- app/clock/Clock.qml 2014-06-30 13:39:47 +0000
> > +++ app/clock/Clock.qml 2014-06-30 22:42:42 +0000
> > @@ -95,11 +95,11 @@
> > }
> > else if(time.search(Qt.locale().amText) !== -1) {
> > // 12 hour format detected with the localised AM text
> > - return time.split(Qt.locale().amText)[0].slice(end-1)
> > + return time.split(Qt.locale().amText)[0]
> > }
> > else {
> > // 12 hour format detected with the localised PM text
> > - return time.split(Qt.locale().pmText)[0].slice(end-1)
> > + return time.split(Qt.locale().pmText)[0]
> > }
> > }
> > }
>
> Are you sure? The slice(end-1) is only there to remove the gap between "01:00"
> and "AM" in the string "01:00 AM" which causes the text to be off centered. So
> after splitting it and taking [0], the string is "01:00 " with a space at the
> end which I then slice of.

Positive. "end" is not defined:

file:///home/victor/Development/correct-time-locale/app/clock/Clock.qml:93: ReferenceError: end is not defined

Could you simply do this to trim the whitespace:

bzr diff
=== modified file 'app/clock/Clock.qml'
--- app/clock/Clock.qml 2014-07-01 10:47:41 +0000
+++ app/clock/Clock.qml 2014-07-01 11:17:00 +0000
@@ -90,11 +90,11 @@
             text: {
                 if (time.search(Qt.locale().amText) !== -1) {
                     // 12 hour format detected with the localised AM text
- return time.split(Qt.locale().amText)[0].slice(end-1)
+ return time.split(Qt.locale().amText)[0].trim()
                 }
                 else if (time.search(Qt.locale().pmText) !== -1) {
                     // 12 hour format detected with the localised PM text
- return time.split(Qt.locale().pmText)[0].slice(end-1)
+ return time.split(Qt.locale().pmText)[0].trim()
                 }
                 else {
                     // 24-hour format detected, return full time string

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

> > > 1. Currently the time does not show in the 12 hour locale. Please make the
> > > following change:
> > >
> > > bzr diff
> > > === modified file 'app/clock/Clock.qml'
> > > --- app/clock/Clock.qml 2014-06-30 13:39:47 +0000
> > > +++ app/clock/Clock.qml 2014-06-30 22:42:42 +0000
> > > @@ -95,11 +95,11 @@
> > > }
> > > else if(time.search(Qt.locale().amText) !== -1) {
> > > // 12 hour format detected with the localised AM text
> > > - return time.split(Qt.locale().amText)[0].slice(end-1)
> > > + return time.split(Qt.locale().amText)[0]
> > > }
> > > else {
> > > // 12 hour format detected with the localised PM text
> > > - return time.split(Qt.locale().pmText)[0].slice(end-1)
> > > + return time.split(Qt.locale().pmText)[0]
> > > }
> > > }
> > > }
> >
> > Are you sure? The slice(end-1) is only there to remove the gap between
> "01:00"
> > and "AM" in the string "01:00 AM" which causes the text to be off centered.
> So
> > after splitting it and taking [0], the string is "01:00 " with a space at
> the
> > end which I then slice of.
>
> Positive. "end" is not defined:
>
> file:///home/victor/Development/correct-time-locale/app/clock/Clock.qml:93:
> ReferenceError: end is not defined
>
> Could you simply do this to trim the whitespace:
>

Wasn't aware of the trim() function. Thnx. I did that in the latest rev

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

One more thing, I reduced the time period font size to 12 dp which corresponds to small fontSize as specified in the design spec at https://docs.google.com/presentation/d/1Kkl7xT8BYo9mT8i3IXh6rPrDlNg6cBxTajahlRYIGlI/edit#slide=id.g35b3f34e6_00

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
Victor Thompson (vthompson) wrote :

IMO 12 dp is far too small. It appears even smaller than the design spec: http://i.imgur.com/WyYBq3T.png

review: Approve
Revision history for this message
Victor Thompson (vthompson) wrote :

16 dp might be closer for the am/pm text, but other than that this looks good!

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

> IMO 12 dp is far too small. It appears even smaller than the design spec:
> http://i.imgur.com/WyYBq3T.png

I agree that 16 dp would be much better. But if you look at the word "Location" in the screenshot, it has a font size "Medium". So the "am/pm" text should be appear smaller than that. Somehow the designers say that the font size will be correct when viewed on the device. I am not so sure if things will improve on the device.

However let's come back to the font sizes through out the app once we get clock app running on the device.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/clock/Clock.qml'
2--- app/clock/Clock.qml 2014-06-26 11:25:17 +0000
3+++ app/clock/Clock.qml 2014-07-01 12:08:31 +0000
4@@ -66,8 +66,8 @@
5 }
6
7 PropertyAnimation {
8- target: _digitalTimeRow
9- property: "digitalTimeFontPixelSize"
10+ target: _digitalTime
11+ property: "font.pixelSize"
12 to: units.dp(62)
13 duration: 900
14 }
15@@ -75,52 +75,57 @@
16 PropertyAnimation {
17 target: _digitalTimePeriod
18 property: "font.pixelSize"
19- to: units.dp(24)
20+ to: units.dp(12)
21 duration: 900
22 }
23 }
24
25- Row {
26- id: _digitalTimeRow
27- property real digitalTimeFontPixelSize: units.dp(1)
28- anchors {
29- centerIn: parent
30- }
31-
32- Label {
33- id: _digitalTimeHours
34- color: UbuntuColors.midAubergine
35- font.pixelSize: _digitalTimeRow.digitalTimeFontPixelSize
36- text: time.split(":")[0]
37- }
38-
39- Label {
40- id: _digitalTimeDivider
41- color: UbuntuColors.coolGrey
42- font.pixelSize: _digitalTimeRow.digitalTimeFontPixelSize
43- text: ":"
44- }
45-
46- Label {
47- id: _digitalTimeMinutes
48- color: UbuntuColors.midAubergine
49- font.pixelSize: _digitalTimeRow.digitalTimeFontPixelSize
50- text: time.split(":")[1].split(" ")[0]
51+ Label {
52+ id: _digitalTime
53+
54+ anchors.centerIn: parent
55+
56+ color: UbuntuColors.midAubergine
57+ font.pixelSize: units.dp(1)
58+ text: {
59+ if (time.search(Qt.locale().amText) !== -1) {
60+ // 12 hour format detected with the localised AM text
61+ return time.split(Qt.locale().amText)[0].trim()
62+ }
63+ else if (time.search(Qt.locale().pmText) !== -1) {
64+ // 12 hour format detected with the localised PM text
65+ return time.split(Qt.locale().pmText)[0].trim()
66+ }
67+ else {
68+ // 24-hour format detected, return full time string
69+ return time
70+ }
71 }
72 }
73
74 Label {
75 id: _digitalTimePeriod
76- property string period: time.split(":")[1].split(" ")[1] !== undefined
77- ? time.split(":")[1].split(" ")[1] : ""
78- anchors {
79- top: _digitalTimeRow.bottom
80- horizontalCenter: parent.horizontalCenter
81- }
82+
83+ anchors.top: _digitalTime.bottom
84+ anchors.horizontalCenter: parent.horizontalCenter
85+
86 color: UbuntuColors.midAubergine
87 font.pixelSize: units.dp(1)
88- visible: period !== ""
89- text: period
90+ visible: text !== ""
91+ text: {
92+ if (time.search(Qt.locale().amText) !== -1) {
93+ // 12 hour format detected with the localised AM text
94+ return Qt.locale().amText
95+ }
96+ else if (time.search(Qt.locale().pmText) !== -1) {
97+ // 12 hour format detected with the localised PM text
98+ return Qt.locale().pmText
99+ }
100+ else {
101+ // 24-hour format detected
102+ return ""
103+ }
104+ }
105 }
106 }
107 }

Subscribers

People subscribed via source and target branches