001package com.thed.zblast.parser.util; 002 003import java.text.DecimalFormat; 004import java.text.SimpleDateFormat; 005import java.util.Calendar; 006import java.util.Date; 007import java.util.Vector; 008 009public class ZCalendarUtils 010 implements ZConstantsResults 011{ 012 public static long getCurrentTimeMillis() 013 { 014 Calendar localCalendar = Calendar.getInstance(); 015 return localCalendar.getTimeInMillis(); 016 } 017 018 public static String getCurrentTime() 019 { 020 Calendar localCalendar = Calendar.getInstance(); 021 return calendarToString(localCalendar); 022 } 023 024 public static String getCurrentLogTime() 025 { 026 Calendar localCalendar = Calendar.getInstance(); 027 return calendarToPreciseTimeOfTheDay(localCalendar); 028 } 029 030 public static String calendarToVerySimpleString(Calendar paramCalendar) 031 { 032 if (paramCalendar == null) 033 return ""; 034 SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("dd/MM"); 035 return localSimpleDateFormat.format(paramCalendar.getTime()); 036 } 037 038 public static String calendarToExtremelySimpleString(Calendar paramCalendar) 039 { 040 if (paramCalendar == null) 041 return ""; 042 SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("dd"); 043 return localSimpleDateFormat.format(paramCalendar.getTime()); 044 } 045 046 public static String calendarToPreciseTimeOfTheDay(Calendar paramCalendar) 047 { 048 if (paramCalendar == null) 049 return ""; 050 SimpleDateFormat localSimpleDateFormat = new SimpleDateFormat("HH:mm:ss.S"); 051 return localSimpleDateFormat.format(paramCalendar.getTime()); 052 } 053 054 public static String calendarToStringForFileName(Calendar paramCalendar) 055 { 056 if (paramCalendar == null) 057 return ""; 058 DecimalFormat localDecimalFormat = new DecimalFormat("00"); 059 return paramCalendar.get(1) + "-" + localDecimalFormat.format(paramCalendar.get(2) + 1) + "-" + localDecimalFormat.format(paramCalendar.get(5)) + "-" + localDecimalFormat.format(paramCalendar.get(11)) + "-" + localDecimalFormat.format(paramCalendar.get(12)) + "-" + localDecimalFormat.format(paramCalendar.get(13)); 060 } 061 062 public static String calendarToString(Calendar paramCalendar) 063 { 064 if (paramCalendar == null) 065 return ""; 066 DecimalFormat localDecimalFormat = new DecimalFormat("00"); 067 return paramCalendar.get(1) + "-" + localDecimalFormat.format(paramCalendar.get(2) + 1) + "-" + localDecimalFormat.format(paramCalendar.get(5)) + " " + localDecimalFormat.format(paramCalendar.get(11)) + ":" + localDecimalFormat.format(paramCalendar.get(12)) + ":" + localDecimalFormat.format(paramCalendar.get(13)); 068 } 069 070 public static String calendarToSimpleString(Calendar paramCalendar) 071 { 072 if (paramCalendar == null) 073 return ""; 074 DecimalFormat localDecimalFormat = new DecimalFormat("00"); 075 return paramCalendar.get(1) + "-" + localDecimalFormat.format(paramCalendar.get(2) + 1) + "-" + localDecimalFormat.format(paramCalendar.get(5)); 076 } 077 078 public static String dateToString(Date paramDate) 079 { 080 Calendar localCalendar = Calendar.getInstance(); 081 if (paramDate != null) 082 localCalendar.setTime(paramDate); 083 return calendarToString(localCalendar); 084 } 085 086 public static String dateToSimpleString(Date paramDate) 087 { 088 Calendar localCalendar = Calendar.getInstance(); 089 if (paramDate != null) 090 localCalendar.setTime(paramDate); 091 return calendarToSimpleString(localCalendar); 092 } 093 094 public static Calendar stringToCalendar(String paramString) 095 { 096 Date localDate = null; 097 try 098 { 099 SimpleDateFormat localSimpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 100 localDate = localSimpleDateFormat1.parse(paramString); 101 } 102 catch (Exception localException1) 103 { 104 } 105 if (localDate == null) 106 try 107 { 108 SimpleDateFormat localSimpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); 109 localDate = localSimpleDateFormat2.parse(paramString); 110 } 111 catch (Exception localException2) 112 { 113 } 114 if (localDate == null) 115 try 116 { 117 SimpleDateFormat localSimpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd"); 118 localDate = localSimpleDateFormat3.parse(paramString); 119 } 120 catch (Exception localException3) 121 { 122 } 123 if (localDate == null) 124 try 125 { 126 SimpleDateFormat localSimpleDateFormat4 = new SimpleDateFormat("HH:mm"); 127 localDate = localSimpleDateFormat4.parse(paramString); 128 } 129 catch (Exception localException4) 130 { 131 } 132 if (localDate != null) 133 { 134 Calendar localCalendar = Calendar.getInstance(); 135 localCalendar.setTime(localDate); 136 return localCalendar; 137 } 138 return null; 139 } 140 141 public static String databaseTimeStringToString(String paramString) 142 { 143 Calendar localCalendar = stringToCalendar(paramString); 144 return calendarToString(localCalendar); 145 } 146 147 public static String dateTimetoDate(String paramString) 148 { 149 if (paramString == null) 150 return ""; 151 String[] arrayOfString = paramString.split(" "); 152 return arrayOfString[0]; 153 } 154 155 public static Calendar computeNextOccurence(Vector<Integer> paramVector, int paramInt1, int paramInt2) 156 { 157 Calendar localCalendar1 = Calendar.getInstance(); 158 int i = localCalendar1.get(7); 159 int j = localCalendar1.get(11); 160 int k = localCalendar1.get(12) + 1; 161 Calendar localCalendar2 = Calendar.getInstance(); 162 localCalendar2.set(11, paramInt1); 163 localCalendar2.set(12, paramInt2); 164 int m = 0; 165 for (int n = 1; n <= 14; n++) 166 { 167 if ((n < i) || ((!paramVector.contains(Integer.valueOf(n))) && (!paramVector.contains(Integer.valueOf(n - 7))))) 168 continue; 169 if ((n == i) && (compareHours(j, k, paramInt1, paramInt2) <= 0)) 170 { 171 m = 1; 172 break; 173 } 174 if (n <= i) 175 continue; 176 localCalendar2.add(7, n - i); 177 m = 1; 178 break; 179 } 180 if (m == 0) 181 return null; 182 return localCalendar2; 183 } 184 185 public static int compareHours(int paramInt1, int paramInt2, int paramInt3, int paramInt4) 186 { 187 Calendar localCalendar1 = Calendar.getInstance(); 188 localCalendar1.set(11, paramInt1); 189 localCalendar1.set(12, paramInt2); 190 Calendar localCalendar2 = Calendar.getInstance(); 191 localCalendar2.set(11, paramInt3); 192 localCalendar2.set(12, paramInt4); 193 return localCalendar1.compareTo(localCalendar2); 194 } 195 196 public static int computeWorkingDaysDuration(Vector<Integer> paramVector, Calendar paramCalendar1, Calendar paramCalendar2) 197 { 198 Calendar localCalendar = Calendar.getInstance(); 199 localCalendar.setTime(paramCalendar1.getTime()); 200 localCalendar.set(11, 0); 201 localCalendar.set(12, 0); 202 localCalendar.set(13, 0); 203 localCalendar.set(14, 1); 204 paramCalendar2.set(11, 0); 205 paramCalendar2.set(12, 0); 206 paramCalendar2.set(13, 0); 207 paramCalendar2.set(14, 1); 208 if ((paramCalendar1 == null) || (paramCalendar2 == null)) 209 return 0; 210 if (localCalendar.compareTo(paramCalendar2) > 0) 211 return 0; 212 int i = 0; 213 while (localCalendar.compareTo(paramCalendar2) <= 0) 214 { 215 if (paramVector.indexOf(Integer.valueOf(localCalendar.get(7))) < 0) 216 i++; 217 localCalendar.add(7, 1); 218 } 219 return i; 220 } 221 222 public static long calculateExtimatedTimeLeft(long paramLong1, long paramLong2, long paramLong3) 223 { 224 if (paramLong1 > 0L) 225 { 226 long l1 = paramLong3 / paramLong1; 227 long l2 = (paramLong2 - paramLong1) * l1; 228 return l2; 229 } 230 return 0L; 231 } 232 233 public static String millisTimeToDurationString(long paramLong) 234 { 235 return millisTimeToDurationString(paramLong, false, true); 236 } 237 238 public static String millisTimeToDurationString(long paramLong, boolean paramBoolean1, boolean paramBoolean2) 239 { 240 if (paramLong == 0L) 241 return "0ms"; 242 StringBuffer localStringBuffer = new StringBuffer(); 243 if (paramLong / 86400000L > 0L) 244 { 245 localStringBuffer.append("" + paramLong / 86400000L + "d "); 246 paramLong %= 86400000L; 247 } 248 if (paramBoolean1) 249 return localStringBuffer.toString(); 250 if (paramLong / 3600000L > 0L) 251 { 252 localStringBuffer.append("" + paramLong / 3600000L + "h "); 253 paramLong %= 3600000L; 254 } 255 if (paramLong / 60000L > 0L) 256 { 257 localStringBuffer.append("" + paramLong / 60000L + "m "); 258 paramLong %= 60000L; 259 } 260 if (paramLong / 1000L > 0L) 261 { 262 localStringBuffer.append("" + paramLong / 1000L + "s "); 263 paramLong %= 1000L; 264 } 265 if ((paramBoolean2) && (paramLong > 0L)) 266 localStringBuffer.append("" + paramLong + "ms"); 267 return localStringBuffer.toString(); 268 } 269 270 public static String secondTimeToDurationString(long paramLong, boolean paramBoolean) 271 { 272 if (paramLong == 0L) 273 return "0s"; 274 StringBuffer localStringBuffer = new StringBuffer(); 275 if (paramLong / 86400L > 0L) 276 { 277 localStringBuffer.append("" + paramLong / 86400L + "d "); 278 paramLong %= 86400L; 279 } 280 if (paramBoolean) 281 return localStringBuffer.toString(); 282 if (paramLong / 3600L > 0L) 283 { 284 localStringBuffer.append("" + paramLong / 3600L + "h "); 285 paramLong %= 3600L; 286 } 287 if (paramLong / 60L > 0L) 288 { 289 localStringBuffer.append("" + paramLong / 60L + "m "); 290 paramLong %= 60L; 291 } 292 localStringBuffer.append("" + paramLong + "s "); 293 return localStringBuffer.toString(); 294 } 295 296 public static String millisTimeToEstimatedDurationString(long paramLong) 297 { 298 if (paramLong == 0L) 299 return "0ms"; 300 StringBuffer localStringBuffer = new StringBuffer(); 301 if (paramLong / 3600000L > 0L) 302 { 303 localStringBuffer.append("" + paramLong / 3600000L + "h "); 304 paramLong %= 3600000L; 305 } 306 if (paramLong / 60000L > 0L) 307 { 308 localStringBuffer.append("" + paramLong / 60000L + "m "); 309 paramLong %= 60000L; 310 } 311 if ((localStringBuffer.toString().indexOf("h") < 0) && (paramLong / 1000L > 0L)) 312 { 313 localStringBuffer.append("" + paramLong / 1000L + "s "); 314 paramLong %= 1000L; 315 } 316 return localStringBuffer.toString(); 317 } 318 319 public static int millisTimeToDurationDays(long paramLong) 320 { 321 if (paramLong == 0L) 322 return 0; 323 if (paramLong / 86400000L > 0L) 324 return (int)(paramLong / 86400000L); 325 return 0; 326 } 327 328 public static long durationStringToMillisTime(String paramString) 329 { 330 long l = 0L; 331 int i = paramString.indexOf("d "); 332 int j = paramString.indexOf("h "); 333 int k = paramString.indexOf("m "); 334 int m = paramString.indexOf("s "); 335 int n = paramString.indexOf("ms"); 336 int i1 = 0; 337 if (i > 0) 338 { 339 l += 86400000 * Integer.parseInt(paramString.substring(i1, i).trim()); 340 i1 = i + 1; 341 } 342 if (j > 0) 343 { 344 l += 3600000 * Integer.parseInt(paramString.substring(i1, j).trim()); 345 i1 = j + 1; 346 } 347 if (k > 0) 348 { 349 l += 60000 * Integer.parseInt(paramString.substring(i1, k).trim()); 350 i1 = k + 1; 351 } 352 if (m > 0) 353 { 354 l += 1000 * Integer.parseInt(paramString.substring(i1, m).trim()); 355 i1 = m + 1; 356 } 357 if (n > 0) 358 l += Integer.parseInt(paramString.substring(i1, n).trim()); 359 return l; 360 } 361 362 public static long durationStringToSecondTime(String paramString) 363 { 364 long l = 0L; 365 int i = paramString.indexOf("d "); 366 int j = paramString.indexOf("h "); 367 int k = paramString.indexOf("m "); 368 int m = paramString.indexOf("s "); 369 int n = 0; 370 if (i > 0) 371 { 372 l += 86400 * Integer.parseInt(paramString.substring(n, i).trim()); 373 n = i + 1; 374 } 375 if (j > 0) 376 { 377 l += 3600 * Integer.parseInt(paramString.substring(n, j).trim()); 378 n = j + 1; 379 } 380 if (k > 0) 381 { 382 l += 60 * Integer.parseInt(paramString.substring(n, k).trim()); 383 n = k + 1; 384 } 385 if (m > 0) 386 { 387 l += Integer.parseInt(paramString.substring(n, m).trim()); 388 n = m + 1; 389 } 390 return l; 391 } 392 393 public static long roundMillisToDay(long paramLong) 394 { 395 long l = paramLong / 86400000L; 396 return 86400000L * l; 397 } 398 399 public static Calendar millisTimeToCalendar(long paramLong) 400 { 401 Date localDate = new Date(paramLong); 402 Calendar localCalendar = Calendar.getInstance(); 403 localCalendar.setTime(localDate); 404 return localCalendar; 405 } 406 407 public static String millisTimeToDateString(long paramLong) 408 { 409 Calendar localCalendar = millisTimeToCalendar(paramLong); 410 return calendarToString(localCalendar); 411 } 412 413 public static String millisTimeToDateSimpleString(long paramLong) 414 { 415 Calendar localCalendar = millisTimeToCalendar(paramLong); 416 return calendarToSimpleString(localCalendar); 417 } 418}