SHARE
TWEET

Untitled

a guest Nov 12th, 2019 103 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private boolean isNumeric(String str) {
  2.         for(char ch : str.toCharArray()) {
  3.             if(!Character.isDigit(ch)) {
  4.                 return false;
  5.             }
  6.         }
  7.  
  8.         return true;
  9.     }
  10.  
  11.     private long parseTime(String timeString, String timeMode) throws CommandException {
  12.         if(!isNumeric(timeString)) {
  13.             throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
  14.         }
  15.         if(timeMode.length() > 1) {
  16.             throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
  17.         }
  18.  
  19.         int sec = Integer.parseInt(timeString) * 60;
  20.  
  21.         char unit = timeMode.charAt(0);
  22.         switch (unit) {
  23.             case 'h':
  24.                 sec *= 60;
  25.                 break;
  26.             case 'd':
  27.                 sec *= (60 * 24);
  28.                 break;
  29.             case 'w':
  30.                 sec *= (7 * 60 * 24);
  31.                 break;
  32.             case 'm':
  33.                 sec *= (30 * 60 * 24);
  34.                 break;
  35.             default:
  36.                 throw new CommandException(Lang.COMMAND_ERROR_TIMEFORMAT);
  37.         }
  38.  
  39.         return sec * 1000L;
  40.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top