Example usage for org.joda.time DateTime minusMillis

List of usage examples for org.joda.time DateTime minusMillis

Introduction

In this page you can find the example usage for org.joda.time DateTime minusMillis.

Prototype

public DateTime minusMillis(int millis) 

Source Link

Document

Returns a copy of this datetime minus the specified number of millis.

Usage

From source file:ch.emad.business.schuetu.BusinessImpl.java

License:Apache License

public SpielEinstellungen saveEinstellungen(SpielEinstellungen einstellungenNeu) {

    if (einstellungenNeu == null) {
        return null;
    }/* ww  w  .  ja  v a 2  s . co m*/

    if (verarbeiter.isFertig()) {
        einstellungenNeu.setPhase(SpielPhasenEnum.G_ABGESCHLOSSEN);
    }

    // spieldatum auf 0 Uhr zuruecksetzen
    DateTime time = new DateTime(einstellungenNeu.getStarttag());
    final int millis = time.getMillisOfDay();
    time = time.minusMillis(millis);
    einstellungenNeu.setStarttag(new Date(time.getMillis()));

    this.spielEinstellungenRepo.save(einstellungenNeu);

    return spielEinstellungenRepo.getEinstellungen();
}

From source file:ch.emad.business.schuetu.BusinessImpl.java

License:Apache License

