[gnome-clocks] Do not use floating point formatting
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Do not use floating point formatting
- Date: Sun, 3 Mar 2013 22:14:57 +0000 (UTC)
commit 3eaefa03d0f18619aa197e4792ed9ffb4cfbdce1
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Mar 3 23:07:54 2013 +0100
Do not use floating point formatting
We always want the dot for subsecond stuff, not comma depending on the
locale.
src/stopwatch.vala | 30 ++++++++++++++++++------------
src/timer.vala | 8 +++++---
src/utils.vala | 13 +++++++------
3 files changed, 30 insertions(+), 21 deletions(-)
---
diff --git a/src/stopwatch.vala b/src/stopwatch.vala
index 4fe5c0d..f742be5 100644
--- a/src/stopwatch.vala
+++ b/src/stopwatch.vala
@@ -156,13 +156,16 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
int h;
int m;
- double s;
- Utils.time_to_hms (e, out h, out m, out s);
+ int s;
+ double r;
+ Utils.time_to_hms (e, out h, out m, out s, out r);
+ int cs = (int) (r * 100);
int split_h;
int split_m;
- double split_s;
- Utils.time_to_hms (split, out split_h, out split_m, out split_s);
+ int split_s;
+ Utils.time_to_hms (split, out split_h, out split_m, out split_s, out r);
+ int split_cs = (int) (r * 100);
var n_label = "<span color='dimgray'> %d </span>".printf (current_lap);
@@ -170,16 +173,16 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
string split_label;
if (split_h > 0) {
- split_label = "%i∶%02i∶%05.2f".printf (split_h, split_m, split_s);
+ split_label = "%i∶%02i∶%02i.%i".printf (split_h, split_m, split_s, split_cs);
} else {
- split_label = "%02i∶%05.2f".printf (split_m, split_s);
+ split_label = "%02i∶%02i.%i".printf (split_m, split_s, split_cs);
}
string tot_label;
if (h > 0) {
- tot_label = "%i∶%02i∶%05.2f".printf (h, m, s);
+ tot_label = "%i∶%02i∶%02i.%i".printf (h, m, s, cs);
} else {
- tot_label = "%02i∶%05.2f".printf (m, s);
+ tot_label = "%02i∶%02i.%i".printf (m, s, cs);
}
Gtk.TreeIter i;
@@ -208,16 +211,19 @@ public class MainPanel : Gtk.Box, Clocks.Clock {
private bool update_time_label () {
int h = 0;
int m = 0;
- double s = 0;
+ int s = 0;
+ double r = 0;
if (state != State.RESET) {
- Utils.time_to_hms (timer.elapsed (), out h, out m, out s);
+ Utils.time_to_hms (timer.elapsed (), out h, out m, out s, out r);
}
+ int ds = (int) (r * 10);
+
// Note that the format uses unicode RATIO character
if (h > 0) {
- time_label.set_text ("%i∶%02i∶%04.1f".printf (h, m, s));
+ time_label.set_text ("%i∶%02i∶%02i.%i".printf (h, m, s, ds));
} else {
- time_label.set_text ("%02i∶%04.1f".printf (m, s));
+ time_label.set_text ("%02i∶%02i.%i".printf (m, s, ds));
}
return true;
diff --git a/src/timer.vala b/src/timer.vala
index 071e5ee..d94e411 100644
--- a/src/timer.vala
+++ b/src/timer.vala
@@ -206,12 +206,14 @@ public class MainPanel : Gd.Stack, Clocks.Clock {
if (time_label.get_mapped ()) {
int h;
int m;
- double s;
- Utils.time_to_hms (t, out h, out m, out s);
+ int s;
+ double r;
+ Utils.time_to_hms (t, out h, out m, out s, out r);
// Math.ceil() because we count backwards: with 0.3 seconds
// we want to show 1 second remaining
- update_countdown_label (h, m, (int)Math.ceil(s));
+ s += (int) Math.ceil (r);
+ update_countdown_label (h, m, s);
}
}
diff --git a/src/utils.vala b/src/utils.vala
index 61a2786..50cb7ed 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -52,12 +52,13 @@ public Gdk.Pixbuf? load_image (string image) {
return null;
}
-public void time_to_hms (double t, out int h, out int m, out double s) {
- s = t;
- h = (int) s / 3600;
- s = t % 3600;
- m = (int) s / 60;
- s = s % 60;
+public void time_to_hms (double t, out int h, out int m, out int s, out double remainder) {
+ h = (int) t / 3600;
+ t = t % 3600;
+ m = (int) t / 60;
+ t = t % 60;
+ s = (int) t;
+ remainder = t - s;
}
// TODO: For now we are wrapping Gnome's clock, but we should probably
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]