Author: mhabersack
Date: 2007-06-25 07:43:56 -0400 (Mon, 25 Jun 2007)
New Revision: 80681
Modified:
trunk/moon/ChangeLog
trunk/moon/desklet/lameclock/clock.cs
Log:
2007-06-25 Marek Habersack <[EMAIL PROTECTED]>
* desklet/lameclock/clock.cs: small modifications to the lameclock
desklet - make am/pm show up properly, use 12h clock by default
Modified: trunk/moon/ChangeLog
===================================================================
--- trunk/moon/ChangeLog 2007-06-25 11:41:33 UTC (rev 80680)
+++ trunk/moon/ChangeLog 2007-06-25 11:43:56 UTC (rev 80681)
@@ -1,3 +1,8 @@
+2007-06-25 Marek Habersack <[EMAIL PROTECTED]>
+
+ * desklet/lameclock/clock.cs: small modifications to the lameclock
+ desklet - make am/pm show up properly, use 12h clock by default.
+
2007-06-25 Larry Ewing <[EMAIL PROTECTED]>
* gtk/mopen.cs: remove useless size allocate code.
Modified: trunk/moon/desklet/lameclock/clock.cs
===================================================================
--- trunk/moon/desklet/lameclock/clock.cs 2007-06-25 11:41:33 UTC (rev
80680)
+++ trunk/moon/desklet/lameclock/clock.cs 2007-06-25 11:43:56 UTC (rev
80681)
@@ -1,5 +1,6 @@
using System.Windows;
using System;
+using System.Globalization;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
@@ -8,21 +9,39 @@
namespace Clock {
public class Display : Canvas {
- TextBlock hour, minute;
+ TextBlock hour, minute, ampm;
DateTime last = DateTime.MinValue;
+ bool isAm, use24h;
void UpdateTime ()
{
DateTime dt = DateTime.Now;
-
+
if (dt.Hour == last.Hour && dt.Minute == last.Minute)
return;
-
- if (dt.Hour != last.Hour)
- hour.Text = dt.Hour.ToString ("00");
-
+
+ if (dt.Hour != last.Hour) {
+ int h = dt.Hour;
+ if (!use24h) {
+ h %= 12;
+ if (h == 0)
+ h = 12;
+ }
+ hour.Text = h.ToString ("00");
+ }
+
minute.Text = ":" + dt.Minute.ToString ("00");
last = dt;
+
+ if (!use24h) {
+ if (isAm && dt.Hour >= 12) {
+ isAm = false;
+ ampm.Text = "pm";
+ } else if (!isAm && dt.Hour < 12) {
+ isAm = true;
+ ampm.Text = "am";
+ }
+ }
}
public void PageLoaded(object o, EventArgs e)
@@ -33,6 +52,14 @@
Storyboard sb = FindName ("run") as Storyboard;
hour = FindName ("hour") as TextBlock;
minute = FindName ("minute") as TextBlock;
+ ampm = FindName ("ampm") as TextBlock;
+
+ if (ampm != null) {
+ if (use24h)
+ ampm.Visibility = Visibility.Hidden;
+ else
+ isAm = ampm.Text.ToLower () == "am";
+ }
if (sb == null || r == null || hour == null || minute
== null){
Console.WriteLine ("Elements are missing from
the xaml file\n");
@@ -42,7 +69,6 @@
DoubleAnimation timer = new DoubleAnimation ();
sb.Children.Add (timer);
timer.Duration = new Duration (TimeSpan.FromSeconds
(0.5));
-
sb.Completed += delegate {
visible = !visible;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches