Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 24
Updateshifttime
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 5
56
0.00% covered (danger)
0.00%
0 / 24
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 convertTimeToUTCzone
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 convertdate
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 8
 convertdateForAttendance
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 8
 handle
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
class Updateshifttime extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update:shifttime';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'update shift time in UTC';
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    //this function convert string to UTC time zone
    function convertTimeToUTCzone($str, $format = 'Y-m-d H:i:s'){
        $new_str = Carbon::parse($str,'asia/kolkata');
        $new_str->setTimezone(config('UTC'));
        return $new_str;
    }
    public function convertdate($table)
    {
        $data = DB::table($table)->get();
        foreach ($data as $value) {
            $start_time = $this->convertTimeToUTCzone($value->start_time);
            $end_time = $this->convertTimeToUTCzone($value->end_time);
            DB::table($table)
                        ->where('id','=',$value->id)
                        ->update(['start_time' => $start_time,'end_time' => $end_time]);
        }
        return 0;
    }
    public function convertdateForAttendance($table)
    {
        $data = DB::table($table)->get();
        foreach ($data as $value) {
            $start_time = $this->convertTimeToUTCzone($value->shift_start);
            $end_time = $this->convertTimeToUTCzone($value->shift_end);
            DB::table($table)
                        ->where('id','=',$value->id)
                        ->update(['shift_start' => $start_time,'shift_end' => $end_time]);
        }
        return 0;
    }
    public function handle()
    {
        $this->convertdate('shifts');
        $this->convertdateForAttendance('attendance_details');
    }
}