Moodle Server Time Block

Do you ever wonder what the real time is on your Moodle server? Many people have downloaded the Analog Clock block for Moodle thinking that this will show the time on their Moodle server only to find out that it shows the local time on their personal computer. How many of you have set a quiz or assignment to close at a certain time and suddenly students are being told that they are out of time to finish the test because the time on the server is incorrect. I have had teachers totally freak out, and rightly so, when Moodle shuts a test down during the middle of class because the server time was off a bit.

Moodle Server Clock PictureI recently was asked by another district if I knew of a module that would just show the actual time on the server with a basic clock. Well, I went to the modules and plugins database on the moodle.org site and downloaded all three of the server clocks. I installed them all one by one and viewed the output on my live server. I liked features of all three but didn't like any one completely. So, being open source, I modified the code to come up with something that I liked. The pic to the right is how it looks on our servers current theme. You can download the zip file of this slightly modified version if you would like to try it out. Just add the file to your blocks folder in your Moodle installation and unzipthe contents. To activate the module just go to your "Site administration" block and click on the "Notifications" link. On older versions just go to the main admin page to activate the block.

Okay, now I will give you a brief tutorial on how to make a couple of modifications to customize it for your server. It comes in a single file that is relatively short. The items that can be modified are:

  1. Block Title
  2. The words "Current Server Time"
  3. Adjust the time for a different time zone if your server is hosted in another part of the world.

To modify the block title, open up the block_server_clock.php file and go to line 9 of the code that looks like this:

$this->title = "Moodle Server Clock";

Just change the name between the quotes and that will change the clock title.

 

To change the words just above the actual clock, go to line  of the  block_server_clock.php file that looks like this:

<p style='text-align: center;'><b>Current Server Time</b><br><br><b> <span id='servertime'></span></b></p>

and just change the text between the <b> and </b> tags where it says "Current Server Time" to whatever you like.

 

If your server lives in a different "neck of teh woods" then you want it to show the local time where your students reside, assuming you don't have students from all over the world, then this may not be what you are looking for. To change the time to a different time zone just takes a bit of basic math. First figure out how many hours you are ahead or behind the location where your server resides. In the case of this site, my server resides somewhere that is one hour ahead of me so I need to back the clock up an hour so it shows my current locations time. To do this I need to know how many seconds there are in an hour. There happens to be 3600 seconds in an hour. Now that I know the number that I need to work with I open up my  block_server_clock.php file and find line 33 that says:

var currenttime = '". date('F d, Y H:i:s', time())."' //PHP method of getting server date

Now the change that needs to take place is in between the last two brackets after the word "time." After the modifications line 33 should look something like this:

var currenttime = '". date('F d, Y H:i:s', time() - 3600)."' //PHP method of getting server date

Notice the "- 3600". This is telling the script to grab the current time on the server and then subtract 3600 seconds, one hour, from the time before it passes the time onto the javascript clock that actually does the work in the body of the block. You can add or subtract as many seconds as you need to get the proper time.

The last thing you could possibly do is  to add a class to the paragraph tag in line 70 so you canuse your style sheet to change the appearance of the text on the fly. I hope you find this little tidbit of trivia useful. Time for this guy to hit the sack.

Trackback URL for this post:

http://orwinconsulting.com/trackback/46
No votes yet
Anonymous
Afternoon the moodle server
Afternoon the moodle server clock is bad, one our late, as the reality.
German
Awesome! I needed this.
Awesome! I needed this. Thank you ;)