Announcement

Collapse
No announcement yet.

Duration of the meeting in working days(recognize weekend)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Duration of the meeting in working days(recognize weekend)

    Hello, is there any way how to set the duration of the meeting for working days instead of days?

    I would like it to recognize if there is a weekend during the duration of the meeting and if so add 2 days to the duration.

    Thanks a lot.

    edit: I am generating those meetings via workflow, that is why I would need it automated.
    Last edited by Jakub Grufik; 02-03-2023, 12:17 PM.

  • #2
    Hi Jakub Grufik,

    I am developing some solution for you now and I want to clarify some details with you: how should the Date End be rearranged for your automatically created Meeting if the array of days of the week between Date Start and Date End (where 0 is Sunday, 1 is Monday, 2 is Tuesday, etc.) look likes as follows? [2,3,4,5,6,0,1,2,3,4,5,6,0,1,2,3,4,5,6].
    Will it be necessary to add 4 days to Date End in this case?

    And yet, for example, such an array of days of the week: [2,3,4,5,6]​.
    Will it be necessary to add 1 days to Date End​?

    Or do you want to focus specifically on the last days: Saturday or Sunday, and in which case rearrange the Date End of the Meeting to closest Monday?

    Comment


    • #3
      Hello lazovic I am so sorry I am currently busy at work and I cannot spend time on this "nice-to-have" feature. I am so glad you are trying to help me with this but please lets pause this topic for now and I will come back to this when I will have plenty of times.

      Comment


      • #4
        Jakub Grufik
        hello. I made a new function for changing Due Date in workflows. I'm not sure that it's what you really need, but you can try.

        I created a new file custom/Espo/Custom/Core/Formula/Functions/NsGroup/AddWorkingDaysType.php with this content:

        Code:
        <?php
        namespace Espo\Custom\Core\Formula\Functions\NsGroup;
        
        use \DateTime as DateTimeStd;
        
        use Espo\Core\Formula\{
        Functions\BaseFunction,
        ArgumentList,
        };
        
        use Espo\Core\Di;
        
        class AddWorkingDaysType extends BaseFunction
        {
        public function process(ArgumentList $args)
        {
        if (count($args) < 2) {
        $this->throwTooFewArguments();
        }
        
        // array for holidays. 01.01 is the New Year, for example
        $holidays = array('01-01');
        
        $startDate = $this->evaluate($args[0]);
        $adddays = $this->evaluate($args[1]);
        $retdate = $startDate;
        $sign = "+";
        
        if($adddays < 0){
        $adddays = $adddays*-1;
        $sign = "-";
        }
        
        while ($adddays > 0) {
        if (DateTimeStd::createFromFormat('Y-m-d H:i:s', $startDate) !== FALSE) {
        $retdate = date ( 'Y-m-d H:i:s' , strtotime ( "$retdate {$sign}1 day" ) );
        }
        if (DateTimeStd::createFromFormat('Y-m-d', $startDate) !== FALSE) {
        $retdate = date ( 'Y-m-d' , strtotime ( "$retdate {$sign}1 day" ) );
        }
        $what_day = date("N", strtotime($retdate));
        if ( $what_day != 6 && $what_day != 7 && in_array($current_date, $holidays) == false ) {
        $adddays--;
        }
        }
        return $retdate;
        }
        }​
        and I can use the function ns\AddWorkingDays(date, 10) for adding 10 working days to the date. This function also works with negative numbers (ns\AddWorkingDays(date, -10)). It should work with dateTime and date-only fields. "NsGroup" and "ns" prefix you can change to yours.

        Sorry, I'm not a professional programmer, so the code can be not very good, but it works.

        UPD: sorry, I forgot to mention that I also added to the file custom/Espo/Custom/Resources/metadata/app/formula.json this code:
        Code:
        {
        "functionList": [
        "__APPEND__",
        {
        "name": "ns\\addWorkingDays",
        "insertText": "ns\\addWorkingDays(DATE, DAYS)"
        }
        ],
        "functionClassNameMap": {
        "ns\\addWorkingDays": "Espo\\Custom\\Core\\Formula\\Functions\\NsGroup\\AddWorkingDaysType"
        }
        }
        Last edited by dmytro_s; 03-10-2023, 01:28 PM.

        Comment

        Working...
        X