Ejemplo n.º 1
0
 public void test_westernHemisphereTime() throws Exception {
   Long yesterday =
       DateTimeOperations.convert(
           (new DateTime(2009, 7, 23, 13, 18, 20, 0, DateTimeZone.forID("UTC"))));
   Assert.assertEquals(
       DateTimeOperations.print(
           yesterday, DateTimeFormat.shortTime(), null, DateTimeZone.forID("America/New_York")),
       DateTimeOperations.print(
           (DateTimeArithmetics.minus(yesterday, Period.hours(11))),
           DateTimeFormat.shortTime(),
           null,
           DateTimeZone.forID("Asia/Bangkok")));
 }
Ejemplo n.º 2
0
 public void test_londonAndMoscowShortTime() throws Exception {
   Long current = System.currentTimeMillis();
   Assert.assertEquals(
       DateTimeOperations.print(
           current,
           DateTimeFormat.shortTime(),
           new Locale("ru", "RU", ""),
           DateTimeZone.forID("Europe/London")),
       DateTimeOperations.print(
           (DateTimeArithmetics.minus(current, Period.hours(3))),
           DateTimeFormat.shortTime(),
           new Locale("ru", "RU", ""),
           DateTimeZone.forID("Europe/Moscow")));
 }
Ejemplo n.º 3
0
 public void test_westernHemisphereDate() throws Exception {
   Long yesterday =
       DateTimeOperations.convert(
           (new DateTime(2009, 7, 23, 13, 18, 20, 0, DateTimeZone.forID("UTC"))));
   Assert.assertFalse(
       (DateTimeOperations.print(
               yesterday,
               DateTimeFormat.fullDate(),
               Locale.US,
               DateTimeZone.forID("America/New_York")))
           .equals(
               DateTimeOperations.print(
                   (DateTimeArithmetics.plus(yesterday, Period.hours(22))),
                   DateTimeFormat.fullDate(),
                   Locale.US,
                   DateTimeZone.forID("Asia/Bangkok"))));
 }
Ejemplo n.º 4
0
  void drawTimeLine() {

    // draw the base timeline

    int minorTickHeight = (int) (20 * scaleFactorY);
    int majorTickHeight = (int) (40 * scaleFactorY);
    parent.strokeWeight(10);
    parent.stroke(0);
    parent.line(lineStart, lineY, lineStop, lineY);
    // draw days
    // int maxDays = Days.daysBetween(timelineStartDate,
    // timelineEndDate).getDays();
    int maxHours = Hours.hoursBetween(timelineStartDate, timelineEndDate).getHours();
    // println("Interval  is " + fullTimeInterval);
    // println("Period is " + Days.daysBetween(minDate, maxDate).getDays());
    // println("Max days is " + maxDays);

    DateTime tempdt = new DateTime(timelineStartDate);
    String previousMonth = timelineStartDate.monthOfYear().getAsText();
    int previousDay = -1; // =tempdt.dayOfYear().get();
    int monthStart = lineStart;
    parent.textAlign(PConstants.CENTER, PConstants.TOP);

    for (int a = 0; a < maxHours; a++) {
      // println(a);
      parent.textAlign(PConstants.CENTER, PConstants.TOP);
      // draw label
      parent.textFont(parent.font);
      parent.textSize(10 * fontScale);

      if (tempdt.dayOfYear().get() != previousDay) {
        int tx = (int) (PApplet.map(a, 0, maxHours, lineStart, lineStop));
        // draw tick
        parent.strokeWeight(1);
        parent.line(tx, lineY, tx, lineY + minorTickHeight);
        previousDay = tempdt.dayOfYear().get();
        parent.fill(0);
        if (tempdt.dayOfMonth().get() == 1) {
          // special case!
          parent.textSize(14 * fontScale);
          parent.text(
              tempdt.dayOfMonth().getAsString(),
              tx,
              lineY + majorTickHeight + parent.textDescent());
        } else {
          parent.text(
              tempdt.dayOfMonth().getAsString(),
              tx,
              lineY + minorTickHeight + parent.textDescent());
        }

        // check if need to draw monthName
        if (!previousMonth.equals(tempdt.monthOfYear().getAsText())) {
          // draw some visual markers!
          // line(monthStart, lineY, monthStart,
          // lineY+majorTickHeight);
          parent.line(tx, lineY, tx, lineY + majorTickHeight);
          // position halfway between monthStart and tx, draw
          // monthname
          parent.textSize(18 * fontScale);
          // check! do we overlap the next month? if so, change
          // alignment
          if (parent.textWidth(previousMonth) / 2 + monthStart > tx) {
            parent.textAlign(PConstants.RIGHT, PConstants.TOP);
          }
          parent.text(
              previousMonth,
              (tx + monthStart) / 2,
              lineY + minorTickHeight + 2 * (parent.textAscent() + parent.textDescent()));
          previousMonth = tempdt.monthOfYear().getAsText();
          monthStart = tx;
        }
      }
      tempdt = tempdt.plus(Period.hours(1));
    }
    // draw final day
    parent.line(lineStop, lineY, lineStop, lineY + minorTickHeight);
    if (tempdt.dayOfMonth().get() == 1) {
      // special case!
      parent.text(
          tempdt.dayOfMonth().getAsString(),
          lineStop,
          lineY + majorTickHeight + parent.textDescent());
    } else {
      parent.text(
          tempdt.dayOfMonth().getAsString(),
          lineStop,
          lineY + minorTickHeight + parent.textDescent());
    }
    // draw final month!
    parent.textSize(18 * fontScale);
    parent.text(
        tempdt.monthOfYear().getAsText(),
        (lineStop + monthStart) / 2,
        lineY + minorTickHeight + 2 * (parent.textAscent() + parent.textDescent()));
  }
