Java Code Examples for ucar.nc2.time.CalendarDate#add()

The following examples show how to use ucar.nc2.time.CalendarDate#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePartition.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Iterable<MCollection> makePartitions(CollectionUpdateType forceCollection) throws IOException {

    List<MCollection> result = new ArrayList<>();
    CollectionListRange curr = null;
    CalendarDate startDate;
    CalendarDate endDate = null;

    for (MFile mfile : getFilesSorted()) {
      CalendarDate cdate = dateExtractor.getCalendarDate(mfile);
      if (cdate == null)
        continue; // skip - error should be logged
      if ((curr == null) || !endDate.isAfter(cdate)) {
        startDate = cdate.truncate(timePeriod.getField()); // start on a boundary
        endDate = startDate.add(timePeriod);
        String name = collectionName + "-" + cdf.toString(startDate);
        curr = new CollectionListRange(name, root, startDate, endDate, this.logger);
        curr.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, this.config);
        if (!wasRemoved(curr))
          result.add(curr); // skip if in removed list
      }
      curr.addFile(mfile);
    }

    return result;
  }
 
Example 2
Source File: DefaultDateRangeTest.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SpringJUnit4ParameterizedClassRunner.Parameters
public static List<Object[]> getTestParameters() {

  CalendarDate now = CalendarDate.present();
  CalendarDate dayAfter = now.add(CalendarPeriod.of(1, CalendarPeriod.Field.Day));
  CalendarDate dayBefore = now.add(CalendarPeriod.of(-1, CalendarPeriod.Field.Day));

  String nowStr = CalendarDateFormatter.toDateTimeStringISO(now);
  String dayAfterStr = CalendarDateFormatter.toDateTimeStringISO(dayAfter);
  String dayBeforeStr = CalendarDateFormatter.toDateTimeStringISO(dayBefore);

  return Arrays
      .asList(new Object[][] {{0L, null, "present", "present", null}, {86400L, null, "present", dayAfterStr, null},
          {86400L, null, dayBeforeStr, "present", null}, {86400L * 2, null, dayBeforeStr, dayAfterStr, null},
          {86400L * 3, null, nowStr, null, "P3D"}, {86400L * 2, null, null, dayBeforeStr, "P2D"}});
}
 
Example 3
Source File: GribCoordsMatchGbx.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private CalendarDate[] makeDateBounds(SubsetParams coords, CalendarDate runtime) {
  double[] time_bounds = coords.getTimeOffsetIntv();
  CalendarDateUnit dateUnit = (CalendarDateUnit) coords.get(SubsetParams.timeOffsetUnit);
  CalendarDate[] result = new CalendarDate[2];
  result[0] = runtime.add(CalendarPeriod.of((int) time_bounds[0], dateUnit.getCalendarField()));
  result[1] = runtime.add(CalendarPeriod.of((int) time_bounds[1], dateUnit.getCalendarField()));
  return result;
}
 
Example 4
Source File: VariableTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 */
DateRenderer() {

  oldForm = new CalendarDateFormatter("yyyy-MM-dd HH:mm:ss", CalendarTimeZone.UTC);
  newForm = new CalendarDateFormatter("dd MMM HH:mm:ss", CalendarTimeZone.UTC);

  CalendarDate now = CalendarDate.present();
  cutoff = now.add(-1, CalendarPeriod.Field.Year); // "now" time format within a year
}
 
Example 5
Source File: StructureTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
DateRenderer() {

      oldForm = new CalendarDateFormatter("yyyy MMM dd HH:mm", CalendarTimeZone.UTC);
      newForm = new CalendarDateFormatter("MMM dd, HH:mm", CalendarTimeZone.UTC);

      CalendarDate now = CalendarDate.present();
      cutoff = now.add(-1, CalendarPeriod.Field.Year); // "now" time format within a year
    }
 
Example 6
Source File: NwsMetDevTables.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@Nullable
public TimeCoordIntvDateValue getForecastTimeInterval(Grib2Record gr) {
  Grib2Pds pds = gr.getPDS();
  if (!pds.isTimeInterval())
    return null;
  Grib2Pds.PdsInterval pdsIntv = (Grib2Pds.PdsInterval) gr.getPDS();

  // override here only if timeRangeUnit = 255
  boolean needOverride = false;
  for (Grib2Pds.TimeInterval ti : pdsIntv.getTimeIntervals()) {
    needOverride = (ti.timeRangeUnit == 255);
  }
  if (!needOverride)
    return super.getForecastTimeInterval(gr);

  CalendarDate intvEnd = pdsIntv.getIntervalTimeEnd();
  int ftime = pdsIntv.getForecastTime();
  int timeUnitOrg = pds.getTimeUnit();
  int timeUnitConvert = convertTimeUnit(timeUnitOrg);
  CalendarPeriod unitPeriod = Grib2Utils.getCalendarPeriod(timeUnitConvert);
  if (unitPeriod == null)
    throw new IllegalArgumentException("unknown CalendarPeriod " + timeUnitConvert + " org=" + timeUnitOrg);

  CalendarPeriod.Field fld = unitPeriod.getField();

  CalendarDate referenceDate = gr.getReferenceDate();
  CalendarDate intvStart = referenceDate.add(ftime, fld);

  return new TimeCoordIntvDateValue(intvStart, intvEnd);
}
 
Example 7
Source File: TimeCoordIntvValue.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public TimeCoordIntvValue convertReferenceDate(CalendarDate fromDate, CalendarPeriod fromUnit, CalendarDate toDate,
    CalendarPeriod toUnit) {
  CalendarDate start = fromDate.add(fromUnit.multiply(b1));
  CalendarDate end = fromDate.add(fromUnit.multiply(b2));
  int startOffset = toUnit.getOffset(toDate, start);
  int endOffset = toUnit.getOffset(toDate, end);
  return new TimeCoordIntvValue(startOffset, endOffset);
}
 
Example 8
Source File: DateType.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateType add(TimeUnit d) {
  CalendarDate useDate = getCalendarDate();
  CalendarDate result = useDate.add((int) d.getValueInSeconds(), CalendarPeriod.Field.Second);
  return new DateType(result);
}
 
Example 9
Source File: DateType.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DateType subtract(TimeUnit d) {
  CalendarDate useDate = getCalendarDate();
  CalendarDate result = useDate.add((int) -d.getValueInSeconds(), CalendarPeriod.Field.Second);
  return new DateType(result);
}
 
Example 10
Source File: GribUtils.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static CalendarDate getValidTime(CalendarDate refDate, int timeUnit, int offset) {
  CalendarPeriod period = GribUtils.getCalendarPeriod(timeUnit);
  return refDate.add(period.multiply(offset));
}
 
Example 11
Source File: TimeCoordIntvDateValue.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public TimeCoordIntvDateValue(CalendarDate start, CalendarPeriod period) {
  this.start = start;
  this.end = start.add(period);
}
 
Example 12
Source File: FmrcInv.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a date from base and hour offset
 * 
 * @param base base date
 * @param offset hourss
 * @return base + offset as a Date
 */
public static CalendarDate makeOffsetDate(CalendarDate base, double offset) {
  return base.add(offset, CalendarPeriod.Field.Hour);
}