Exemplo n.º 1
0
  protected void assemble(Fields fields) {
    if (getParam() == null) {
      // julian chrono removed zero, but we need to put it back
      DateTimeField field = fields.year;
      fields.year =
          new OffsetDateTimeField(new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);

      // one era, so yearOfEra is the same
      field = fields.yearOfEra;
      fields.yearOfEra = new DelegatedDateTimeField(fields.year, DateTimeFieldType.yearOfEra());

      // julian chrono removed zero, but we need to put it back
      field = fields.weekyear;
      fields.weekyear =
          new OffsetDateTimeField(new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);

      field = new OffsetDateTimeField(fields.yearOfEra, 99);
      fields.centuryOfEra = new DividedDateTimeField(field, DateTimeFieldType.centuryOfEra(), 100);

      field = new RemainderDateTimeField((DividedDateTimeField) fields.centuryOfEra);
      fields.yearOfCentury = new OffsetDateTimeField(field, DateTimeFieldType.yearOfCentury(), 1);

      field =
          new RemainderDateTimeField(fields.weekyear, DateTimeFieldType.weekyearOfCentury(), 100);
      fields.weekyearOfCentury =
          new OffsetDateTimeField(field, DateTimeFieldType.weekyearOfCentury(), 1);

      fields.era = ERA_FIELD;
    }
  }
Exemplo n.º 2
0
 public static Partial getPartialFromString(String date) {
   Integer month = Integer.valueOf(date.substring(0, 2));
   Integer year = Integer.valueOf(date.substring(2));
   return new Partial(
       new DateTimeFieldType[] {DateTimeFieldType.year(), DateTimeFieldType.monthOfYear()},
       new int[] {year.intValue(), month.intValue()});
 }
Exemplo n.º 3
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();
 }
 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;
 }
Exemplo n.º 5
0
 // Get a beginning-of-week time for consistent tariff evaluation
 private Instant getNextSunday() {
   Instant result = getNowInstant();
   int hour = result.get(DateTimeFieldType.hourOfDay());
   if (hour > 0) result = result.plus((24 - hour) * TimeService.HOUR);
   int day = result.get(DateTimeFieldType.dayOfWeek());
   result = result.plus((7 - day) * TimeService.DAY);
   return result;
 }
Exemplo n.º 6
0
 public void test_zeroDateIsNotNever() throws Exception {
   Long at1January1970 = DateTimeOperations.convert(Period.seconds(0));
   Assert.assertFalse(
       DateTimeOperations.compare(
               at1January1970, CompareType.EQ, null, DateTimeFieldType.millisOfSecond())
           || DateTimeOperations.compare(
               at1January1970,
               CompareType.EQ,
               DateTimeOperations.never(),
               DateTimeFieldType.millisOfSecond()));
 }
 public int getMaximumValue(ReadablePartial partial) {
   if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
     int month = partial.get(DateTimeFieldType.monthOfYear());
     if (partial.isSupported(DateTimeFieldType.year())) {
       int year = partial.get(DateTimeFieldType.year());
       return iChronology.getDaysInYearMonth(year, month);
     }
     return iChronology.getDaysInMonthMax(month);
   }
   return getMaximumValue();
 }
 public FlightSchedule(
     DateTime validFromInclusive,
     DateTime validUntilExclusive,
     int flightHourOfDay,
     int flightMinuteOfHour) {
   this.validFromInclusive = validFromInclusive;
   this.validUntilInclusive = validUntilExclusive;
   flightTimeOfDay =
       new Partial()
           .with(DateTimeFieldType.hourOfDay(), 12)
           .with(DateTimeFieldType.minuteOfHour(), 30);
 }
 private Date convertPartialToDate(AbstractPartial partial) {
   if (partial == null) {
     return null;
   }
   Calendar calendar = Calendar.getInstance();
   calendar.clear();
   if (isHour()) {
     calendar.set(Calendar.HOUR_OF_DAY, partial.get(DateTimeFieldType.hourOfDay()));
   }
   if (isMinute()) {
     calendar.set(Calendar.MINUTE, partial.get(DateTimeFieldType.minuteOfHour()));
   }
   return calendar.getTime();
 }
