Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HALF BUSINESS DAY ADDITION #23

Open
legreco opened this issue Jul 20, 2017 · 2 comments
Open

HALF BUSINESS DAY ADDITION #23

legreco opened this issue Jul 20, 2017 · 2 comments
Labels

Comments

@legreco
Copy link

legreco commented Jul 20, 2017

Hello,
How to add 1/2 business day to a date?
I give you an example:
In my work worked hours start from 7h30AM to 3h30PM in regular business day.
In half worked business day hours start from 7h30AM to11h3AM.
I am programming a leave request system. Employee should be able to take 1/2 business days.

Sorry if my english is not good.
:)

@florianv
Copy link
Owner

Hello,

you can use a SpecialDay to change the working hours dynamically:

$days = [
    // Special day with dynamic opening hours depending on the date
    new SpecialDay(Days::FRIDAY, function (\DateTime $date) {
        if ('2015-05-29' === $date->format('Y-m-d')) {
            return [['9 AM', '12:00']];
        }
    
        return [['9 AM', '5 PM']];
    }),
];

@legreco
Copy link
Author

legreco commented Sep 11, 2017

Thanks. I solved it this way.
But i do a little trick. Because employees can request half day leave, i split the business day in two equal part:
time

` if(ctype_digit($leave_duration))
{
//business day = 8 hours
$hours=$leave_duration*8;

            while($hours>0)
            {
                $leave_start_date_time->add(new \DateInterval("PT4H"));      // I add 1/2 of business day
                $leave_start_date_time = $business_c->closest($leave_start_date_time);  // I get the closest business date time
                $hours=$hours-4;

            }
            // Finally  we get the employee return date time
            $employee_return_date_time=$business->closest($leave_start_date_time);

        }
        else
        {

//leave duration is decimal
// we get the int part
$leave_duration_int=intval($leave_duration);

            if($leave_duration_int>0)
            {
                $hours=$leave_duration_int*8;
                while($hours>0)
                {
                    $leave_start_date_time->add(new \DateInterval("PT4H"));
                    $leave_start_date_time = $business_c->closest($leave_start_date_time);
                    $hours=$hours-4;

                }


            }

//we add the intervall equal to the 1/2 business day remaining
$leave_start_date_time->add(new \DateInterval("PT4H"));
$leave_start_date_time = $business_c->closest($leave_start_date_time);

           // Finally  we get the employee return date time
            $employee_return_date_time=$business->closest($leave_start_date_time);
        }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants