01-14-2012, 03:50 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
|
OOP vs Procedural
What are the advantages of using oop over procedural ?
Take the following function, and if I were to make this into a class (which I have no idea how to yet!) what would I gain ?
This is to find out the current week number for a company financial year, 4th April 2011 being week 1
PHP Code:
<?php
date_default_timezone_set('Europe/London');
function longDate($uk_date, $sep){
list($day, $month, $year) = explode($sep, $uk_date);
$usdate = $month.'/'.$day.'/'.$year;
return date("l, F jS, Y",strtotime($usdate));
}
function getCurrentWeek($type){
$week_secs = 604800;
// uk format dd/mm/yyyy
$week1 = '04/04/2011';
list($day, $month, $year) = explode('/', $week1);
$startFinYear = gmmktime(0,0,0,$month, $day, $year);
// current unix time
$currTime = strtotime('now');
$weekDiff = floor(($currTime - $startFinYear)/$week_secs);
$timeDiff = $currTime - $startFinYear;
$shortDate = date('d/m/Y', strtotime("+" . $weekDiff . " week",$startFinYear ));
$longDate = longDate(date('d/m/Y', strtotime("+" . $weekDiff . " week",$startFinYear )), '/');
switch($type){
case 'short':
return $shortDate;
break;
case 'long' :
return $longDate;
break;
default:
return $weekDiff;
break;
}
}
echo getCurrentWeek('') . "<br />";
echo getCurrentWeek('short') . "<br />";
echo getCurrentWeek('long') . "<br />";
?>
__________________
Thanks... Simon
Sex, Drugs & Linux Rules
|
|
|