List of usage examples for org.joda.time MutableDateTime MutableDateTime
public MutableDateTime(Object instant)
From source file:org.hippoecm.frontend.plugins.yui.datetime.YuiDateTimeField.java
License:Apache License
private void updateDateTime() { Date date = getDate();/*w ww .j av a2 s .c om*/ if (date != null) { MutableDateTime datetime = new MutableDateTime(date); try { TimeZone zone = getClientTimeZone(); if (zone != null) { datetime.setZone(DateTimeZone.forTimeZone(zone)); } Integer hours = getHours(); if (hours != null) { datetime.set(DateTimeFieldType.hourOfDay(), hours % 24); Integer minutes = getMinutes(); datetime.setMinuteOfHour(minutes != null ? minutes : 0); } // the date will be in the server's timezone setDate(datetime.toDate()); //setModelObject(datetime.toDate()); } catch (RuntimeException e) { error(e.getMessage()); invalid(); } } }
From source file:org.hippoecm.frontend.widgets.AjaxDateTimeField.java
License:Apache License
private void updateDateTime(Object datetime, Integer hours, Integer minutes, AjaxRequestTarget target) { MutableDateTime date = new MutableDateTime(datetime); try {/* w w w . j ava 2s.c o m*/ TimeZone zone = getClientTimeZone(); if (zone != null) { date.setZone(DateTimeZone.forTimeZone(zone)); } if (hours != null) { date.set(DateTimeFieldType.hourOfDay(), hours.intValue() % 24); date.setMinuteOfHour((minutes != null) ? minutes.intValue() : 0); } // the date will be in the server's timezone setModelObject(date.toDate()); if (target != null) { target.add(this); } } catch (RuntimeException e) { error(e.getMessage()); invalid(); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJodaSetYear() { int COUNT = COUNT_FAST; // Is it fair to use only MutableDateTime here? You decide. MutableDateTime dt = new MutableDateTime(GJChronology.getInstance()); for (int i = 0; i < AVERAGE; i++) { start("Joda", "setYear"); for (int j = 0; j < COUNT; j++) { dt.setYear(1972);/*from ww w . j a va 2 s.co m*/ if (dt == null) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJodaSetHour() { int COUNT = COUNT_VERY_FAST; // Is it fair to use only MutableDateTime here? You decide. MutableDateTime dt = new MutableDateTime(GJChronology.getInstance()); for (int i = 0; i < AVERAGE; i++) { start("Joda", "setHour"); for (int j = 0; j < COUNT; j++) { dt.setHourOfDay(13);//from www .j a v a 2 s. c om if (dt == null) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.joda.example.time.DateTimePerformance.java
License:Apache License
private void checkJodaSetGetHour() { int COUNT = COUNT_VERY_FAST; // Is it fair to use only MutableDateTime here? You decide. MutableDateTime dt = new MutableDateTime(GJChronology.getInstance()); for (int i = 0; i < AVERAGE; i++) { start("Joda", "setGetHour"); for (int j = 0; j < COUNT; j++) { dt.setHourOfDay(13);/*from ww w. ja v a 2 s .c o m*/ int val = dt.getHourOfDay(); if (dt == null) { System.out.println("Anti optimise"); } } end(COUNT); } }
From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java
License:Educational Community License
public static DateTime getLowerDateTimeBound(String dateRange) throws ParseException { Range range = SearchExpressionUtils.parseRange(dateRange); if (range == null) { throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange); }/*from w ww .j av a 2 s .c o m*/ if (range.getLowerBoundValue() != null) { java.util.Date lowerRangeDate = null; try { lowerRangeDate = CoreApiServiceLocator.getDateTimeService() .convertToDate(range.getLowerBoundValue()); } catch (ParseException pe) { GlobalVariables.getMessageMap().putError("dateFrom", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage()); } MutableDateTime dateTime = new MutableDateTime(lowerRangeDate); dateTime.setMillisOfDay(0); return dateTime.toDateTime(); } return null; }
From source file:org.kuali.rice.kew.docsearch.DocumentSearchInternalUtils.java
License:Educational Community License
public static DateTime getUpperDateTimeBound(String dateRange) throws ParseException { Range range = SearchExpressionUtils.parseRange(dateRange); if (range == null) { throw new IllegalArgumentException("Failed to parse date range from given string: " + dateRange); }//from w w w .j a v a 2 s . c om if (range.getUpperBoundValue() != null) { java.util.Date upperRangeDate = null; try { upperRangeDate = CoreApiServiceLocator.getDateTimeService() .convertToDate(range.getUpperBoundValue()); } catch (ParseException pe) { GlobalVariables.getMessageMap().putError("dateCreated", RiceKeyConstants.ERROR_CUSTOM, pe.getMessage()); } MutableDateTime dateTime = new MutableDateTime(upperRangeDate); // set it to the last millisecond of the day dateTime.setMillisOfDay((24 * 60 * 60 * 1000) - 1); return dateTime.toDateTime(); } return null; }
From source file:org.kuali.student.enrollment.class2.acal.util.AcalCommonUtils.java
License:Educational Community License
public static Date getDateWithTime(Date date, String hourMinute, String amPm) { if (null == date) { return null; }/*ww w .j a va 2 s . c om*/ MutableDateTime dateTime = new MutableDateTime(date); if (StringUtils.isNotBlank(hourMinute)) { int hour = Integer.parseInt(StringUtils.substringBefore(hourMinute, ":")); if (StringUtils.equalsIgnoreCase(amPm, "PM")) { // 24-hour clock; e.g. 12 PM = hour 12; 8 PM = hour 20 if (hour < 12) { hour += 12; } } else // if amPm is blank/null, assume AM if (hour == 12) { hour = 0; // 12 AM is stored in Calendar as hour 0 } dateTime.setTime(hour, Integer.parseInt(StringUtils.substringAfter(hourMinute, ":")), 0, 0); } return dateTime.toDate(); }
From source file:org.springframework.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
/** * For each query, we need to convert the interval into two variations. One is the start and end points rounded to * the resolution (used to calculate the number of entries to be returned from the query). The second is the start * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the * start day as the start index into the first array, and writing the total number of entries in sequence from that * point into the combined result counts array. *//* www . ja v a2 s .co m*/ @Override public AggregateCounter getCounts(String name, Interval interval, AggregateCounterResolution resolution) { DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCounterResolution.minute) { // Iterate through each hour in the interval and load the minutes for it MutableDateTime dt = new MutableDateTime(interval.getStart()); dt.setRounding(c.hourOfDay()); Duration step = Duration.standardHours(1); List<long[]> hours = new ArrayList<long[]>(); while (dt.isBefore(end) || dt.isEqual(end)) { hours.add(getMinCountsForHour(name, dt)); dt.add(step); } counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCounterResolution.hour) { DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis())); List<long[]> days = new ArrayList<long[]>(); Duration step = Duration.standardHours(24); while (cursor.isBefore(end)) { days.add(getHourCountsForDay(name, cursor)); cursor = cursor.plus(step); } counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCounterResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis())); List<long[]> months = new ArrayList<long[]>(); DateTime endMonth = new DateTime( c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis())); while (cursor.isBefore(endMonth)) { months.add(getDayCountsForMonth(name, cursor)); cursor = cursor.plusMonths(1); } counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays); } else if (resolution == AggregateCounterResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> years = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis())); while (cursor.isBefore(endYear)) { years.add(getMonthCountsForYear(name, cursor)); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCounterResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); Map<String, Long> yearCounts = getYearCounts(name); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { int year = startYear.plusYears(i).getYear(); Long count = yearCounts.get(Integer.toString(year)); if (count == null) { count = 0L; } counts[i] = count; } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCounter(name, interval, counts, resolution); }
From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
/** * For each query, we need to convert the interval into two variations. One is the start and end points rounded to * the resolution (used to calculate the number of entries to be returned from the query). The second is the start * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the * start day as the start index into the first array, and writing the total number of entries in sequence from that * point into the combined result counts array. *//*from w w w. j a v a2 s. c o m*/ @Override public AggregateCount getCounts(String name, Interval interval, AggregateCountResolution resolution) { DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCountResolution.minute) { // Iterate through each hour in the interval and load the minutes for it MutableDateTime dt = new MutableDateTime(interval.getStart()); dt.setRounding(c.hourOfDay()); Duration step = Duration.standardHours(1); List<long[]> hours = new ArrayList<long[]>(); while (dt.isBefore(end) || dt.isEqual(end)) { hours.add(getMinCountsForHour(name, dt)); dt.add(step); } counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCountResolution.hour) { DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis())); List<long[]> days = new ArrayList<long[]>(); Duration step = Duration.standardHours(24); while (cursor.isBefore(end)) { days.add(getHourCountsForDay(name, cursor)); cursor = cursor.plus(step); } counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCountResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis())); List<long[]> months = new ArrayList<long[]>(); DateTime endMonth = new DateTime( c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis())); while (cursor.isBefore(endMonth)) { months.add(getDayCountsForMonth(name, cursor)); cursor = cursor.plusMonths(1); } counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays); } else if (resolution == AggregateCountResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> years = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis())); while (cursor.isBefore(endYear)) { years.add(getMonthCountsForYear(name, cursor)); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCountResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); Map<String, Long> yearCounts = getYearCounts(name); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { int year = startYear.plusYears(i).getYear(); Long count = yearCounts.get(Integer.toString(year)); if (count == null) { count = 0L; } counts[i] = count; } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCount(name, interval, counts, resolution); }