Example usage for org.joda.time DateTime getYear

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

Introduction

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

Prototype

public int getYear() 

Source Link

Document

Get the year field value.

Usage

From source file:com.serotonin.mango.web.dwr.BaseDwr.java

License:Open Source License

public Map<String, Object> getDateRangeDefaults(int periodType, int period) {
    Map<String, Object> result = new HashMap<String, Object>();

    // Default the specific date fields.
    DateTime dt = new DateTime();
    result.put("toYear", dt.getYear());
    result.put("toMonth", dt.getMonthOfYear());
    result.put("toDay", dt.getDayOfMonth());
    result.put("toHour", dt.getHourOfDay());
    result.put("toMinute", dt.getMinuteOfHour());
    result.put("toSecond", 0);

    dt = DateUtils.minus(dt, periodType, period);
    result.put("fromYear", dt.getYear());
    result.put("fromMonth", dt.getMonthOfYear());
    result.put("fromDay", dt.getDayOfMonth());
    result.put("fromHour", dt.getHourOfDay());
    result.put("fromMinute", dt.getMinuteOfHour());
    result.put("fromSecond", 0);

    return result;
}

From source file:com.serotonin.mango.web.dwr.MaintenanceEventsDwr.java

License:Open Source License

public DwrResponseI18n getMaintenanceEvent(int id) {
    Permissions.ensureAdmin();//from www.ja  va  2 s  .c  om

    DwrResponseI18n response = new DwrResponseI18n();

    MaintenanceEventVO me;
    boolean activated = false;
    if (id == Common.NEW_ID) {
        DateTime dt = new DateTime();
        me = new MaintenanceEventVO();
        me.setXid(new MaintenanceEventDao().generateUniqueXid());
        me.setActiveYear(dt.getYear());
        me.setInactiveYear(dt.getYear());
        me.setActiveMonth(dt.getMonthOfYear());
        me.setInactiveMonth(dt.getMonthOfYear());
    } else {
        me = new MaintenanceEventDao().getMaintenanceEvent(id);

        MaintenanceEventRT rt = Common.ctx.getRuntimeManager().getRunningMaintenanceEvent(me.getId());
        if (rt != null)
            activated = rt.isEventActive();
    }

    response.addData("me", me);
    response.addData("activated", activated);

    return response;
}

From source file:com.serotonin.mango.web.dwr.ScheduledEventsDwr.java

License:Open Source License

public ScheduledEventVO getScheduledEvent(int id) {
    Permissions.ensureDataSourcePermission(Common.getUser());

    if (id == Common.NEW_ID) {
        DateTime dt = new DateTime();
        ScheduledEventVO se = new ScheduledEventVO();
        se.setXid(new ScheduledEventDao().generateUniqueXid());
        se.setActiveYear(dt.getYear());
        se.setInactiveYear(dt.getYear());
        se.setActiveMonth(dt.getMonthOfYear());
        se.setInactiveMonth(dt.getMonthOfYear());
        return se;
    }/*from  www  . ja  v a 2 s  .c  om*/
    return new ScheduledEventDao().getScheduledEvent(id);
}

From source file:com.sonicle.webtop.mail.bol.js.JsSmartSearchTotals.java

License:Open Source License

public void addDate(Date d) {
    synchronized (lock) {
        DateTime ydt = new DateTime(d);
        Year y = new Year(ydt.getYear());
        int iy = years.indexOf(y);
        if (iy >= 0)
            y = years.get(iy);/*ww  w .j  a v  a  2  s  .  c om*/
        else
            years.add(y);
        y.total++;
        y.addDate(ydt);
    }
}

From source file:com.spears.objects.io.DatedFileAppenderImpl.java

License:Open Source License

private static String generateFilename(String rootpath) {
    String filename;//from  w  ww  .  j a  v a 2 s  . co  m
    DateTime date = new DateTime();
    int ver = 1;
    do {
        filename = String.format("%s/%d/%d/%d/LOG_%s_(%d).log", rootpath, date.getYear(), date.getMonthOfYear(),
                date.getDayOfMonth(), date.toString(DateTimeFormat.forPattern("MM-dd-yyyy_HH.mm")), ver);
        ver++;
    } while (new File(filename).exists());
    return filename;
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

public void setValue(DateTime value) throws StandardException {
    restoreToNull();//from   w w  w  . j a  v  a2  s  . com
    encodedDate = computeEncodedDate(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth());
    isNull = evaluateNull();
}

From source file:com.splicemachine.db.iapi.types.SQLDate.java

License:Apache License

static int computeEncodedDate(DateTime dateTime) throws StandardException {
    return computeEncodedDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth());

}

From source file:com.splicemachine.db.iapi.types.SQLTimestamp.java

License:Apache License

private static int computeEncodedDate(DateTime value) throws StandardException {
    if (value == null)
        return 0;

    return SQLDate.computeEncodedDate(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth());
}

From source file:com.splicemachine.derby.utils.SpliceDateFunctions.java

License:Apache License

/**
 * Implements the trunc_date function/*ww w . j  a v a  2 s.  com*/
 */
public static Timestamp TRUNC_DATE(Timestamp source, String field) throws SQLException {
    if (source == null || field == null)
        return null;
    DateTime dt = new DateTime(source);
    field = field.toLowerCase();
    String lowerCaseField = field.toLowerCase();
    if ("microseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000;
        source.setNanos(nanos);
        return source;
    } else if ("milliseconds".equals(lowerCaseField)) {
        int nanos = source.getNanos();
        nanos = nanos - nanos % 1000000;
        source.setNanos(nanos);
        return source;
    } else if ("second".equals(lowerCaseField)) {
        source.setNanos(0);
        return source;

    } else if ("minute".equals(lowerCaseField)) {
        DateTime modified = dt.minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("hour".equals(lowerCaseField)) {
        DateTime modified = dt.minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("day".equals(lowerCaseField)) {
        DateTime modified = dt.minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("week".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.getDayOfWeek()).minusHours(dt.getHourOfDay())
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("month".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("quarter".equals(lowerCaseField)) {
        int month = dt.getMonthOfYear();
        DateTime modified = dt;
        if ((month + 1) % 3 == 1) {
            modified = dt.minusMonths(2);
        } else if ((month + 1) % 3 == 0) {
            modified = dt.minusMonths(1);
        }
        DateTime fin = modified.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(fin.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("year".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusMonths(dt.getMonthOfYear() - 1)
                .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("decade".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusYears(dt.getYear() % 10).minusHours(dt.getHourOfDay())
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("century".equals(lowerCaseField)) {
        DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1)
                .minusHours(dt.getHourOfDay()).minusYears(dt.getYear() % 100)
                .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour())
                .minusSeconds(dt.getSecondOfMinute());
        Timestamp ret = new Timestamp(modified.getMillis());
        ret.setNanos(0);
        return ret;
    } else if ("millennium".equals(lowerCaseField)) {
        int newYear = dt.getYear() - dt.getYear() % 1000;
        //noinspection deprecation (converstion from joda to java.sql.Timestamp did not work for millennium < 2000)
        return new Timestamp(newYear - 1900, Calendar.JANUARY, 1, 0, 0, 0, 0);
    } else {
        throw new SQLException(String.format("invalid time unit '%s'", field));
    }
}

From source file:com.spotify.heroic.shell.Tasks.java

License:Apache License

private static long parseTodayInstant(String input, final Chronology chrono, long now) {
    final DateTime n = new DateTime(now, chrono);

    for (final DateTimeParser p : today) {
        final DateTimeParserBucket bucket = new DateTimeParserBucket(0, chrono, null, null, 2000);

        bucket.saveField(chrono.year(), n.getYear());
        bucket.saveField(chrono.monthOfYear(), n.getMonthOfYear());
        bucket.saveField(chrono.dayOfYear(), n.getDayOfYear());

        try {//from w  ww.  j  ava  2 s  .c o m
            p.parseInto(bucket, input, 0);
        } catch (IllegalArgumentException e) {
            // pass-through
            continue;
        }

        return bucket.computeMillis();
    }

    throw new IllegalArgumentException(input + " is not a valid instant");
}