List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
From source file:com.pureblue.quant.util.frequency.Minute.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), time.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), 0, 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Monthly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear(), 1, 0, 0, 0, 0, time.getZone()); }
From source file:com.pureblue.quant.util.frequency.Quarterly.java
@Override public DateTime periodBegin(DateTime time) { return new DateTime(time.getYear(), time.getMonthOfYear() - ((time.getMonthOfYear() - 1) % 3), 1, 0, 0, 0, 0, time.getZone());/* w ww . ja va 2 s . com*/ }
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;/* ww w.ja v a 2s . c om*/ } 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.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); }/*w w w . jav a 2 s. com*/ 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.redprairie.moca.server.db.translate.filter.TU_FunctionMonthsBetween.java
License:Open Source License
public void testMonthsBetween() throws MocaException { String sql;//from ww w . j a va2s .co m sql = "select months_between(sysdate, sysdate) result from dual"; runTest(sql, "result", 0); DateTime now = new DateTime(); DateTime then = now.minusDays(60); // We have to find the correct difference of months. Since we could // be crossing a year we have to make sure to normalize it if so by // adding 12 months to it. int monthDifference = (monthDifference = now.getMonthOfYear() - then.getMonthOfYear()) < 0 ? monthDifference + 12 : monthDifference; // There is technically still a race condition if the month of year // changes after we calculate it but before we execute that this could // fail when going to a month that differs in the number of months when // subtracting 60 days. sql = "select round(months_between(sysdate, sysdate-/*=moca_util.days(*/ 60 /*=)*/)) result from dual"; runTest(sql, "result", monthDifference); sql = "select round(months_between(sysdate-/*=moca_util.days(*/ 60 /*=)*/, sysdate)) result from dual"; runTest(sql, "result", -monthDifference); }
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 w w w . j a va2 s . 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())); }/* w ww .j a va 2s. c o m*/ return new RangeSet(regions.toArray(new TimeRegion[] {})); }
From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java
License:Open Source License
private static DateTime dateTimeCeiling(DateTime dt, Period p) { if (p.getYears() != 0) { return dt.yearOfEra().roundCeilingCopy().minusYears(dt.getYearOfEra() % p.getYears()); } else if (p.getMonths() != 0) { return dt.monthOfYear().roundCeilingCopy().minusMonths((dt.getMonthOfYear() - 1) % p.getMonths()); } else if (p.getWeeks() != 0) { return dt.weekOfWeekyear().roundCeilingCopy().minusWeeks((dt.getWeekOfWeekyear() - 1) % p.getWeeks()); } else if (p.getDays() != 0) { return dt.dayOfMonth().roundCeilingCopy().minusDays((dt.getDayOfMonth() - 1) % p.getDays()); } else if (p.getHours() != 0) { return dt.hourOfDay().roundCeilingCopy().minusHours(dt.getHourOfDay() % p.getHours()); } else if (p.getMinutes() != 0) { return dt.minuteOfHour().roundCeilingCopy().minusMinutes(dt.getMinuteOfHour() % p.getMinutes()); } else if (p.getSeconds() != 0) { return dt.secondOfMinute().roundCeilingCopy().minusSeconds(dt.getSecondOfMinute() % p.getSeconds()); }//w ww . j a v a 2 s .c o m return dt.millisOfSecond().roundCeilingCopy().minusMillis(dt.getMillisOfSecond() % p.getMillis()); }