Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 11:54 AM   PM User | #1
andreii_1989
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
andreii_1989 is an unknown quantity at this point
How to tweak Windows 7 clock gadget to make it 24 hours?

Hi guys
I've recently discovered and fell in love with 24 hour analog clocks and watches, and I'd like to tweak the standard clock gadget on windows 7 so that, basically, the hour hand would rotate at half its usual speed.
I've done a little reading on gadgets and have found it easy to change the gadget graphically (I've swapped the background image to a 24 hour face and have modified the hour and minute hands). However, I've never worked with javascript before, but looking into the "clock.js" file I get the feeling that I would only need to change a little bit of the "timePerInterval()" function, but I have no idea what.
What do you guys think? Is it possible to edit it as I want? I hope it's nothing too complex.

Thanks for the help!

P.S. The file "clock.js" I mentioned lies in "C:\Program Files\Windows Sidebar\Gadgets\Clock.Gadget\en-US\js"

P.P.S. I would have copied the part of the script that I was referring to, but I don't know if that's alright. Is it frowned upon, what with copyright restrictions, or is it ok if it's just a part of the file and not the entire script?

Last edited by andreii_1989; 02-27-2013 at 09:36 AM..
andreii_1989 is offline   Reply With Quote
Old 02-27-2013, 07:15 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You're right, you should tweak the clock.js

Try this
Code:
////////////////////////////////////////////////////////////////////////////////
//
// calculate current time
//
////////////////////////////////////////////////////////////////////////////////
function timePerInterval()
{
	refreshDate();
	with (date)
	{
		hours = getHours();
		minutes = getMinutes();
		seconds = getSeconds();
	}
	
	var rotationHours = hours;

	// if (hours > 12)
	// {
		// rotationHours = hours - 12;
	// }
	
	h.Rotation = (rotationHours * 15) + (minutes / 4);
	m.Rotation = (minutes * 6) + (seconds / 10);
		
	if (mySetting.secondsEnabled)
	{
		s.Rotation = (seconds * 6);

		var secondOffset = secondTimeOffset();
			
		if (secondOffset > 0)
		{
			newTimeOut = setTimeout("timePerInterval()", secondOffset);
		}
		else
		{
			timePerInterval();
		}
	}
	else
	{
		var minuteOffset = minuteTimeOffset();
		
		if (minuteOffset > 0)
		{
			newTimeOut = setTimeout("timePerInterval()", minuteOffset);
		}
		else
		{
			timePerInterval();
		}
	}
}
Basically I have removed (commented) the lines to subtract 12 from hours greater than 12, because it is not needed any more. And then I have changed the line to calculate the rotation angle of the hour hand to half the usual speed (15 degrees per hour and 1 degree every 4 minutes instead of 30 degrees per hour and 1 degree every two minutes)
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
andreii_1989 (02-27-2013)
Old 02-27-2013, 09:34 AM   PM User | #3
andreii_1989
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
andreii_1989 is an unknown quantity at this point
This is exactly what I was looking for, devnull69. I had also realised that I needed to remove the "if (hours>12)" clause but I completely failed to see that the "h.Rotation = (rotationHours * 30) + (minutes / 2)" bit was meant as degree positioning. It's so obvious now that you've explained it!
Thank you very much for the help!
andreii_1989 is offline   Reply With Quote
Reply

Bookmarks

Tags
24 hour clock, windows 7

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:29 AM.


Advertisement
Log in to turn off these ads.