List of usage examples for org.joda.time Interval getEnd
public DateTime getEnd()
From source file:com.sos.scheduler.model.objects.JSObjWeekday.java
License:Apache License
@Override public RunTimeElements getRunTimeElements(Interval timeRange) { RunTimeElements result = new RunTimeElements(timeRange); int which = Integer.valueOf(getWhich()); Iterator<String> it = getDay().iterator(); while (it.hasNext()) { String dayList = it.next(); List<Integer> weekdays = JodaTools.getJodaWeekdays(dayList); for (int weekday : weekdays) { DateTime d = JodaTools.getWeekdayInIntervalOrNull(timeRange, weekday, which); while (d != null) { Iterator<Period> itP = getPeriod().iterator(); while (itP.hasNext()) { Period p = itP.next(); JSObjPeriod period = new JSObjPeriod(objFactory); period.setObjectFieldsFrom(p); DateTime start = period.getDtSingleStartOrNull(d); if (start != null && timeRange.contains(start)) result.add(new RunTimeElement(start, period.getWhenHoliday())); }/*from w ww.java 2 s . c o m*/ DateTime start = JodaTools.getStartOfMonth(d.plusMonths(1)); if (!timeRange.contains(start)) break; Interval i = new Interval(start, timeRange.getEnd()); d = JodaTools.getWeekdayInIntervalOrNull(i, weekday, which); } } } // Collections.sort(result, DateTimeComparator.getInstance()); return result; }
From source file:com.stagecents.pay.domain.Overtime.java
License:Open Source License
@Override public void processHours(Interval interval, Activity activity, Timecard timecard, Position position) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); // 1. Test start time against normal start time. DateTime regStart = start;/*from w w w . j av a 2s . co m*/ if (position.getNormalStart() != null) { DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart()); regStart = regStart.isBefore(normalStart) ? normalStart : regStart; } // Update the time card with any premium time prior to the position's // normal start if (start.isBefore(regStart)) { updateTimecard(timecard, activity, new Interval(start, regStart)); } // 2. Test end time against minimum call. MinimumCallValue mc = getMinimumCall(new Interval(start, end)); if (mc != null) { long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60; DateTime minCallEnd = end.plus(minCall); end = end.isBefore(minCallEnd) ? minCallEnd : end; } // Test end time against normal end time. DateTime regEnd = end; if (position.getNormalEnd() != null) { DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd()); regEnd = normalEnd.isBefore(regEnd) ? normalEnd : regEnd; } // Test end time against maximum time for position. if (position.getMaximumHours() > 0) { float priorHrs = getPriorHours(timecard, regStart.toLocalDate()); long availMillis = (long) (position.getMaximumHours() - priorHrs) * 1000 * 60 * 60; DateTime availEnd = regStart.plus(availMillis); regEnd = availEnd.isBefore(regEnd) ? availEnd : regEnd; } // Update the timecard with any premium time after the position's normal // end if (regEnd.isBefore(end)) { updateTimecard(timecard, activity, new Interval(regEnd, end)); } }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
/** * Returns the number of semimonthly pay cycles in the given time interval. * //from w w w. j a va 2s . c om * @param arg The time period to analyze. * @return The number of semimonthly pay cycles in the given time interval. */ private int getSemiMonthlyCycles(Interval arg) { int startPer = arg.getStart().getDayOfMonth() <= 15 ? 1 : 2; int endPer = arg.getEnd().getDayOfMonth() <= 15 ? 1 : 2; DateTime adjStart = (arg.getStart().getDayOfMonth() <= 15) ? arg.getStart().dayOfMonth().withMinimumValue() : arg.getStart().withDayOfMonth(15); DateTime adjEnd = (arg.getEnd().getDayOfMonth() <= 15) ? arg.getEnd().dayOfMonth().withMinimumValue() : arg.getEnd().dayOfMonth().withMaximumValue(); return (Months.monthsBetween(adjStart, adjEnd).getMonths() * 2) + ((startPer == endPer) ? 1 : 2); }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
/** * Returns the number of monthly pay cycles in the given time interval. * //from w w w.j ava 2 s .c om * @param arg The time interval to analyze. * @return The number of monthly pay cycles in the given time interval. */ private int getMonthlyCycles(Interval arg) { DateTime adjStart = arg.getStart().withDayOfMonth(1); DateTime adjEnd = (arg.getEnd().getDayOfMonth() < 15) ? arg.getEnd().withDayOfMonth(1) : arg.getEnd().dayOfMonth().withMaximumValue(); return Months.monthsBetween(adjStart, adjEnd).getMonths() + 1; }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
/** * Returns the number of calendar quarters in the given time interval. * /* w w w . j av a 2 s . c om*/ * @param arg The time interval to analyze. * @return The number of calendar quarters in the given time interval. */ private int getQuarterlyCycles(Interval arg) { int adjStartMonth = getQuarterStartMonth(arg.getStart().getMonthOfYear()); int adjEndMonth = getQuarterEndMonth(arg.getEnd().getMonthOfYear()); DateTime adjStart = arg.getStart().withMonthOfYear(adjStartMonth).withDayOfMonth(1); DateTime adjEnd = arg.getEnd().withMonthOfYear(adjEndMonth).dayOfMonth().withMaximumValue(); return (int) Math.ceil((Months.monthsBetween(adjStart, adjEnd).getMonths() + 1) / 3d); }
From source file:com.stagecents.pay.domain.PayCycle.java
License:Open Source License
/** * Returns the number of calendar years in the given time interval. * /*from w w w .j av a2 s. c om*/ * @param arg The time interval to analyze. * @return The number of calendar years. */ private int getAnnualCycles(Interval arg) { return arg.getEnd().getYear() - arg.getStart().getYear() + 1; }
From source file:com.stagecents.pay.domain.RegularWages.java
License:Open Source License
protected void doProcessHours(Interval interval, Activity activity, Timecard timecard, Position position) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); // Test start time against normal start time. if (position.getNormalStart() != null) { DateTime normalStart = start.toLocalDate().toDateTime(position.getNormalStart()); start = start.isBefore(normalStart) ? normalStart : start; }//from w w w. j a v a 2 s . c o m // Test end time against minimum call. MinimumCallValue mc = getMinimumCall(activity.duration()); if (mc != null) { long minCall = (long) mc.getDefaultValue() * 1000 * 60 * 60; DateTime minCallEnd = end.plus(minCall); end = end.isBefore(minCallEnd) ? minCallEnd : end; } // Test end time against normal end time. if (position.getNormalEnd() != null) { DateTime normalEnd = end.toLocalDate().toDateTime(position.getNormalEnd()); end = end.isAfter(normalEnd) ? normalEnd : end; } // Test end time against maximum time for position. if (position.getMaximumHours() > 0) { float priorHours = getPriorHours(timecard, start.toLocalDate()); long availMillis = (long) (position.getMaximumHours() - priorHours) * 1000 * 60 * 60; DateTime availEnd = start.plus(availMillis); end = availEnd.isBefore(end) ? availEnd : end; } updateTimecard(timecard, activity, new Interval(start, end)); }
From source file:com.tkmtwo.timex.DateTimes.java
License:Apache License
/** * Calculate split DateTimes over an Interval. * <p>// ww w. j a v a 2 s.c om * * This method will start at the beginning of the Interval and * add the specified number of milliseconds for each split. Splits will * continue to be calculated until the end of the Interval is reached * or overshot. * <p> * * A DateTimeDirection will either start at the beginning of the * Interval and work forward, or start at the end and work backward. * <p> * * The end of the Interval may or may not be included in the splits. This * depends on whether duraMillis divides into interval.getMillis() * evenly or not. For example: * <p> * * *<pre> * * DateTimeDirection dtDirection = DateTimeDirection.FORWARD; * Interval interval = new Interval(new DateTime(0L), * new DateTime(240010L)); * long duraLong = 60000L; * * List<DateTime> dts = DateTimes.splits(dtDirection, * interval, * duraLong); * for (int i = 0; i < dts.size(); i++) { * System.out.println(String.format("Split %d is %s which is %8dms.", * i, * dts.get(i).toString(), * dts.get(i).getMillis())); * } * *</pre> * * Will print: * <p> * * <pre> * * Split 0 is 1970-01-01T00:00:00.000Z which is 0ms. * Split 1 is 1970-01-01T00:01:00.000Z which is 60000ms. * Split 2 is 1970-01-01T00:02:00.000Z which is 120000ms. * Split 3 is 1970-01-01T00:03:00.000Z which is 180000ms. * Split 4 is 1970-01-01T00:04:00.000Z which is 240000ms. * * </pre> * * Even though the end of the Interval is 240010L. Splits are calculated * based on the whole increments of duraMillis which will fit in * the Interval. If the direction is reversed with * DateTimeDirection.REVERSE: * <p> * * <pre> * * Split 0 is 1970-01-01T00:04:00.010Z which is 240010ms. * Split 1 is 1970-01-01T00:03:00.010Z which is 180010ms. * Split 2 is 1970-01-01T00:02:00.010Z which is 120010ms. * Split 3 is 1970-01-01T00:01:00.010Z which is 60010ms. * Split 4 is 1970-01-01T00:00:00.010Z which is 10ms. * * </pre> * * Is printed. * * * @param dtDirection a DateTimeDirection value * @param interval an Interval value * @param duraMillis a long value specifying the duration between splits * @return a List<DateTime> value */ public static List<DateTime> splits(DateTimeDirection dtDirection, Interval interval, long duraMillis) { checkNotNull(dtDirection, "Need a direction."); checkNotNull(interval, "Need an interval."); checkArgument(duraMillis != 0L, "DuraMillis can not be zero."); checkArgument(interval.toDurationMillis() > duraMillis, "Interval must be greater than the DuraMillis."); List<DateTime> dts = new ArrayList<DateTime>(); for (DateTime dt = dtDirection.getStart(checkNotNull(interval)); dtDirection.lteq(dt, dtDirection.getEnd(interval)); dt = dtDirection.plus(dt, duraMillis)) { dts.add(dt); } /* START */ //if (!interval.getEnd().isEqual(dts.get(dts.size() - 1))) { if (!dtDirection.getEnd(interval).isEqual(dts.get(dts.size() - 1))) { dts.add(interval.getEnd()); } /* STOP */ return dts; }
From source file:com.tkmtwo.timex.Intervals.java
License:Apache License
public static Interval noMillis(Interval i) { return new Interval(DateTimes.noMillis(i.getStart()), DateTimes.noMillis(i.getEnd())); }
From source file:com.tkmtwo.timex.Intervals.java
License:Apache License
/** * Print the Interval in ISO basic format with no milliseconds * in the UTC time zone.//from w w w.j a v a 2s. c o m * * The format is START/END with a slash in between. * * This is a good format to use for human-readable applications * like error messages or application logs. * * @param i an Interval value * @return a String value */ public static String printBasic(Interval i) { checkNotNull(i, "Input interval is null."); return DateTimes.getBasicFormatter().print(i.getStart()) + "/" + DateTimes.getBasicFormatter().print(i.getEnd()); }