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 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 42
Updatedates
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 42
 __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
 handle
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 29
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use DB;
use Carbon\Carbon;
class Updatedates extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'update:dates';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'update all datetime 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('UTC');
    return $new_str;
}
    public function convertdate($table)
    {
        $data = DB::table($table)->get();
        foreach ($data as $value) {
            $created_at = $this->convertTimeToUTCzone($value->created_at);
            $updated_at = $this->convertTimeToUTCzone($value->updated_at);
            DB::table($table)
                        ->where('id','=',$value->id)
                        ->update(['created_at' => $created_at,'updated_at' => $updated_at]);
        }
        return 0;
    }
    public function handle()
    {
        $this->convertdate('apply_leaves');
        //$this->convertdate('attendance_details');
        $this->convertdate('attendance_reasons');
        $this->convertdate('audits');
        $this->convertdate('biometric_data');
        $this->convertdate('holidays');
        $this->convertdate('leaves');
        $this->convertdate('leave_entitlements');
        $this->convertdate('notifications');
        $this->convertdate('notification_lists');
        $this->convertdate('schedules');
        $this->convertdate('shifts');
        $this->convertdate('team_shift_details');
        $this->convertdate('users');
        $this->convertdate('user_addresses');
        $this->convertdate('user_attendance_requests');
        $this->convertdate('user_bank_details');
        $this->convertdate('user_details');
        $this->convertdate('user_document_details');
        $this->convertdate('weekends');
        $attendance_details = DB::table('attendance_details')->get();
        foreach ($attendance_details as $value) {
            $created_at = $this->convertTimeToUTCzone($value->created_at);
            $updated_at = $this->convertTimeToUTCzone($value->updated_at);
            $check_in = $this->convertTimeToUTCzone($value->check_in);
            $check_out = $this->convertTimeToUTCzone($value->check_out);
            DB::table('attendance_details')
                        ->where('id','=',$value->id)
                        ->update(['created_at' => $created_at,'updated_at' => $updated_at,'check_in' =>$check_in,'check_out' => $check_out]);
        }
        
        return;
    }
        
}