Example usage for org.joda.time MutableDateTime setSecondOfMinute

List of usage examples for org.joda.time MutableDateTime setSecondOfMinute

Introduction

In this page you can find the example usage for org.joda.time MutableDateTime setSecondOfMinute.

Prototype

public void setSecondOfMinute(final int secondOfMinute) 

Source Link

Document

Set the second of the minute to the specified value.

Usage

From source file:org.calrissian.accumulorecipes.commons.support.TimeUnit.java

License:Apache License

public long normalize(long timestamp) {
    MutableDateTime ts = new MutableDateTime(timestamp, DateTimeZone.UTC);

    /**/*from   ww  w .j av  a  2  s  . c o m*/
     * NOTE: order of switch matters.
     *
     * This switch is designed to fall through from most to least significant. Zeroes all non significant
     * portions of the time before finally breaking at the end.
     */
    switch (this) {
    case MONTHS:
        ts.setDayOfMonth(1);
    case DAYS:
        ts.setHourOfDay(0);
    case HOURS:
        ts.setMinuteOfHour(0);
    case MINUTES:
        ts.setSecondOfMinute(0);
        ts.setMillisOfSecond(0);
        break;
    default:
        throw new IllegalArgumentException("Unsupported time unit");
    }

    return ts.getMillis();
}

From source file:org.n52.sos.cache.AbstractCacheScheduler.java

License:Apache License

public MutableDateTime resolveNextScheduleDate(LocalTime localTime, DateTime referenceTime) {
    /*//from   w w  w  . j  a v  a  2 s . co m
     * every 4am, starting with next
     */
    MutableDateTime mdt = referenceTime.toMutableDateTime();
    mdt.setHourOfDay(localTime.getHourOfDay());
    mdt.setMinuteOfHour(localTime.getMinuteOfHour());
    mdt.setSecondOfMinute(localTime.getSecondOfMinute());

    if (!referenceTime.isBefore(mdt)) {
        mdt.addDays(1);
    }

    Random random = new Random();
    mdt.addSeconds(random.nextInt(11) * 2);
    return mdt;
}

From source file:org.obp.utils.TimeUtil.java

License:Apache License

public static final long fromUtcHHMMSS(double time) {
    int hhmmss = (int) time;
    MutableDateTime mdt = MutableDateTime.now(DateTimeZone.UTC);
    mdt.setSecondOfMinute(hhmmss % 100);
    mdt.setMinuteOfHour((hhmmss / 100) % 100);
    mdt.setHourOfDay(hhmmss / 10000);/*from  w  ww .  j  ava  2 s.co m*/
    mdt.setMillisOfSecond((int) ((time - hhmmss) * 1000));
    return mdt.toDateTime().getMillis();
}

From source file:org.osframework.util.DateUtil.java

License:Apache License

static DateTime forceMidnight(DateTime dt) {
    MutableDateTime mdt = dt.toMutableDateTime();
    mdt.setHourOfDay(0);/*  w  w  w.j a v a  2  s. c o m*/
    mdt.setMinuteOfHour(0);
    mdt.setSecondOfMinute(0);
    return mdt.toDateTime();
}

From source file:org.talend.components.netsuite.avro.converter.XMLGregorianCalendarToDateTimeConverter.java

License:Open Source License

@Override
public Object convertToAvro(XMLGregorianCalendar xts) {
    if (xts == null) {
        return null;
    }/*from w  w w  .  j  a v a  2  s  .  co m*/

    MutableDateTime dateTime = new MutableDateTime();
    try {
        dateTime.setYear(xts.getYear());
        dateTime.setMonthOfYear(xts.getMonth());
        dateTime.setDayOfMonth(xts.getDay());
        dateTime.setHourOfDay(xts.getHour());
        dateTime.setMinuteOfHour(xts.getMinute());
        dateTime.setSecondOfMinute(xts.getSecond());
        dateTime.setMillisOfSecond(xts.getMillisecond());

        DateTimeZone tz = DateTimeZone.forOffsetMillis(xts.getTimezone() * 60000);
        if (tz != null) {
            dateTime.setZoneRetainFields(tz);
        }

        return Long.valueOf(dateTime.getMillis());
    } catch (IllegalArgumentException e) {
        throw new ComponentException(e);
    }
}

From source file:se.toxbee.sleepfighter.model.Alarm.java

License:Open Source License

/**
 * Returns when this alarm will ring.<br/>
 * If {@link #canHappen()} returns false, -1 will be returned.
 *
 * @param now the current time in unix epoch timestamp.
 * @return the time in unix epoch timestamp when alarm will next ring.
 *///from w w w .  j  a va2  s  . com
public synchronized Long getNextMillis(long now) {
    if (!this.canHappen()) {
        return NEXT_NON_REAL;
    }

    MutableDateTime next = new MutableDateTime(now);
    next.setHourOfDay(this.hour);
    next.setMinuteOfHour(this.minute);
    next.setSecondOfMinute(this.second);

    // Check if alarm was earlier today. If so, move to next day
    if (next.isBefore(now)) {
        next.addDays(1);
    }
    // Offset for weekdays
    int offset = 0;

    // first weekday to check (0-6), getDayOfWeek returns (1-7)
    int weekday = next.getDayOfWeek() - 1;

    // Find the weekday the alarm should run, should at most run seven times
    for (int i = 0; i < 7; i++) {
        // Wrap to first weekday
        if (weekday > MAX_WEEK_INDEX) {
            weekday = 0;
        }
        if (this.enabledDays[weekday]) {
            // We've found the closest day the alarm is enabled for
            offset = i;
            break;
        }
        weekday++;
        offset++;
    }

    if (offset > 0) {
        next.addDays(offset);
    }

    return next.getMillis();
}