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

TaskEmailDue: Hours before due date possible? #16

Closed
bhopmann opened this issue Jan 3, 2021 · 7 comments
Closed

TaskEmailDue: Hours before due date possible? #16

bhopmann opened this issue Jan 3, 2021 · 7 comments

Comments

@bhopmann
Copy link

bhopmann commented Jan 3, 2021

First of all, thank you very much for your plugin, especially for the automatic action within the file https://github.com/creecros/SendEmailCreator/blob/master/Action/TaskEmailDue.php.

I wonder if it is possible to include hours in the script instead of (or in addition to) days. Unfortunately, so far I have not been able to fully understand the logic of the script. I would therefore be grateful for any starting point!

@creecros
Copy link
Owner

creecros commented Jan 3, 2021

yes. there are 24 hours in a day. therefore 1/24 is an hour.

@creecros
Copy link
Owner

creecros commented Jan 3, 2021

if you're looking for the logic, its here:

$max_duration = $this->getParam('duration') * 86400;

line 120, duration x 86400, so technically its in seconds. so if your duration was 1.041667, that would be a day and an hour.

bear in mind, this duration is only checked according to your crontab. so its basically irrelevant, unless your cron runs enough to check this. most crons run once a day, its at that time it checks if the duration condition is met. so if your cron runs once a day at 9am, and your condition isn't met until 10am, well, it won't trigger until the next day at 9am, because its not going to check at 10am.

@bhopmann
Copy link
Author

bhopmann commented Jan 3, 2021

Thank you for your explanation!
I'm currently running ./cli trigger:tasks every 15 minutes and want to push notifications one or two hours before a task is due. Therefore I'm currently experimenting with the following setting:

if ( $remaining > 0 ) {
            $hours_to_due = floor($remaining / 3600);
            $seconds_to_due = $remaining % 3600;
            $minutes_to_due = $seconds_to_due > 0 ? floor( $seconds_to_due / 60  ) : 0;
        }

        $time_part = '';
        if ( $hours_to_due > 0 ) {
            $time_part = $hours_to_due . ' hour' . ($hours_to_due == 1 ? '' : 's');
            if ( $hours_to_due < 2 && $minutes_to_due > 0 ) {
                $time_part .= ' and ' . $minutes_to_due . ' minute' . ($minutes_to_due == 1 ? '' : 's');
            }
        }
        else if ( $minutes_to_due > 0 ) {
            $time_part = $minutes_to_due . ' minute' . ($minutes_to_due == 1 ? '' : 's');
        }

[...]

$max_duration = $this->getParam('duration') * 7200;

[...]

$minimum_gotify_span = 86400;

@creecros
Copy link
Owner

creecros commented Jan 3, 2021

you seem to be on the right path, you could take it a step further, and offer an array of "duration in" days, hours, minutes, or seconds and then i.e., if day, multiply by 86400, hours by 3600, etc...

@bhopmann
Copy link
Author

bhopmann commented Jan 4, 2021

Thank you for your advice, I will give it a try!

@bhopmann
Copy link
Author

I've tried out a little more and am now using the following function (with $task['date_due'] set to Hours before due date).

   public function makeDefaultSubject($task)
    {
        $project = $this->projectModel->getById($task['project_id']);

        $remaining = $task['date_due'] - time();
        $days_to_due = 0;
        $hours_to_due = 0;
        $minutes_to_due = 0;

        if ( $remaining > 0 )
        {
        	
            $days_to_due = floor($remaining / 86400);
            $hours_to_due = floor(($remaining % 86400) / 3600);
            $minutes_to_due = floor(($remaining % 3600) / 60);
        }

        $time_part = array();

        if ( $days_to_due > 0 )
        {
            $time_part[] = $days_to_due . t(' day') . ($days_to_due == 1 ? '' : t('s'));
        }

        if ( $hours_to_due > 0 )
        {
            $time_part[] = $hours_to_due . t(' hour') . ($hours_to_due == 1 ? '' : t('s '));
        }

        if ( $minutes_to_due > 0 )
        {
            $time_part[] = $minutes_to_due . t(' minute') . ($minutes_to_due == 1 ? '' : t('s '));
        }

        $time_part = implode(t(' and '), $time_part);

        $subject = '[' . $project['name']  . '][' . $task['title']  . '] ' . ($time_part ? t('Due in ') . $time_part : t('Task is due'));
        //print "\n".$subject."\n";

        return $subject;
    }

@creecros
Copy link
Owner

I dont think there is any action I need to do on this, Stale

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

No branches or pull requests

2 participants