private List<SpielZeile> createZeilen(DateTime startIn, final boolean sonntag) {
    DateTime start = startIn;

    final int millis = start.getMillisOfDay();

    start = start.minusMillis(millis);

    start = start.plusHours(8);/*from w  w w . j ava2 s . c om*/

    final DateTime end = start.plusHours(11);

    final List<SpielZeile> zeilen = new ArrayList<SpielZeile>();
    while (start.isBefore(end.getMillis())) {
        final SpielZeile zeile = new SpielZeile();

        if (start.getHourOfDay() == 8) {
            zeile.setPause(true);
        }

        if (start.getHourOfDay() == MITTAG) {
            zeile.setPause(true);
        }

        if ((start.getHourOfDay() > MITTAG) && sonntag) {
            zeile.setFinale(true);
        }

        // wunsch enum wird gesetzt um spaeter die kategorie gegenpruefen zu koennen
        if (sonntag && (start.getHourOfDay() <= MITTAG)) {
            zeile.setSpieltageszeit(SpielTageszeit.SONNTAGMORGEN);
        }
        if (!sonntag && (start.getHourOfDay() < MITTAG)) {
            zeile.setSpieltageszeit(SpielTageszeit.SAMSTAGMORGEN);
        }
        if (!sonntag && (start.getHourOfDay() > MITTAG)) {
            zeile.setSpieltageszeit(SpielTageszeit.SAMSTAGNACHMITTAG);
        }

        zeile.setStart(start.toDate());
        zeilen.add(zeile);

        final DateTimeZone zone = start.getZone();
        BusinessImpl.LOG.info("zone: " + zone + " date: " + start.toDate());

        zeile.setSonntag(sonntag);

        start = start.plusMinutes(
                this.getSpielEinstellungen().getPause() + this.getSpielEinstellungen().getSpiellaenge());
    }
    return zeilen;
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Get todays events. A convenience method for easy testing
 * /*ww  w.j  a  v a2s . c o m*/
 * @param calendarId
 *            the calendar id
 * @return the events today
 * @throws Exception
 *             the exception
 */
public ArrayNode getEventsToday(@Optional @Name("calendarId") final String calendarId) throws Exception {
    final DateTime now = DateTime.now();
    final DateTime timeMin = now.minusMillis(now.getMillisOfDay());
    final DateTime timeMax = timeMin.plusDays(1);

    return getEvents(timeMin.toString(), timeMax.toString(), calendarId);
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Get busy intervals of today. A convenience method for easy testing
 * //from ww  w .j  ava2s  .  co  m
 * @param calendarId
 *            optional calendar id. If not provided, the default calendar is
 *            used
 * @param timeZone
 *            Time zone used in the response. Optional. The default is UTC.
 * @return the busy today
 * @throws Exception
 *             the exception
 */
public ArrayNode getBusyToday(@Optional @Name("calendarId") final String calendarId,
        @Optional @Name("timeZone") final String timeZone) throws Exception {
    final DateTime now = DateTime.now();
    final DateTime timeMin = now.minusMillis(now.getMillisOfDay());
    final DateTime timeMax = timeMin.plusDays(1);

    return getBusy(timeMin.toString(), timeMax.toString(), calendarId, timeZone);
}

From source file:com.almende.eve.agent.google.GoogleCalendarAgent.java

License:Apache License

/**
 * Quick create an event./*from w  ww .  j a va2  s .c  o  m*/
 * 
 * @param start
 *            the start
 * @param end
 *            the end
 * @param summary
 *            the summary
 * @param location
 *            the location
 * @param calendarId
 *            the calendar id
 * @return the object node
 * @throws Exception
 *             the exception
 */
public ObjectNode createEventQuick(@Optional @Name("start") String start, @Optional @Name("end") String end,
        @Optional @Name("summary") final String summary, @Optional @Name("location") final String location,
        @Optional @Name("calendarId") final String calendarId) throws Exception {
    final ObjectNode event = JOM.createObjectNode();

    if (start == null) {
        // set start to current time, rounded to hours
        DateTime startDate = DateTime.now();
        startDate = startDate.plusHours(1);
        startDate = startDate.minusMinutes(startDate.getMinuteOfHour());
        startDate = startDate.minusSeconds(startDate.getSecondOfMinute());
        startDate = startDate.minusMillis(startDate.getMillisOfSecond());
        start = startDate.toString();
    }
    final ObjectNode startObj = JOM.createObjectNode();
    startObj.put("dateTime", start);
    event.put("start", startObj);
    if (end == null) {
        // set end to start +1 hour
        final DateTime startDate = new DateTime(start);
        final DateTime endDate = startDate.plusHours(1);
        end = endDate.toString();
    }
    final ObjectNode endObj = JOM.createObjectNode();
    endObj.put("dateTime", end);
    event.put("end", endObj);
    if (summary != null) {
        event.put("summary", summary);
    }
    if (location != null) {
        event.put("location", location);
    }

    return createEvent(event, calendarId);
}

From source file:com.almende.eve.agent.MeetingAgent.java

License:Apache License

/**
 * Get the timestamp rounded to the next half hour
 * /*from   w ww. j  av a2s  .c  om*/
 * @return
 */
private DateTime getNextHalfHour() {
    DateTime next = DateTime.now();
    next = next.minusMillis(next.getMillisOfSecond());
    next = next.minusSeconds(next.getSecondOfMinute());

    if (next.getMinuteOfHour() > 30) {
        next = next.minusMinutes(next.getMinuteOfHour());
        next = next.plusMinutes(60);
    } else {
        next = next.minusMinutes(next.getMinuteOfHour());
        next = next.plusMinutes(30);
    }

    return next;
}

From source file:com.altoukhov.svsync.FileSnapshot.java

License:Apache License

public FileSnapshot(String name, long size, DateTime lastModified, String relativePath) {
    this.fileName = name;
    this.fileSize = size;
    this.modifiedTimestamp = lastModified.minusMillis(lastModified.getMillisOfSecond());
    this.relativePath = relativePath;
}

From source file:com.digitald4.iis.model.License.java

License:Open Source License

public static List<License> getAlarming(EntityManager entityManager) {
    DateTime window = DateTime.now().plusDays(30);
    window = window.minusMillis(window.getMillisOfDay());
    List<License> alarming = new ArrayList<License>();
    for (License license : getCollection(License.class, entityManager,
            "SELECT o FROM License o WHERE o.EXPIRATION_DATE <= ?1", window.toDate())) {
        if ((license.isExpired() || license.isWarning())
                && license.getNurse().getStatus() == GenData.NURSE_STATUS_ACTIVE.get(entityManager)) {
            alarming.add(license);/*from  www . j a v  a  2  s  . co m*/
        }
    }
    return alarming;
}

From source file:com.eucalyptus.objectstorage.pipeline.auth.S3Authentication.java

License:Open Source License

static void assertDateNotSkewed(final Date date) throws RequestTimeTooSkewedException {
    DateTime currentTime = DateTime.now();
    DateTime dt = new DateTime(date);
    if (dt.isBefore(currentTime.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT)))
        throw new RequestTimeTooSkewedException();
    if (dt.isAfter(currentTime.plusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT)))
        throw new RequestTimeTooSkewedException();
}

From source file:com.eucalyptus.objectstorage.pipeline.auth.S3V4Authentication.java

License:Open Source License

static void validateExpiresFromParams(Map<String, String> parameters, Date date) throws AccessDeniedException {
    String expires = parameters.get(AWS_EXPIRES_PARAM);
    if (expires == null)
        throw new AccessDeniedException(null, "X-Amz-Expires parameter must be specified.");
    Long expireTime;/*from   ww w.  j a v  a2s.co  m*/
    try {
        expireTime = Long.parseLong(expires);
    } catch (NumberFormatException e) {
        throw new AccessDeniedException(null, "Invalid X-Amz-Expires parameter.");
    }

    if (expireTime < 1 || expireTime > 604800)
        throw new AccessDeniedException(null, "Invalid Expires parameter.");

    DateTime currentTime = DateTime.now();
    DateTime dt = new DateTime(date);
    if (currentTime.isBefore(dt.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT)))
        throw new AccessDeniedException(null, "Cannot process request. X-Amz-Date is not yet valid.");
    if (currentTime.isAfter(dt.plusSeconds(expireTime.intValue() + StackConfiguration.CLOCK_SKEW_SEC)))
        throw new AccessDeniedException(null, "Cannot process request. Expired.");
}