Slight problem with the Silverlight clock sample
|
The clock sample that comes with the Silverlight 1.1 SDK is an excellent example that demonstrates many basic techniques in Silverlight development. However, the clock itself actually isn't accurate. This problem is really just a technicality and doesn't negatively impact the goal of the sample, which is to demonstrate Silverlight programming techniques. But I couldn't help but notice this problem and figured I'd share it with you, mostly as an amusing afterthought. (I'm assuming here you're familiar with the sample; if not, check out the Silverlight article from this week for more information.) With a real clock, you would want the minute hand to be perfectly aligned to each minute when the second hand is exactly straight up. (Similarly with the hour vs minute hands.) Suppose the time is 11:59:30. In a real clock, at this point the minute hand should be half a minute away from straight up. But if you start the clock sample at 11:59:30, the program will set the minute hand to precisely 59 minutes. When will the minute hand be pointing straight up? Not at 12:00:00, but one minute after the program began, at 12:00:30. Oops! Try it for yourself. Replace this line: System.DateTime date = DateTime.Now; with this: System.DateTime date = new DateTime(2007, 8, 14, 11, 59, 30, DateTimeKind.Local); This will set the time to be 11:59:30. (The date will be August 14, 2007, but that's not used in this program, so really any date will do.) Now run the program and watch very carefully as the second hand reaches the top, 30 seconds in, when the time is supposedly exactly 12:00:00. The minute hand has only moved a half minute and isn't yet pointing straight up. Here's what I see:
Then when another thirty seconds passes so we're a minute into the program, the time is 12:00:30, and only then the minute hand is pointing straight up. Here's what I see on mine:
So the clock isn't actually accurate in this regard. The program does, however, successfully demonstrate many interesting aspects of Silverlight development. It would certainly be possible, though, to fix the problem using some rather simple calculations; I'll leave that part up to you. |




Comments (2)
thanks for the GREAT post! Very useful...
Posted by Whatever-ishere | November 21, 2007 6:35 PM
Very interesting... as always! Cheers from -Switzerland-.
Posted by Dog training | November 25, 2007 2:56 PM