Java Code Examples for org.joda.time.DateTime.plus()

The following are Jave code examples for showing how to use plus() of the org.joda.time.DateTime class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Equella   File: EchoUtils.java   Source Code and License Vote up 7 votes
public static String formatDuration(long duration)
{
	// Using Joda Time
	DateTime now = new DateTime(); // Now
	DateTime plus = now.plus(new Duration(duration * 1000));

	// Define and calculate the interval of time
	Interval interval = new Interval(now.getMillis(), plus.getMillis());
	Period period = interval.toPeriod(PeriodType.time());

	// Define the period formatter for pretty printing
	String ampersand = " & ";
	PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
		.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
		.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();

	return pf.print(period).trim();
}
 
Example 2
Project: unitimes   File: QueryLog.java   Source Code and License Vote up 6 votes
public double[] countTimes(Map<String, double[]> table, DateTime date) {
	DateTime d = date;
	double[] ret = new double[3 * Type.values().length];
	for (int i = 0; i < ret.length; i++) ret[i] = 0;
	for (int i = 0; i < iWindow; i++) {
		double[] count = table.get(format(d));
		if (count != null)
			for (int j = 0; j < count.length; j++) {
				if ((j % 3) == 2)
					ret[j] = Math.max(ret[j], count[j]);
				else
					ret[j] += count[j];
			}
		d = d.plus(iIncrement);
	}
	return ret;
}
 
Example 3
Project: alexa-skill   File: NewEventSpeechlet.java   Source Code and License Vote up 6 votes
private DateTime getTimeTo(IntentRequest request, DateTime from) {
  final String sDuration = sv(request, SLOT_DURATION);
  final String sDateFrom = sv(request, SLOT_DATE_FROM);
  final String sDateTo = sv(request, SLOT_DATE_TO);
  final String sTimeTo = sv(request, SLOT_TIME_TO);

  if(sTimeTo != null) {
    if(sDateTo != null) {
      return DateTime.parse(sDateTo + "T" + sTimeTo);
    }

    return DateTime.parse(sDateFrom + "T" + sTimeTo);
  } else if(sDateTo != null) {
    return DateTime.parse(sDateTo).withTimeAtStartOfDay();
  }

  final Duration duration = Duration.parse(sDuration);
  return from.plus(duration.toMillis());
}
 
Example 4
Project: unitimes   File: QueryLog.java   Source Code and License Vote up 5 votes
public double[] countUsers(Map<String, int[]> table, DateTime date) {
	DateTime d = date;
	int[] ret = new int[2];
	for (int i = 0; i < ret.length; i++) ret[i] = 0;
	for (int i = 0; i < iWindow; i++) {
		int[] count = table.get(format(d));
		if (count != null)
			for (int j = 0; j < count.length; j++) ret[j] += count[j];
		d = d.plus(iIncrement);
	}
	return new double[] { ((double)ret[0]) / iWindow, ((double)ret[1]) / iWindow };
}
 
Example 5
Project: unitimes   File: QueryLog.java   Source Code and License Vote up 5 votes
public int[] countQueries(Map<String, int[]> table, DateTime date) {
	DateTime d = date;
	int[] ret = new int[Type.values().length];
	for (int i = 0; i < ret.length; i++) ret[i] = 0;
	for (int i = 0; i < iWindow; i++) {
		int[] count = table.get(format(d));
		if (count != null)
			for (int j = 0; j < count.length; j++) ret[j] += count[j];
		d = d.plus(iIncrement);
	}
	return ret;
}
 
Example 6
Project: crockpod   File: Alarm.java   Source Code and License Vote up 5 votes
public DateTime getNextTriggerTime() {
    DateTime now = DateTime.now();
    DateTime target = now
            .withHourOfDay(getHourOfDay())
            .withMinuteOfHour(getMinute())
            .withSecondOfMinute(0)
            .withMillisOfSecond(0);

    return target.isBefore(now) ? target.plus(REPEAT_DURATION) : target;
}
 
Example 7
Project: lams   File: SAML2Helper.java   Source Code and License Vote up 4 votes
/**
 * Gets the earliest expiration instant within a metadata tree.
 * 
 * @param xmlObject the metadata
 * @param earliestExpiration the earliest expiration instant
 * @param now when this method was called
 * 
 * @return the earliest expiration instant within a metadata tree
 */
public static DateTime getEarliestExpiration(XMLObject xmlObject, DateTime earliestExpiration, DateTime now) {

    // expiration time for a specific element
    DateTime elementExpirationTime;

    // Test duration based times
    if (xmlObject instanceof CacheableSAMLObject) {
        CacheableSAMLObject cacheInfo = (CacheableSAMLObject) xmlObject;

        if (cacheInfo.getCacheDuration() != null && cacheInfo.getCacheDuration().longValue() > 0) {
            elementExpirationTime = now.plus(cacheInfo.getCacheDuration().longValue());
            if (earliestExpiration == null) {
                earliestExpiration = elementExpirationTime;
            } else {
                if (elementExpirationTime != null && elementExpirationTime.isBefore(earliestExpiration)) {
                    earliestExpiration = elementExpirationTime;
                }
            }
        }
    }

    // Test instant based times
    if (xmlObject instanceof TimeBoundSAMLObject) {
        TimeBoundSAMLObject timeBoundObject = (TimeBoundSAMLObject) xmlObject;
        elementExpirationTime = timeBoundObject.getValidUntil();
        if (earliestExpiration == null) {
            earliestExpiration = elementExpirationTime;
        } else {
            if (elementExpirationTime != null && elementExpirationTime.isBefore(earliestExpiration)) {
                earliestExpiration = elementExpirationTime;
            }
        }
    }

    // Inspect children
    List<XMLObject> children = xmlObject.getOrderedChildren();
    if (children != null) {
        for (XMLObject child : xmlObject.getOrderedChildren()) {
            if (child != null) {
                earliestExpiration = getEarliestExpiration(child, earliestExpiration, now);
            }
        }
    }

    return earliestExpiration;
}
 
Example 8
Project: unitimes   File: QueryLog.java   Source Code and License Vote up 4 votes
public DateTime next(DateTime date, DateTime now) {
	DateTime ret = date.plus(iIncrement);
	return (ret.isAfter(now) ? null : ret);
}
 
Example 9
Project: exam   File: AppUtil.java   Source Code and License Vote up 4 votes
public static DateTime getExamExpirationDate(DateTime timeOfSubmission) {
    String expiresAfter = ConfigFactory.load().getString("sitnet.exam.expiration.period");
    Period period = Period.parse(expiresAfter);
    return timeOfSubmission.plus(period);
}