Arduino + GSM module.. How do I implement my GSM module with this codes?

This program will send the time of when a power shortage is available and counts the number
hrs/mins/secs and send the data.

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
const int deviceOne = 3;
const int deviceTwo = 4;
const int deviceThree = 5;
const int ledOut = 13;


int stateOne = 0;
int stateTwo = 0;
int stateThree = 0 ;
int msgFlag = 0;
int second = 0;
int minute = 0;
int hours = 0;
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(deviceOne, INPUT); 
  pinMode(deviceTwo, INPUT); 
  pinMode(deviceThree, OUTPUT);  
  pinMode(ledOut, OUTPUT);      
}

// the loop routine runs over and over again forever:
void loop() {
  stateOne = digitalRead(deviceOne);
  stateTwo = digitalRead(deviceTwo);
  stateThree = digitalRead(deviceThree);
  
  if(stateOne==LOW)
  {  
    //send message OFF
    msgFlag = 1;
      
  }
  while(stateOne == LOW)
  {
    //start count;
   while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  }
    if(stateTwo == LOW)
  {      //send message OFF
  
    while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  
  
  }
  
   
   if(stateThree == LOW)
  {   
    //send message OFF
   while(second <60)
   {
       second++;
       delay(1000);
       
       if(second == 60)
       {
         minute++;
         second = 0;
       }
   
       if(minute == 60)
       {
         hours++;
         minute = 0;
       }
   }
  }
  };

  if ((stateOne == HIGH) & (msgFlag == 1)) 
  {
    //send message ON
    msgFlag = 0;
    //get time value
  }
   
}

Moderator edit: code tags

Very hard to read post. Can you please clarify what is your goal?

Some tips:

  1. Never copy-paste code! If you feel a need of doing so, then you should re-think your design
  2. You know that your program will be stuck in one of while(second <60) loops? (second will never be 60 or more)
  3. That's a very bad way of measuring time (delay(1000)) - accuracy is awful; make a quick test with Serial Monitor and you'll see how fast Arduino will fall behind real clock. Use RealTimeClock module for this purpose

Sorry, it's kinda my first time to use arduino so basically I'm not that sure yet, how some of it's syntax work..

what should I use for my delay?
How can I pass values like integers from arduino to gsm?
how will I be able to text the person with gsm module?