Need some help with this script. When I run this script it works well. However, at the end of the day it freezes at evening. The following day when I run the script it starts at evening, and it should start by saying morning. Am I missing something?

string timeOfDay;

dialog getTimeOfDay (out string TOD) {
			string time = formatDate(now(), "HHmm");
			if (time =~ '(?:[0-1]) (?:[0-1]) (?:[0-5]) (?:[0-9])'){
					TOD = "morning";
			}//Closes Morning String
			elif (time =~ '(?:1) (?:[2-6]) (?:[-5]) (?:[0-9])') {
					TOD = "afternoon";
			}//Closes Afternoon String
			else TOD = "evening";

call getTimeOfDay(out timeOfDay);

This should do it!
Good day to you...

<html>
<head>
<title><!-- Sample --></title>
<script type="text/javascript">
<!-- BEGIN HIDING
var today = new Date();
Date.prototype.greet = function()
{ hour = today.getHours();
  minute = today.getMinutes();
  second = today.getSeconds();
var greetings = '';  
if (( hour >= 7 ) && ( hour < 12 )) { greetings = 'GoodMoning! '; }
else if (( hour >= 12 ) && ( hour < 17 )) { greetings = 'GoodAfternoon! '; }   
else { greetings = 'GoodEvening! '; }
var apos = ( hour < 12 ) ? ' am' : ' pm';  
hour = ( hour >= 13 ) ? hour -12 : hour;
  hour = ( hour == 0 ) ? 12 : hour;

  minute = ( minute < 10 ? '0' : '' ) + minute;
  second = ( second < 10 ? '0' : '' ) + second;   
return greetings + '\nThe Time is now ' + hour + ':' + minute + ':' + second + apos;
}

window.onload = function() {
alert( today.greet() );
}
// DONE HIDING -->
</script>
</head>
<body>
<!-- ///////////////*\\\\\\\\\\\\\\ -->
</body>
</html>
Comments
nice script...
This article has been dead for over six months. Start a new discussion instead.