Guest User

Untitled

a guest
May 21st, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. private void setDatumRegistracije(String datumRegistracije) throws InvalidDatumException {
  2.         String date = datumRegistracije;
  3.         int duzina = date.length();
  4.        
  5.         if(duzina != 10)
  6.             throw new InvalidDatumException(MainFrame.getInstance().getResourceBundle().getString("InvalidDatum"));
  7.        
  8.         String dan = date.substring(0, 2);
  9.         String mesec = date.substring(3, 5);
  10.         String godina = date.substring(6, duzina);
  11.        
  12.         char[] input = date.toCharArray();
  13.        
  14.         if((input[0] < '0' || input[0] > '9') ||
  15.            (input[1] < '0' || input[1] > '9') ||
  16.            (input[2] != '/') ||
  17.            (input[3] < '0' || input[3] > '9') ||
  18.            (input[4] < '0' || input[4] > '9') ||
  19.            (input[5] != '/') ||
  20.            (input[6] < '0' || input[6] > '9') ||
  21.            (input[7] < '0' || input[7] > '9') ||
  22.            (input[8] < '0' || input[8] > '9') ||
  23.            (input[9] < '0' || input[9] > '9') ||
  24.            (duzina != 10))
  25.                 throw new InvalidDatumException(MainFrame.getInstance().getResourceBundle().getString("InvalidDatum"));
  26.         else {
  27.             int d = Integer.parseInt(dan);
  28.             int m = Integer.parseInt(mesec);
  29.             int y = Integer.parseInt(godina);
  30.             this.datumRegistracije.set(y, m-1, d);
  31.         }
  32.     }
Add Comment
Please, Sign In to add comment