1 19 20 package taskblocks; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 25 import org.w3c.dom.Element ; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 29 public class Utils { 30 31 public static final long MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24; 32 33 34 public static final long FIRST_SATURDAY = 1; 35 36 41 public static long countFinishTime(long startTime, long duration) { 42 long startDayInWeek = getDayInWeek(startTime); 43 44 long durationWeeks = (duration) / 5; 45 long durationRest = (duration) % 5; 46 47 long daysAdd = durationWeeks*2; 49 if(startDayInWeek + durationRest > 5) { 50 daysAdd += 2; 51 } 52 53 if(duration > 0 && startDayInWeek == 0 && duration % 5 == 0) { 54 daysAdd-=2; 55 } 56 return startTime + duration + daysAdd; 57 } 58 59 64 public static int getDayInWeek(long time) { 65 return (int)((time + FIRST_SATURDAY + 2) % 7); 66 } 67 68 public static long repairStartTime(long startTime) { 69 long startDayInWeek = Utils.getDayInWeek(startTime); 70 if(startDayInWeek == 5) { 71 return startTime+2; 72 } else if(startDayInWeek == 6) { 73 return startTime+1; 74 } 75 return startTime; 76 } 77 78 79 public static long countWorkDuration(long start, long end) { 80 long result; 81 long weeks = (end-start) / 7; 82 result = weeks * 5; 83 long rest = (end-start) % 7; 84 int startInWeek = getDayInWeek(start); 85 for(int i = 1; i <= rest; i++) { 86 long stepInWeek = (startInWeek + i) % 7; 87 if(stepInWeek != 0 && stepInWeek != 6) { 88 result ++; 89 } 90 } 91 return result; 92 } 93 94 public static Element [] getChilds(Element e, String name) { 95 List <Element >childs = new ArrayList <Element >(); 96 NodeList nl = e.getChildNodes(); 97 for(int i = 0; i < nl.getLength(); i++) { 98 Node n = nl.item(i); 99 if(n.getNodeType() == Node.ELEMENT_NODE && name.equals(n.getNodeName())) { 100 childs.add((Element )n); 101 } 102 } 103 return childs.toArray(new Element [childs.size()]); 104 } 105 106 113 public static String getFirstElemText(Element parent, String childName) { 114 return null; } 116 117 } 118 | Popular Tags |