Exemplo n.º 10
0
  protected void assemble(Fields fields) {
    if (getBase().getZone() == DateTimeZone.UTC) {
      // Use zero based century and year of century.
      fields.centuryOfEra =
          new DividedDateTimeField(
              ISOYearOfEraDateTimeField.INSTANCE, DateTimeFieldType.centuryOfEra(), 100);
      fields.yearOfCentury =
          new RemainderDateTimeField(
              (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.yearOfCentury());
      fields.weekyearOfCentury =
          new RemainderDateTimeField(
              (DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.weekyearOfCentury());

      fields.centuries = fields.centuryOfEra.getDurationField();
    }
  }
 // -----------------------------------------------------------------------
 public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
   // overridden as superclass algorithm can't handle
   // 2004-02-29 + 48 months -> 2008-02-29 type dates
   if (valueToAdd == 0) {
     return values;
   }
   if (partial.size() > 0
       && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear())
       && fieldIndex == 0) {
     // month is largest field and being added to, such as month-day
     int curMonth0 = partial.getValue(0) - 1;
     int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
     return set(partial, 0, values, newMonth);
   }
   if (DateTimeUtils.isContiguous(partial)) {
     long instant = 0L;
     for (int i = 0, isize = partial.size(); i < isize; i++) {
       instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
     }
     instant = add(instant, valueToAdd);
     return iChronology.get(partial, instant);
   } else {
     return super.add(partial, fieldIndex, values, valueToAdd);
   }
 }
Exemplo n.º 12
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);
  }
 public int getMaximumValue(ReadablePartial partial, int[] values) {
   int size = partial.size();
   for (int i = 0; i < size; i++) {
     if (partial.getFieldType(i) == DateTimeFieldType.monthOfYear()) {
       int month = values[i];
       for (int j = 0; j < size; j++) {
         if (partial.getFieldType(j) == DateTimeFieldType.year()) {
           int year = values[j];
           return iChronology.getDaysInYearMonth(year, month);
         }
       }
       return iChronology.getDaysInMonthMax(month);
     }
   }
   return getMaximumValue();
 }
Exemplo n.º 14
0
 public Interval getInterval() {
   final DateTime beginningOfSemester = new DateTime(getAttends().getBegginingOfLessonPeriod());
   final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
   final DateTime start =
       firstMonday.withFieldAdded(DurationFieldType.weeks(), getWeekOffset().intValue());
   final DateTime end = start.plusWeeks(1);
   return new Interval(start, end);
 }
Exemplo n.º 15
0
  /** @param daysInYear The number of days in each year */
  protected FixedYearLengthChronology(int daysInYear) {
    this.daysInYear = daysInYear;

    this.yearDuration =
        new PreciseDurationField(
            DurationFieldType.years(), daysInYear * dayDuration.getUnitMillis());
    this.centuryDuration =
        new PreciseDurationField(DurationFieldType.centuries(), 100 * yearDuration.getUnitMillis());

    this.dayOfYear =
        new OneBasedPreciseDateTimeField(
            DateTimeFieldType.dayOfYear(), dayDuration, this.yearDuration);
    this.yearOfCentury =
        new PreciseDateTimeField(
            DateTimeFieldType.yearOfCentury(), this.yearDuration, this.centuryDuration);
    this.year = new YearField(this.yearDuration);
  }
Exemplo n.º 16
0
 public void test_nullIsNever() throws Exception {
   Long nullDate = null;
   Assert.assertTrue(
       DateTimeOperations.compare(
           nullDate,
           CompareType.EQ,
           DateTimeOperations.never(),
           DateTimeFieldType.millisOfSecond()));
 }
