Example usage for org.joda.time MutableDateTime now

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

Introduction

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

Prototype

public static MutableDateTime now() 

Source Link

Document

Obtains a MutableDateTime set to the current system millisecond time using ISOChronology in the default time zone.

Usage

From source file:de.pro.dbw.util.impl.DateConverter.java

License:Open Source License

public Long addDays(int days) {
    final MutableDateTime mdtNow = MutableDateTime.now();
    mdtNow.addDays(days);

    return mdtNow.getMillis();
}

From source file:de.pro.dbw.util.impl.DateConverter.java

License:Open Source License

public Boolean isAfter(int days, Long time) {
    final MutableDateTime mdtNow = MutableDateTime.now();
    mdtNow.addDays(days);//  www. j  av  a  2s.  c  o  m

    final MutableDateTime mdtTime = new MutableDateTime(time);
    return mdtTime.isAfter(mdtNow);
}

From source file:de.pro.dbw.util.impl.DateConverter.java

License:Open Source License

public Boolean isBefore(int days, Long time) {
    final MutableDateTime mdtNow = MutableDateTime.now();
    mdtNow.addDays(days);//from ww  w.j  a v  a 2s  . c  o m

    final MutableDateTime mdtTime = new MutableDateTime(time);
    return mdtTime.isBefore(mdtNow);
}

From source file:jais.messages.StaticAndVoyageRelatedData.java

License:Apache License

/**
 *
 * @return/*from   w  w w  .j a  va 2s .  c  om*/
 */
public MutableDateTime getETA() {
    StringBuilder eta = new StringBuilder();
    MutableDateTime dt = MutableDateTime.now();
    int year = dt.getYear();
    int month = dt.getMonthOfYear();

    if (_month > 0) {
        // properly formatted month
        if (_month < 10) {
            eta.append("0").append(_month);
        } else if (_month > 12) {
            eta.append("12");
            _month = 12; // use this to validate the days later
        } else {
            eta.append(_month);
        }
        eta.append("/");

        // assume next year
        if (_month < month) {
            year++;
        }

        // prepend datetime string with YYYY/
        eta.insert(0, year).insert(4, "/");

        // recreate the Calendar object based on the validated month
        dt = new MutableDateTime(year, _month, 1, 0, 0, 0, 0, DateTimeZone.UTC);

        // Get the number of days in that month
        int daysInMonth = dt.monthOfYear().getMaximumValue();

        // properly formatted day
        if (_day < 1) {
            eta.append("01");
        } else if (_day < 10) {
            eta.append("0").append(_day);
        } else if (_day >= daysInMonth) {
            eta.append(daysInMonth);
        } else {
            eta.append(_day);
        }
        eta.append(" ");

        // properly formatted hour
        if (_hour < 1) {
            eta.append("00");
        } else if (_hour < 10) {
            eta.append("0").append(_hour);
        } else if (_hour >= 24) {
            eta.append(00);
        } else {
            eta.append(_hour);
        }
        eta.append(":");

        // properly formatted minute
        if (_minute < 1 || _minute > 59) {
            eta.append("00");
        } else if (_minute < 10) {
            eta.append("0").append(_minute);
        } else {
            eta.append(_minute);
        }
    } else {
        // default to epoch if month is invalid
        eta.append("1970/01/01 00:00");
    }

    try {
        dt = MutableDateTime.parse(eta.toString(), ETA_FORMATTER);
    } catch (Exception e) {
        LOG.warn("Invalid ETA, setting to epoch");
        dt = MutableDateTime.parse("1970/01/01 00:00", ETA_FORMATTER);
    }

    return dt;
}

From source file:msi.gaml.expressions.NowUnitExpression.java

License:Open Source License

@Override
public GamaDate value(final IScope scope) {
    return new GamaDate(MutableDateTime.now());
}

From source file:msi.gaml.types.GamaDateType.java

License:Open Source License

public static GamaDate staticCast(final IScope scope, final Object obj, final Object param, final boolean copy)
        throws GamaRuntimeException {
    if (obj == null) {
        return null;
    }//from ww  w  . j a v a  2 s.  c o m
    if (obj instanceof GamaDate) {
        if (copy) {
            return new GamaDate((GamaDate) obj);
        }
        return (GamaDate) obj;
    }
    if (obj instanceof IList) {
        return new GamaDate((IList) obj);
    }
    if (obj instanceof IContainer) {
        return staticCast(scope, ((IContainer) obj).listValue(scope, Types.NO_TYPE, false), param, copy);
    }

    if (obj instanceof String) {
        if ("now".equals(obj.toString())) {
            return new GamaDate(MutableDateTime.now());
        }
        return new GamaDate((String) obj);
    }
    if (obj instanceof Boolean) {
        return new GamaDate();
    }
    int i = Cast.asInt(scope, obj);
    return new GamaDate(i);
}

From source file:org.gdg.frisbee.android.eventseries.EventListFragment.java

License:Apache License

private DateTime getMonthEnd(int month) {
    MutableDateTime date = MutableDateTime.now();
    date.setMillisOfDay(0);/*from  w  w  w. ja v  a2s .  c o m*/
    date.setMonthOfYear(month);

    return date.toDateTime().dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue();
}

From source file:se.toxbee.sleepfighter.service.AlarmPlannerService.java

License:Open Source License

/**
 * Reschedule an {@link Alarm}, that has gone of, to some minutes from now,
 * defined by the alarm itself./*from  w w w  .  ja  v a2s . co m*/
 * 
 * @param alarmId
 *            the alarm's id
 */
private void snooze(int alarmId) {
    Alarm alarm = SFApplication.get().getPersister().fetchAlarmById(alarmId);
    if (alarm == null) {
        throw new IllegalArgumentException("No alarm was found with given id");
    }

    // Determine which time to schedule at by adding offset minutes from alarm to current time
    MutableDateTime dateTime = MutableDateTime.now();

    int mins = alarm.getSnoozeConfig().getSnoozeTime();

    dateTime.addMinutes(mins);

    long scheduleTime = dateTime.getMillis();
    schedule(scheduleTime, alarm);
    showSnoozingNotification(alarm, dateTime.toString("HH:mm"));
}