Ejemplo n.º 1
0
 public static long getTimeInterval(EnumQuotaPeriod period, DateTimeZone timezone) {
   DateTime ct = getCurrentWindow(period, timezone);
   DateTime tt = null;
   int y = ct.get(DateTimeFieldType.year());
   int m = ct.get(DateTimeFieldType.monthOfYear());
   int d = ct.get(DateTimeFieldType.dayOfMonth());
   int h = ct.get(DateTimeFieldType.hourOfDay());
   switch (period) {
     case Hourly:
       h++;
       tt = new DateTime(y, m, d, h, 0, timezone);
       break;
     case Daily:
       d++;
       tt = new DateTime(y, m, d, 0, 0, timezone);
       break;
     case Monthly:
       m++;
       tt = new DateTime(y, m, 0, 0, 0, timezone);
       break;
     case Yearly:
       y++;
       tt = new DateTime(y, m, 0, 0, 0, timezone);
       break;
   }
   Interval i = new Interval(ct, tt);
   return i.toDurationMillis();
 }
Ejemplo n.º 2
0
 private Calendar convertDateTimeToCalendar(DateTime dt) {
   Calendar calendar = Calendar.getInstance();
   calendar.clear();
   calendar.set(Calendar.HOUR_OF_DAY, dt.get(DateTimeFieldType.hourOfDay()));
   calendar.set(Calendar.MINUTE, dt.get(DateTimeFieldType.minuteOfHour()));
   calendar.set(Calendar.SECOND, dt.get(DateTimeFieldType.secondOfMinute()));
   return calendar;
 }
Ejemplo n.º 3
0
  public void init(Directory d) {
    this.directory = d;
    searcher = Searcher.create(directory);
    indexer = new LuceneIndexer();

    DateTime dt = new DateTime();
    int hours = dt.get(DateTimeFieldType.hourOfDay());

    EvaExecutors.getInstance()
        .getScheduler()
        .scheduleAtFixedRate(
            new Runnable() {
              @Override
              public void run() {
                vbotDAOHTMLImplementation.getInstance().flush();
                try {
                  SearchManager.getInstanse().updateIndex(true);
                } catch (IOException e) {
                  log.error(e, e);
                }
              }
            },
            24 - hours,
            24,
            TimeUnit.HOURS);
  }
Ejemplo n.º 4
0
  public static DateTime getCurrentWindow(
      EnumQuotaPeriod period, long timestamp, DateTimeZone timezone) {
    DateTime ct = new DateTime(timestamp);

    switch (period) {
      case Hourly:
        return new DateTime(
            ct.get(DateTimeFieldType.year()),
            ct.get(DateTimeFieldType.monthOfYear()),
            ct.get(DateTimeFieldType.dayOfMonth()),
            ct.get(DateTimeFieldType.hourOfDay()),
            0,
            timezone);
      case Daily:
        return new DateTime(
            ct.get(DateTimeFieldType.year()),
            ct.get(DateTimeFieldType.monthOfYear()),
            ct.get(DateTimeFieldType.dayOfMonth()),
            0,
            0,
            timezone);
      case Monthly:
        return new DateTime(
            ct.get(DateTimeFieldType.year()),
            ct.get(DateTimeFieldType.monthOfYear()),
            0,
            0,
            0,
            timezone);
      case Yearly:
        return new DateTime(ct.get(DateTimeFieldType.year()), 0, 0, 0, 0, timezone);

      default:
        break;
    }
    return null;
  }