Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

calcPatchNotesStartDate()

By: a guest on Mar 10th, 2013  |  syntax: None  |  size: 0.94 KB  |  views: 28  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     //Thursday at 14:55
  2.     private static Date calcPatchNotesStartDate() {
  3.                 Calendar calendar = Calendar.getInstance();
  4.  
  5.         boolean runToday = false;
  6.  
  7.         int today = calendar.get(Calendar.DAY_OF_WEEK);
  8.         if(today == Calendar.THURSDAY && calendar.get(Calendar.HOUR_OF_DAY) < 14 && calendar.get(Calendar.MINUTE) < 55) {
  9.             runToday = true;
  10.         }
  11.  
  12.         //Run at 14:55
  13.         calendar.set(Calendar.HOUR_OF_DAY, 14);
  14.         calendar.set(Calendar.MINUTE, 55);
  15.         calendar.set(Calendar.SECOND, 0);
  16.  
  17.         if(runToday) {
  18.             return calendar.getTime();
  19.         }
  20.  
  21.         int dif = Calendar.THURSDAY - today;
  22.         if(dif > 1) {
  23.             calendar.set(Calendar.DAY_OF_YEAR, dif + calendar.get(Calendar.DAY_OF_YEAR));
  24.         } else {
  25.             calendar.set(Calendar.DAY_OF_YEAR, 7 + dif + calendar.get(Calendar.DAY_OF_YEAR));
  26.         }
  27.  
  28.         return calendar.getTime();
  29.     }