Hi, I am currently developing a website which allows users to add their work history to a database in order to apply for jobs. The system allows the user to add both full-time and part-time references. When displaying what the user has entered, I need to show how much time they have entered so far.
Full-time reference dates cannot overlap each other and so are easy to calculate. However part-time reference dates can overlap both full-time references and part-time references. This introduces the problem. Since part-time reference dates can overlap any number of full-time ones, it's hard to find the exact amount when looping through the data.
I'm looking for suggestions as to how to calculate this. Here is a code snippet of what I have so far:
foreach($this->reference_count as $value){
$date = new Date($value['dt_to']);
if($date->isAfter($five_years_back)){
/* Count full time references first */
if($value['cd_employ'] == 0){
if($date->isAfter(date("Y-m-d"))){
$totaltime += $date->count_days($value['dt_from'], date("Y-m-d"));
}else{
$totaltime += $date->count_days($value['dt_from'], $value['dt_to']);
}
/* Count part-time references */
}elseif($value['cd_employ'] == 1){
foreach($this->reference_count as $value2){
if($date->isAfter($value2['dt_from'] && $date->isBefore($value2['dt_to']){
continue;
/* Reference starts before an existing reference and ends during an existing reference */
}else{
//
/* Reference starts during an existing reference and ends after that reference, but not after another */
}
}
}
}
$this->reference_count contains all references entered, ordered by type (full-time or part-time - 'cd_employ' ) and then by date.
$date is an object with methods isAfter (which checks if a given date is later than the one used when creating the object), isBefore, which does the same but backward and count_days (which returns the number of days between two given dates).
Has anyone had any similar experiences? By the way I might have messed up the syntax when pasting into the form.
Thanks in advance.