Give Your Visitors a Rough Time

Share this article

Whilst out surfing the big WWW I came across Laurence Willmott project page about how people really tell the time.

When asked the time, we generally don’t need to be military accurate with our response and so don’t tend to say ‘its nine fifty three and twenty two seconds’. We generally communicate the approximate time. i.e. ‘its nearly ten’ or ‘its just gone half past three’. Yet on the web, time is generally shown as ’12:24:13 AM’, or similar — not very visitor friendly.

This gave me an idea: what about doing a similar thing on a web site. i.e. showing the time as you would say it. So, without further ado I give you: “RoughTime” a bit of PHP code to express the time — roughly.

< ?php
$hour = (int) date('g');
$minute = (int) date('i');

	case ($minute >=0 && $minute <5):
		$roughTime = numberToWord($hour).'-ish';
	case ($minute >=5 && $minute <14):
		$roughTime = 'just gone '.numberToWord($hour);
	case ($minute >=15 && $minute <20):
		$roughTime = 'quarter past '.numberToWord($hour);
	case ($minute >=20 && $minute <25):
		$roughTime = 'nearly half '.numberToWord($hour);
	case ($minute >=25 && $minute <35):
		$roughTime = 'half '.numberToWord($hour);
	case ($minute >=35 && $minute <40):
		$roughTime = 'just gone half '.numberToWord($hour);
	case ($minute >=40 && $minute <50):
		$roughTime = 'quarter to '.numberToWord($hour + 1);
	case ($minute >=50):
		$roughTime =  'nearly '.numberToWord($hour +1);

function numberToWord($number){
		case 1:
			$word = 'one';break;
		case 2:
			$word = 'two';break;
		case 3:
			$word = 'three';break;
		case 4:
			$word = 'four';break;
		case 5:
			$word = 'five';break;
		case 6:
			$word = 'six';break;
		case 7:
			$word = 'seven';break;
		case 8:
			$word = 'eight';break;
		case 9:
			$word = 'nine';break;
		case 10:
			$word = 'ten';break;
		case 11:
			$word = 'eleven';break;
		case 13:
			$word = 'one';break;
			$word = 'twelve';break;
	return $word;

echo 'Its '.$roughTime;

The code is deliberately in a pretty raw state, so you can adapt it to suit.

How does it work?
First off, it gets the minute and hour of the current time as integers. Next, it selects the appropriate message based on the minutes past the hour and finally sets the sets the hour number as a word.

A useful alternative to the “traditional” way of displaying time? Go on give your site visitors a rough time, you never know — they might like it.

Toby SomervilleToby Somerville
View Author
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week