need help debugging two classes
Posted: Thu Nov 30, 2006 6:13 pm
feyd | Please use
On the main page I'm instantiating the class as follows passing in UNIX time stamps:
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
When I add this to my page, it clears any responses that I'm already getting from the main page. I'm basically adjusting UNIX time stamps.Code: Select all
class Exception {
function __construct();
final public getMessage();
final public getCode();
final public getFile();
final public getLine();
final public getTrace();
final public getTraceAsString();
protected $message;
protected $code;
protected $file;
protected $line;
}
class Paydate_Calculator {
###
# Weekend
# determines if day is a Saturday or a Sunday
# Then calls LoopType passing "Forward" as its argument
###
*/
private function Weekend() {
if ((date('D',$this->pay_day) == "Saturday") || (date('D',$this->pay_day) == "Sunday"))
LoopType("Forward");
if ($this->pay_day == NULL) {
throw new Exception("In function Weekend, pay_day is null");
}
}
###
# LoopType
# adds a day or subtracts a day to the payday date depending on
# whether we recieve "Forward" or "Reverse" as its argument
###
private function LoopType($type) {
switch ($type) (
case "Forward":
$this->pay_day = $this->pay_day + DAY;
break;
case "Reverse":
$this->pay_day = $this->pay_day - DAY;
break;
}
if($type == NULL) {
throw new Exception("type is NULL");
}
}
###
# CheckIfHoliday
# if pay-day is a Monday we loop throught the Holiday array
# to see if the date matches a holiday. If so we add a day
# if it isn't we subtract a day
###
private function CheckIfHoliday() {
$blnIsHoliday = 0;
if(date('N',$this->pay_day) == 1) {
for ($i = 0; $i < count($this->holiday_array); $i++) {
// add one more day if holiday occurs on a Monday
if ((date("N",$this->pay_day) == 1) && ($this->pay_day == $this->holiday_array[$i])) {
LoopType("Forward");
$blnIsHoliday = 1;
} else {
LoopType("Reverse");
$blnIsHoliday = 1;
}
}
}
return $blnIsHoliday;
if ($this->payday == NULL} {
throw new Exception("In function CheckIfHoliday, pay_day is null");
}
}
###
# setDueDate
# takes the orginal date of the loan and adds 10 days to set the 1st due date
# then we determine how many intervals there are from then until today
# We then keep adding ten days per loop to he orginal due date until we are
# current with today.
###
private function setDueDate($type) {
// now
$now = time();
//Set 1st Due Date
$original_due_date = $this->fund_day + self::TENDAYS;
// if due_date occured before today calculate next due_date
While ($original_due_date < $now) {
$this->due_date = $original_due_date + self::TENDAYS;
}
if ($this->due-day == NULL) {
throw new Exception("I function setDuedate due_date is null");
}
}
###
# tunePayDay
# if the client does not desire direct deposit, we add 10 days to the date
# we then call Weekend() to determine if its a saturday
# we again call Weekend() to determine if its a sunday
# finally we check if it's a Holiday
###
private function tunePayDay() {
if (!$this->direct_deposit) { $this->pay_day = $this->pay_day + DAY; }
// check if Saturday if yes, Loop forward
Weekend();
// check if Sunday if yes, Loop forward
Weekend();
// check if it's a Monday and a Holiday, then move it forward else move it backward
CheckIfHoliday();
}
###
# Calculate_Due_Date
# we set all the class variables
# we then set 1st due date to fund_day + pay_span and make it current
# we now fine tune the pay date for weekends and holidays
# returning true or false if this waas accomplished
# We call all thrown error and print them to the page.
###
public function Calculate_Due_Date($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit) {
try {
$this->fund_day = $fund_day;
$this->holiday_array = $holiday_array;
$this->pay_span = $pay_span;
$this->pay_day = $pay_day;
$this->direct_deposit = $direct_deposit;
try {
// set 1st due date to fund_day + pay_span and make it current
setDueDate();
tunePayDay();
if ($this->pay_day >= $this->due_date) {
return 1;
} else {
$this->pay_day = $this->pay_day + $this->pay_span;
$tunePayDay();
return 0;
}
} catch (Exception $exception) {
print $exception->getMessage();
print " in file " . $exception->getFile();
print " on line " . $exception->getLine() . "\n";
}
}
###
# Get_due_date
# I added this to try and test whether the due date is being set
# we then the constructor Calculate_Due_Date is called
###
function Get_due_date() {
return $this->due_date;
}
const DAY = (1*24*60*60);
const TENDAYS = (10*24*60*60);
private $due_date;
private $fund_day;
private $holiday_array;
private $pay_span;
private $pay_day;
private $direct_deposit;
};Code: Select all
$calc = new Paydate_Calculator($fund_day, $holiday_array, $pay_span, $pay_day, $direct_deposit);
if ($calc == 1) {
$pay_day = $calc->Get_due_date();
echo "pay_day is: $payday";
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]