@JsonAutoDetect
@AutoValue
public abstract class SearchesClusterConfig {
  private static final Period DEFAULT_QUERY_TIME_RANGE_LIMIT = Period.ZERO;
  private static final Map<Period, String> DEFAULT_RELATIVE_TIMERANGE_OPTIONS =
      ImmutableMap.<Period, String>builder()
          .put(Period.minutes(5), "Search in the last 5 minutes")
          .put(Period.minutes(15), "Search in the last 15 minutes")
          .put(Period.minutes(30), "Search in the last 30 minutes")
          .put(Period.hours(1), "Search in the last 1 hour")
          .put(Period.hours(2), "Search in the last 2 hours")
          .put(Period.hours(8), "Search in the last 8 hours")
          .put(Period.days(1), "Search in the last 1 day")
          .put(Period.days(2), "Search in the last 2 days")
          .put(Period.days(5), "Search in the last 5 days")
          .put(Period.days(7), "Search in the last 7 days")
          .put(Period.days(14), "Search in the last 14 days")
          .put(Period.days(30), "Search in the last 30 days")
          .put(Period.ZERO, "Search in all messages")
          .build();
  private static final Map<Period, String> DEFAULT_SURROUNDING_TIMERANGE_OPTIONS =
      ImmutableMap.<Period, String>builder()
          .put(Period.seconds(1), "1 second")
          .put(Period.seconds(5), "5 seconds")
          .put(Period.seconds(10), "10 seconds")
          .put(Period.seconds(30), "30 seconds")
          .put(Period.minutes(1), "1 minute")
          .put(Period.minutes(5), "5 minutes")
          .build();
  private static final Set<String> DEFAULT_SURROUNDING_FILTER_FIELDS =
      ImmutableSet.<String>builder()
          .add("source")
          .add("gl2_source_input")
          .add("file")
          .add("source_file")
          .build();

  @JsonProperty("query_time_range_limit")
  public abstract Period queryTimeRangeLimit();

  @JsonProperty("relative_timerange_options")
  public abstract Map<Period, String> relativeTimerangeOptions();

  @JsonProperty("surrounding_timerange_options")
  public abstract Map<Period, String> surroundingTimerangeOptions();

  @JsonProperty("surrounding_filter_fields")
  public abstract Set<String> surroundingFilterFields();

  @JsonCreator
  public static SearchesClusterConfig create(
      @JsonProperty("query_time_range_limit") Period queryTimeRangeLimit,
      @JsonProperty("relative_timerange_options") Map<Period, String> relativeTimerangeOptions,
      @JsonProperty("surrounding_timerange_options")
          Map<Period, String> surroundingTimerangeOptions,
      @JsonProperty("surrounding_filter_fields") Set<String> surroundingFilterFields) {
    return builder()
        .queryTimeRangeLimit(queryTimeRangeLimit)
        .relativeTimerangeOptions(relativeTimerangeOptions)
        .surroundingTimerangeOptions(surroundingTimerangeOptions)
        .surroundingFilterFields(surroundingFilterFields)
        .build();
  }

  public static SearchesClusterConfig createDefault() {
    return builder()
        .queryTimeRangeLimit(DEFAULT_QUERY_TIME_RANGE_LIMIT)
        .relativeTimerangeOptions(DEFAULT_RELATIVE_TIMERANGE_OPTIONS)
        .surroundingTimerangeOptions(DEFAULT_SURROUNDING_TIMERANGE_OPTIONS)
        .surroundingFilterFields(DEFAULT_SURROUNDING_FILTER_FIELDS)
        .build();
  }

  public static Builder builder() {
    return new AutoValue_SearchesClusterConfig.Builder();
  }

  public abstract Builder toBuilder();

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder queryTimeRangeLimit(Period queryTimeRangeLimit);

    public abstract Builder relativeTimerangeOptions(Map<Period, String> relativeTimerangeOptions);

    public abstract Builder surroundingTimerangeOptions(
        Map<Period, String> surroundingTimerangeOptions);

    public abstract Builder surroundingFilterFields(Set<String> surroundingFilterFields);

    public abstract SearchesClusterConfig build();
  }
}
Ejemplo n.º 6
0
 @Override
 public Period byAmount(int amount) {
   return Period.hours(amount);
 }