public Time2D(CalendarDate refDate, Integer time, TimeCoord.Tinv tinv) { this.refDate = refDate.getMillis(); this.time = time; this.tinv = tinv; }
@Override public int getIndex(Object val) { long want; if (val instanceof CalendarDate) want = ((CalendarDate) val).getMillis(); else if (val instanceof Number) want = ((Number)val).longValue(); else throw new IllegalArgumentException(val.getClass().getName()); return Arrays.binarySearch(runtimes, want); }
@Override public Object extract(Grib2Record gr) { return gr.getReferenceDate().getMillis(); }
/** * Parses the given ISO date, assuming proleptic Gregorian calendar and UTC time zone. * * @param value the date in ISO format. * @return the parsed date. * @throws IllegalArgumentException if the given date can not be parsed. */ private static Date parseDate(final String value) throws IllegalArgumentException { return new Date(CalendarDateFormatter.isoStringToCalendarDate(Calendar.proleptic_gregorian, value).getMillis()); }
@Override public Object extract(Grib1Record gr) { return gr.getReferenceDate().getMillis(); }
/** * Get offsets from firstDate, in units of timeUnit * @return for each runtime, a list of values from firstdate */ public List<Double> getOffsetsInTimeUnits() { double start = firstDate.getMillis(); List<Double> result = new ArrayList<>(runtimes.length); for (int idx=0; idx<runtimes.length; idx++) { double runtime = (double) getRuntime(idx); double msecs = (runtime - start); result.add(msecs / timeUnit.getValueInMillisecs()); } return result; }
public CalendarDateFactory(CoordinateRuntime master) { map = new HashMap<>(master.getSize() * 2); for (Object valo : master.getValues()) { CalendarDate cd = CalendarDate.of((Long) valo); map.put(cd.getMillis(), cd); } }
private double getTime(CoordVarExtractor cve, StructureData[] tableData) { if (cve == null) return Double.NaN; if (tableData[cve.nestingLevel] == null) return Double.NaN; if (cve.isString()) { String timeString = timeVE.getCoordValueString(tableData); CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, timeString); if (date == null) { log.error("Cant parse date - not ISO formatted, = "+timeString); return 0.0; } return date.getMillis(); } else { return cve.getCoordValue(tableData); } }
private double getTime(CoordVarExtractor cve, StructureData[] tableData) { if (cve == null) return Double.NaN; if (tableData[cve.nestingLevel] == null) return Double.NaN; if (cve.isString()) { String timeString = timeVE.getCoordValueString(tableData); CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, timeString); if (date == null) { log.error("Cant parse date - not ISO formatted, = " + timeString); return 0.0; } return date.getMillis(); } else { return cve.getCoordValue(tableData); } }
private double getTime(CoordVarExtractor cve, StructureData[] tableData) { if (cve == null) return Double.NaN; if (tableData[cve.nestingLevel] == null) return Double.NaN; if (cve.isString()) { String timeString = timeVE.getCoordValueString(tableData); CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, timeString); if (date == null) { log.error("Cant parse date - not ISO formatted, = "+timeString); return 0.0; } return date.getMillis(); } else { return cve.getCoordValue(tableData); } }
private double getTime(StructureMembers.Member timeVar, StructureData sdata) { if (timeVar == null) return 0.0; if ((timeVar.getDataType() == DataType.CHAR) || (timeVar.getDataType() == DataType.STRING)) { String time = sdata.getScalarString(timeVar); CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, time); if (date == null) { log.error("Cant parse date - not ISO formatted, = " + time); return 0.0; } return date.getMillis() / 1000.0; } else { return sdata.convertScalarDouble(timeVar); } }
private double getTime(StructureMembers.Member timeVar, StructureData sdata) { if (timeVar == null) return 0.0; if ((timeVar.getDataType() == DataType.CHAR) || (timeVar.getDataType() == DataType.STRING)) { String time = sdata.getScalarString(timeVar); CalendarDate date = CalendarDateFormatter.isoStringToCalendarDate(null, time); if (date == null) { log.error("Cant parse date - not ISO formatted, = "+time); return 0.0; } return date.getMillis() / 1000.0; } else { return sdata.convertScalarDouble(timeVar); } }
@Override protected PointFeature makeFeature(int recnum, StructureData sdata) throws IOException { extract.extract(sdata); String stationId = extract.getStationId(); //System.out.printf(" '%s' '%s' (%d) %n", s.getName(), stationId, countRecords++); //if (count > 10) return null; if (!stationId.equals(s.getName())) return null; CalendarDate date = extract.makeCalendarDate(); return new BufrStationPoint(s, date.getMillis(), 0, munger.munge(sdata)); // LOOK obsTime, nomTime } }
CdmrFeatureProto.CalendarDateRange.Builder encodeDateRange(CalendarDateRange dateRange) { CdmrFeatureProto.CalendarDateRange.Builder builder = CdmrFeatureProto.CalendarDateRange.newBuilder(); builder.setStart(dateRange.getStart().getMillis()); builder.setEnd(dateRange.getEnd().getMillis()); Calendar cal = dateRange.getStart().getCalendar(); builder.setCalendar(convertCalendar(cal)); return builder; }
@Override protected PointFeature makeFeature(int recnum, StructureData sdata) throws IOException { extract.extract(sdata); String stationId = extract.getStationId(); StationFeature want = stationsWanted.getStation(stationId); if (want == null) return null; CalendarDate date = extract.makeCalendarDate(); countHere++; return new BufrPoint(want, date.getMillis(), 0, munger.munge(sdata)); }
private GribCollectionProto.Partition writePartitionProto(PartitionCollectionMutable pc, PartitionCollectionMutable.Partition p) throws IOException { GribCollectionProto.Partition.Builder b = GribCollectionProto.Partition.newBuilder(); String pathRS = makeReletiveFilename(pc, p); // reletive to pc.directory b.setFilename(pathRS); b.setName(p.name); // b.setDirectory(p.directory); b.setLastModified(p.lastModified); b.setLength(p.fileSize); if (p.partitionDate != null) b.setPartitionDate(p.partitionDate.getMillis()); // LOOK what about calendar ?? return b.build(); }
@Test public void testBase() throws Exception { Date base = getBase(datestring); CalendarDateUnit cdu = CalendarDateUnit.of(calendar, datestring); Assert.assertEquals("Difference (ms): " + (base.getTime() - cdu.getBaseDate().getTime()), cdu.getBaseDate(), base); Assert.assertEquals("Difference (ms): " + (CalendarDate.of(base).getMillis() - cdu.getBaseCalendarDate().getMillis()), cdu.getBaseCalendarDate(), CalendarDate.of(base)); }
protected GribCollectionProto.Coord writeCoordProto(CoordinateTime coord) throws IOException { GribCollectionProto.Coord.Builder b = GribCollectionProto.Coord.newBuilder(); b.setAxisType(convertAxisType(coord.getType())); b.setCode(coord.getCode()); b.setUnit(coord.getTimeUnit().toString()); b.addMsecs(coord.getRefDate().getMillis()); for (Integer offset : coord.getOffsetSorted()) b.addValues(offset); int[] time2runtime = coord.getTime2runtime(); if (time2runtime != null) for (int val : time2runtime) b.addTime2Runtime(val); return b.build(); }