public Calendar truncate(Calendar calendar) { Calendar cal = Calendar.getInstance(); cal.setTime(truncate(calendar.getTime())); return cal; }
public Calendar truncate(Calendar calendar) { Calendar cal = Calendar.getInstance(); cal.setTime(truncate(calendar.getTime())); return cal; }
private TimePartition(@NonNull UpdatePeriod updatePeriod, @NonNull Date date) { this.updatePeriod = updatePeriod; this.date = updatePeriod.truncate(date); this.dateString = updatePeriod.format(this.date); }
private static CoveringInfo getMilliSecondCoveringInfo(Date from, Date to, long millisInInterval, UpdatePeriod interval) { long diff = to.getTime() - from.getTime(); return new CoveringInfo((int) (diff / millisInInterval), Stream.of(from, to).allMatch(a->interval.truncate(a).equals(a))); // start date and end date should lie on boundaries. }
private TimePartition(@NonNull UpdatePeriod updatePeriod, @NonNull Date date) { this.updatePeriod = updatePeriod; this.date = updatePeriod.truncate(date); this.dateString = updatePeriod.format(this.date); }
private static CoveringInfo getMilliSecondCoveringInfo(Date from, Date to, long millisInInterval, UpdatePeriod interval) { long diff = to.getTime() - from.getTime(); return new CoveringInfo((int) (diff / millisInInterval), Stream.of(from, to).allMatch(a->interval.truncate(a).equals(a))); // start date and end date should lie on boundaries. }
public static Date resolveRelativeDate(String str, Date now) throws LensException { if (StringUtils.isBlank(str)) { throw new LensException(LensCubeErrorCode.NULL_DATE_VALUE.getLensErrorInfo()); } // Resolve NOW with proper granularity Calendar calendar = Calendar.getInstance(); calendar.setTime(now); str = str.toLowerCase(); Matcher relativeMatcher = P_RELATIVE.matcher(str); if (relativeMatcher.find()) { String nowWithGranularity = relativeMatcher.group(); nowWithGranularity = nowWithGranularity.replaceAll("now", ""); nowWithGranularity = nowWithGranularity.replaceAll("\\.", ""); Matcher granularityMatcher = P_UNIT.matcher(nowWithGranularity); if (granularityMatcher.find()) { calendar = UpdatePeriod.fromUnitName(granularityMatcher.group().toLowerCase()).truncate(calendar); } } // Get rid of 'now' part and whitespace String diffStr = str.replaceAll(RELATIVE, "").replace(WSPACE, ""); TimeDiff diff = TimeDiff.parseFrom(diffStr); return diff.offsetFrom(calendar.getTime()); }
public static Date resolveRelativeDate(String str, Date now) throws LensException { if (StringUtils.isBlank(str)) { throw new LensException(LensCubeErrorCode.NULL_DATE_VALUE.getLensErrorInfo()); } // Resolve NOW with proper granularity Calendar calendar = Calendar.getInstance(); calendar.setTime(now); str = str.toLowerCase(); Matcher relativeMatcher = P_RELATIVE.matcher(str); if (relativeMatcher.find()) { String nowWithGranularity = relativeMatcher.group(); nowWithGranularity = nowWithGranularity.replaceAll("now", ""); nowWithGranularity = nowWithGranularity.replaceAll("\\.", ""); Matcher granularityMatcher = P_UNIT.matcher(nowWithGranularity); if (granularityMatcher.find()) { calendar = UpdatePeriod.fromUnitName(granularityMatcher.group().toLowerCase()).truncate(calendar); } } // Get rid of 'now' part and whitespace String diffStr = str.replaceAll(RELATIVE, "").replace(WSPACE, ""); TimeDiff diff = TimeDiff.parseFrom(diffStr); return diff.offsetFrom(calendar.getTime()); }
public DateOffsetProvider(UpdatePeriod updatePeriod, boolean truncate) { this.updatePeriod = updatePeriod; Date date = calendar.getTime(); if (truncate) { date = updatePeriod.truncate(date); calendar.setTime(date); } put(0, date); }
@Test(dataProvider = "update-periods") public void testFormat(UpdatePeriod period) throws Exception { RandomDateGenerator randomDateGenerator = new RandomDateGenerator(); for (int i = 0; i < 5000; i++) { Date randomDate = randomDateGenerator.nextDate(); randomDate = period.truncate(randomDate); assertEquals(randomDate, period.parse(period.format(randomDate))); } } }
private XTimePartSpecElement createTimePartSpecElement(Date partDate, String timeDimension) { XTimePartSpecElement timePart = cubeObjectFactory.createXTimePartSpecElement(); timePart.setKey(timeDimension); timePart.setValue(JAXBUtils.getXMLGregorianCalendar(HOURLY.truncate(partDate))); return timePart; }