public static Searches.DateHistogramInterval buildInterval(@Nullable final String intervalParam, final TimeRange timeRange) { if (!isNullOrEmpty(intervalParam)) { final String interval = intervalParam.toUpperCase(Locale.ENGLISH); if (!validateInterval(interval)) { throw new IllegalArgumentException("Invalid interval: \"" + interval + "\""); } return Searches.DateHistogramInterval.valueOf(interval); } final Duration duration = Duration.millis(timeRange.getTo().getMillis() - timeRange.getFrom().getMillis()); // This is the same as SearchPage#_determineHistogramResolution() in the UI code if (duration.getStandardHours() < 12) { return Searches.DateHistogramInterval.MINUTE; } else if (duration.getStandardDays() < 3) { return Searches.DateHistogramInterval.HOUR; } else if (duration.getStandardDays() < 30) { return Searches.DateHistogramInterval.DAY; } else if (duration.getStandardDays() < (30 * 2)) { return Searches.DateHistogramInterval.WEEK; } else if (duration.getStandardDays() < (30 * 18)) { return Searches.DateHistogramInterval.MONTH; } else if (duration.getStandardDays() < (365 * 3)) { return Searches.DateHistogramInterval.QUARTER; } else { return Searches.DateHistogramInterval.YEAR; } }
/** * Converts this duration to a period in days assuming that there are the * standard number of milliseconds in a day. * <p> * This method assumes that there are 24 hours in a day, * 60 minutes in an hour, 60 seconds in a minute and 1000 milliseconds in * a second. This will be true for most days, however days with Daylight * Savings changes will not have 24 hours, so use this method with care. * * @return a period representing the number of standard days in this period, never null * @throws ArithmeticException if the number of days is too large to be represented * @since 2.0 */ public Days toStandardDays() { long days = getStandardDays(); return Days.days(FieldUtils.safeToInt(days)); }
/** * Converts this duration to a period in days assuming that there are the * standard number of milliseconds in a day. * <p> * This method assumes that there are 24 hours in a day, * 60 minutes in an hour, 60 seconds in a minute and 1000 milliseconds in * a second. This will be true for most days, however days with Daylight * Savings changes will not have 24 hours, so use this method with care. * * @return a period representing the number of standard days in this period, never null * @throws ArithmeticException if the number of days is too large to be represented * @since 2.0 */ public Days toStandardDays() { long days = getStandardDays(); return Days.days(FieldUtils.safeToInt(days)); }
public static String humanDuration(final Duration dur) { final Period p = dur.toPeriod().normalizedStandard(); if (dur.getStandardSeconds() == 0) { return "0 seconds"; } else if (dur.getStandardSeconds() < 60) { return format("%d second%s", p.getSeconds(), p.getSeconds() > 1 ? "s" : ""); } else if (dur.getStandardMinutes() < 60) { return format("%d minute%s", p.getMinutes(), p.getMinutes() > 1 ? "s" : ""); } else if (dur.getStandardHours() < 24) { return format("%d hour%s", p.getHours(), p.getHours() > 1 ? "s" : ""); } else { return format("%d day%s", dur.getStandardDays(), dur.getStandardDays() > 1 ? "s" : ""); } }
/** * Converts this duration to a period in days assuming that there are the * standard number of milliseconds in a day. * <p> * This method assumes that there are 24 hours in a day, * 60 minutes in an hour, 60 seconds in a minute and 1000 milliseconds in * a second. This will be true for most days, however days with Daylight * Savings changes will not have 24 hours, so use this method with care. * * @return a period representing the number of standard days in this period, never null * @throws ArithmeticException if the number of days is too large to be represented * @since 2.0 */ public Days toStandardDays() { long days = getStandardDays(); return Days.days(FieldUtils.safeToInt(days)); }
private int daysInYear(int year) { Duration d = new Duration(new DateTime(year, 1, 1, 0, 0), new DateTime(year + 1, 1, 1, 0, 0)); return (int)d.getStandardDays(); }
private int daysInYear(int year) { Duration d = new Duration(new DateTime(year, 1, 1, 0, 0), new DateTime(year + 1, 1, 1, 0, 0)); return toIntExact(d.getStandardDays()); }
public MetricsIndexRowTransformer(String tenantId, MetricType<T> type, int defaultTTL) { this.type = type; this.tenantId = tenantId; this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays(); }
public MetricFromDataRowTransformer(String tenantId, MetricType<T> type, int defaultTTL) { this.type = type; this.tenantId = tenantId; this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays(); }
public MetricFromDataRowTransformer(String tenantId, MetricType<T> type, int defaultTTL) { this.type = type; this.tenantId = tenantId; this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays(); }
public MetricsIndexRowTransformer(String tenantId, MetricType<T> type, int defaultTTL) { this.type = type; this.tenantId = tenantId; this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays(); }
private DateTime getRandomDate(DateTime from, DateTime to) { Duration duration = new Duration(from, to); long diffInDays = duration.getStandardDays(); return from.plusDays((int) randomHelper.number(diffInDays) + 1); } }
public MetricIdentifierFromFullDataRowTransformer(int defaultTTL) { this.defaultDataRetention = (int) Duration.standardSeconds(defaultTTL).getStandardDays(); }
public List<String> getDates() { List<String> result = new ArrayList<String>(); int duration = (int) new Duration(this.getBeginningAsDate(), new DateTime(this.getEnd())).getStandardDays(); for (int i = 0; i <= duration; i++) { result.add(DateFormat.getDateInstance().format(this.getBeginningAsDate().plusDays(i).toDate())); } return result; }
/** * Returns the days until the demo expire. * * @param date * the current {@link DateTime} date. * * @return the {@link Long} days left. */ public long getDaysLeftDemo(DateTime date) { DateTime installDate = registration.getInstallDate(); long days = new Duration(installDate, date).getStandardDays(); return getDaysDemo() - days; }
private double getIntervalCostMultiplier() { int days = 0; for (Interval interval : intervals) { days += interval.toDuration().getStandardDays(); } // Cost increases with the wider interval being queries. // A plan querying 10 or more years of data will have 10x the cost of a // plan returning 1 day data. // A plan where least interval is queries will be preferred. return RelMdUtil.linear(days, 1, DAYS_IN_TEN_YEARS, 0.1d, 1d); }
private double getIntervalCostMultiplier() { int days = 0; for (Interval interval : intervals) { days += interval.toDuration().getStandardDays(); } // Cost increases with the wider interval being queries. // A plan querying 10 or more years of data will have 10x the cost of a // plan returning 1 day data. // A plan where least interval is queries will be preferred. return RelMdUtil.linear(days, 1, DAYS_IN_TEN_YEARS, 0.1d, 1d); }
public Long getFeedsDuration() throws ParseException { String d = statementsMap.mapValue(FEEDS, FEEDS_DURATION); if (d != null) { return durationFormatFactory.create().parse(d).getStandardDays(); } else { return null; } }
@Override public int daysInYear( int year ) { LocalDate localDate = new LocalDate( year, 1, 1, chronology ); return (int) localDate.toDateTimeAtStartOfDay().year().toInterval().toDuration().getStandardDays(); }
private void init() { LocalDate firstDate = new LocalDate(year, month, 1); startDate = firstDate.withDayOfWeek(DateTimeConstants.MONDAY); LocalDate lastDate = firstDate.withDayOfMonth(firstDate.dayOfMonth().getMaximumValue()); LocalDate endDate; if (lastDate.getDayOfWeek() != DateTimeConstants.SUNDAY) { endDate = lastDate.withDayOfWeek(DateTimeConstants.SUNDAY); } else { endDate = lastDate; } Duration d = new Duration(startDate.toDateMidnight(DateTimeZone.UTC), endDate.toDateMidnight(DateTimeZone.UTC)); nbWeek = ((int) d.getStandardDays() + 1) / 7; }