Exemplo n.º 17
0
 public void test_nowIsNotNever() throws Exception {
   Long nowDate = System.currentTimeMillis();
   Assert.assertTrue(
       DateTimeOperations.compare(
           nowDate,
           CompareType.NE,
           DateTimeOperations.never(),
           DateTimeFieldType.millisOfSecond()));
 }
    private Object convertCalendarToPartial(Class type, Calendar calendar) throws Exception {
      if (type.equals(Partial.class)) {
        Partial partial = new Partial();
        if (isHour()) {
          partial = partial.with(DateTimeFieldType.hourOfDay(), calendar.get(Calendar.HOUR_OF_DAY));
        }
        if (isMinute()) {
          partial = partial.with(DateTimeFieldType.minuteOfHour(), calendar.get(Calendar.MINUTE));
        }
        return partial;
      } else {
        // ASSUMPTION
        // assume that we want a subtype of BasePartial and that the
        // subtype implements the factory
        // method fromCalendarField(Calendar calendar)
        Method method = type.getMethod("fromCalendarFields", new Class[] {Calendar.class});

        return method.invoke(null, new Object[] {calendar});
      }
    }
Exemplo n.º 19
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;
  }
Exemplo n.º 20
0
  public void apply(Document doc, List<Object> values, Span span, DateTime ref) {
    Map params = getParameters();
    String value = (String) params.get("value");
    String diff = (String) params.get("diff");
    String dir = (String) params.get("dir");
    DateTime val = ref;
    if (value != null) {
      value = assignValues(value, values);
      val = new DateTime(value);
    } else if (diff != null) {
      diff = assignValues(diff, values);
      Period period = new Period(diff);

      if (dir == null || dir.equals("plus")) {
        val = ref.plus(period);
      } else if (dir.equals("minus")) {
        val = ref.minus(period);
      }
    } else {
      val = ref;
      // use set_xxx
      for (Map.Entry entry : (Set<Map.Entry>) params.entrySet()) {
        Matcher m = Pattern.compile("set_(.*)").matcher((String) entry.getKey());
        if (m.matches()) {
          String field = assignValues((String) entry.getValue(), values);
          String fieldName = m.group(1);

          if (fieldName.equals("month")) {
            int month = Integer.parseInt(field);
            val = getTimeAnnotator().normalizeMonth(val, month);
          } else if (fieldName.equals("day")) {
            int day = Integer.parseInt(field);
            val = val.withField(DateTimeFieldType.dayOfMonth(), day);
          } else {
            throw new InternalError();
          }
        }
      }
    }

    String formattedDate = formatter.print(val);
    FeatureSet attrs = new FeatureSet();
    attrs.put("VAL", formattedDate);

    doc.annotate("TIMEX2", span, attrs);
  }
Exemplo n.º 21
0
 /**
  * Get the century of era field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField centuryOfEra() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.centuryOfEra(), centuries());
 }
Exemplo n.º 22
0
 /**
  * Get the year of century field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField yearOfCentury() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.yearOfCentury(), years());
 }
Exemplo n.º 23
0
 /**
  * Get the month of year field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField monthOfYear() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.monthOfYear(), months());
 }
Exemplo n.º 24
0
 /**
  * Get the year of a week based year field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField weekyear() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.weekyear(), weekyears());
 }
Exemplo n.º 25
0
 /**
  * Get the day of year field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField dayOfYear() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.dayOfYear(), days());
 }
Exemplo n.º 26
0
 /**
  * Get the AM(0) PM(1) field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField halfdayOfDay() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.halfdayOfDay(), halfdays());
 }
Exemplo n.º 27
0
 /**
  * Get the hour of am/pm (offset to 1-12) field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField clockhourOfHalfday() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.clockhourOfHalfday(), hours());
 }
Exemplo n.º 28
0
 /**
  * Get the era field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField era() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.era(), eras());
 }
 /** Restricted constructor */
 GJEraDateTimeField(BasicChronology chronology) {
   super(DateTimeFieldType.era());
   iChronology = chronology;
 }
Exemplo n.º 30
0
 /**
  * Get the hour of day (0-23) field for this chronology.
  *
  * @return DateTimeField or UnsupportedDateTimeField if unsupported
  */
 public DateTimeField hourOfDay() {
   return UnsupportedDateTimeField.getInstance(DateTimeFieldType.hourOfDay(), hours());
 }