lundi 6 août 2018

Laravel Queue Job Based on User TimeZone

I have user timezone and working hour. I am trying to schedule a job in the working hours of the user. But it seems not working correctly.Can you please check if I did something wrong.

An Example value is :

Timezone is 'America/New_York'
User Starts at  "10 am"
User Stops at  "6 pm"   

I am checking if it is user's working hour or not trying to get the number of seconds and then schedule jon after that many seconds.

   date_default_timezone_set($users->timezone);
   $date = date('m/d/Y h:i:s a', time());
    if (strtotime($date) > strtotime($users->start) && strtotime($date) < strtotime($users->stop)) {
        goto processnow;
    }
    else{

        $tomorrow = new DateTime('tomorrow');
        $newdate =  date('Y-m-d H:i',strtotime('+'. $users->start .' hour',strtotime($tomorrow->format('Y-m-d H:i:s'))));
        $dtnow = new DateTime();
        $ndate =  date('Y-m-d H:i',strtotime($dtnow->format('Y-m-d H:i:s')));
        $sec = strtotime($newdate) - strtotime($ndate);

        ProcessCoupons::dispatch($this->id) 
            ->delay(now()->addSeconds($sec));   
    }



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire