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.pureblue.quant.util.frequency.Second.java

@Override
public DateTime periodBegin(DateTime time) {
    return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(),
            time.getMinuteOfHour(), time.getSecondOfMinute(), 0, time.getZone());
}

From source file:com.pureblue.quant.util.frequency.Weekly.java

@Override
public DateTime periodBegin(DateTime time) {
    int timeDifference = time.getDayOfWeek() - day.toJodaTimeValue();
    if (timeDifference < 0) {
        timeDifference += 7;/*from w  w w. jav  a  2 s .co  m*/
    }
    DateTime startDay = time.minusDays(timeDifference);
    DateTime weekStart = new DateTime(startDay.getYear(), startDay.getMonthOfYear(), startDay.getDayOfMonth(),
            dayStartTime.getHourOfDay(), dayStartTime.getMinuteOfHour(), dayStartTime.getSecondOfMinute(),
            dayStartTime.getMillisOfSecond(), startDay.getZone());
    if (weekStart.isAfter(time)) {
        return weekStart.minusWeeks(1);
    } else {
        return weekStart;
    }
}

From source file:com.pureblue.quant.util.frequency.Yearly.java

@Override
public DateTime periodBegin(DateTime time) {
    return new DateTime(time.getYear(), 1, 1, 0, 0, 0, 0, time.getZone());
}

From source file:com.qcadoo.localization.api.utils.DateUtils.java

License:Open Source License

/**
 * Parse string into date, with autocomplete missing month, day, hour, minute and second.
 * //from   w  ww .j a  va2s .  c o  m
 * Examples with up-complete:
 * 
 * <ul>
 * <li>2010: 2010-12-31 23:59:59</li>
 * <li>2010-03: 2010-03-31 23:59:59</li>
 * <li>2010-03-06: 2010-03-06 23:59:59</li>
 * <li>2010-03-06 19: 2010-03-06 19:59:59</li>
 * <li>2010-03-06 19:30: 2010-03-06 19:30:59</li>
 * <li>2010-03-06 19:30:20: 2010-03-06 19:30:20</li>
 * </ul>
 * 
 * Examples with down-complete:
 * 
 * <ul>
 * <li>2010: 2010-01-01 00:00:00</li>
 * <li>2010-03: 2010-03-01 00:00:00</li>
 * <li>2010-03-06: 2010-03-06 00:00:00</li>
 * <li>2010-03-06 19: 2010-03-06 19:00:00</li>
 * <li>2010-03-06 19:30: 2010-03-06 19:30:00</li>
 * <li>2010-03-06 19:30:20: 2010-03-06 19:30:20</li>
 * </ul>
 * 
 * @param dateExpression
 *            string with date expression
 * @param upComplete
 *            true if up-complete, otherwise down-complete
 * @return parsed date
 * @throws ParseException
 *             if year, month, day, hour, minute or second is invalid or when year is &lt; 1500 or &gt; 2500
 */
public static Date parseAndComplete(final String dateExpression, final boolean upComplete)
        throws ParseException {
    final String trimmedDateExpression = StringUtils.trim(dateExpression);
    DateTime parsedDate = new DateTime(org.apache.commons.lang3.time.DateUtils
            .parseDateStrictly(trimmedDateExpression, SUPPORTED_PATTERNS));

    final String[] dateAndTime = trimmedDateExpression.split(" ");
    if (dateAndTime.length > 2 || parsedDate.getYear() < 1500 || parsedDate.getYear() > 2500) {
        throw new ParseException(L_WRONG_DATE, 1);
    }

    return round(parsedDate, upComplete, dateAndTime).toDate();
}

From source file:com.qcadoo.model.internal.types.DateTimeType.java

License:Open Source License

@Override
public ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value) {
    if (value instanceof Date) {
        return ValueAndError.withoutError(value);
    }/*from   w  w  w .j a  v  a2  s  .c om*/
    try {
        DateTimeFormatter fmt = DateTimeFormat.forPattern(DateUtils.L_DATE_TIME_FORMAT);
        DateTime dt = fmt.parseDateTime(String.valueOf(value));
        int year = dt.getYear();
        if (year < 1500 || year > 2500) {
            return ValueAndError.withError("qcadooView.validate.field.error.invalidDateTimeFormat");
        }
        return ValueAndError.withoutError(dt.toDate());
    } catch (IllegalArgumentException e) {
        return ValueAndError.withError("qcadooView.validate.field.error.invalidDateTimeFormat");
    }
}

From source file:com.qcadoo.model.internal.types.DateType.java

License:Open Source License

@Override
public ValueAndError toObject(final FieldDefinition fieldDefinition, final Object value) {
    if (value instanceof Date) {
        return ValueAndError.withoutError(value);
    }/*from  w  w w  . j a  v  a  2s  . c  o  m*/
    try {
        DateTimeFormatter fmt = DateTimeFormat.forPattern(DateUtils.L_DATE_FORMAT);
        DateTime dt = fmt.parseDateTime(String.valueOf(value));

        int year = dt.getYear();
        if (year < 1500 || year > 2500) {
            return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat.range");
        }

        Date date = dt.toDate();

        if (year < 2000) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.YEAR, dt.getYear());
            c.set(Calendar.MONTH, dt.getMonthOfYear() - 1);
            c.set(Calendar.DAY_OF_MONTH, dt.getDayOfMonth());
            c.set(Calendar.HOUR_OF_DAY, dt.hourOfDay().get());
            c.set(Calendar.MINUTE, dt.getMinuteOfHour());
            c.set(Calendar.SECOND, dt.getSecondOfMinute());
            c.set(Calendar.MILLISECOND, dt.getMillisOfSecond());
            date = c.getTime();
        }

        return ValueAndError.withoutError(date);
    } catch (IllegalArgumentException e) {
        return ValueAndError.withError("qcadooView.validate.field.error.invalidDateFormat");
    }
}

From source file:com.revetkn.achewood.AchewoodExtractor.java

License:Open Source License

/**
 * Helper method to build an 'organized' storage path for saved strips by examining
 * the strip's date.//w ww  .j a va2  s .c om
 * <p>
 * General format is <tt>BASE_SAVED_DIRECTORY</tt>/Year/Month.
 * @param stripDate Date from which the directory structure is built.
 * @return A storage path for the given strip date.
 */
protected String createStoragePath(DateTime stripDate) {
    return BASE_SAVED_DIRECTORY + File.separator + stripDate.getYear() + File.separator
            + MONTH_ONLY_DATE_FORMATTER.print(stripDate);
}

From source file:com.robwilliamson.healthyesther.reminder.TimingModel.java

License:Open Source License

private RangeSet allowedTimes() {
    DateTime yesterday = mEnvironment.getNow().minus(Duration.standardDays(1));
    return mAllowedNotificationTimes.startingFrom(yesterday.getYear(), yesterday.getMonthOfYear(),
            yesterday.getDayOfMonth());//from   ww w  . j a  v a 2s . c  o  m
}

From source file:com.robwilliamson.healthyesther.util.time.RangeSet.java

License:Open Source License

@Override
public RangeSet startingFrom(int year, int monthOfYear, int dayOfMonth) {
    Duration shift = Duration
            .millis(from.withDate(year, monthOfYear, dayOfMonth).getMillis() - from.getMillis());
    Set<TimeRegion> regions = new HashSet<>(mTimeRegions.size());

    for (TimeRegion region : mTimeRegions) {
        DateTime newFrom = region.from.plus(shift);
        regions.add(region.startingFrom(newFrom.getYear(), newFrom.getMonthOfYear(), newFrom.getDayOfMonth()));
    }//from  ww w .j  a  v a 2  s . com

    return new RangeSet(regions.toArray(new TimeRegion[] {}));
}

From source file:com.serotonin.mango.vo.report.ReportVO.java

License:Open Source License

public ReportVO() {
    // Default the specific date fields.
    DateTime dt = DateUtils.truncateDateTime(new DateTime(), Common.TimePeriods.DAYS);
    toYear = dt.getYear();
    toMonth = dt.getMonthOfYear();/*from www . j  a  va  2  s. c  o m*/
    toDay = dt.getDayOfMonth();
    toHour = dt.getHourOfDay();
    toMinute = dt.getMinuteOfHour();

    dt = DateUtils.minus(dt, Common.TimePeriods.DAYS, 1);
    fromYear = dt.getYear();
    fromMonth = dt.getMonthOfYear();
    fromDay = dt.getDayOfMonth();
    fromHour = dt.getHourOfDay();
    fromMinute = dt.getMinuteOfHour();
}