Java Code Examples for ucar.nc2.time.CalendarDateFormatter#isoStringToCalendarDate()
The following examples show how to use
ucar.nc2.time.CalendarDateFormatter#isoStringToCalendarDate() .
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: RecordDatasetHelper.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); } }
Example 2
Source File: NestedTable.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
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); } }
Example 3
Source File: DecoderWrapper.java From sis with Apache License 2.0 | 6 votes |
/** * Returns the value of the attribute of the given name as a date, or {@code null} if none. * * @param name the name of the attribute to search, or {@code null}. * @return the attribute value, or {@code null} if none or unparsable or if the given name was null. */ @Override public Date dateValue(final String name) { if (name != null) { for (final Group group : groups) { final Attribute attribute = findAttribute(group, name); if (attribute != null && attribute.isString()) { String value = Utils.nonEmpty(attribute.getStringValue()); if (value != null) { final CalendarDate date; try { date = CalendarDateFormatter.isoStringToCalendarDate(Calendar.proleptic_gregorian, value); } catch (IllegalArgumentException e) { listeners.warning(e); continue; } return new Date(date.getMillis()); } } } } return null; }
Example 4
Source File: FeatureDatasetCapabilitiesWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static CalendarDateRange getTimeSpan(Document doc) { Element root = doc.getRootElement(); Element timeSpan = root.getChild("TimeSpan"); if (timeSpan == null) return null; String beginS = timeSpan.getChildText("begin"); String endS = timeSpan.getChildText("end"); // String resS = timeSpan.getChildText("resolution"); if ((beginS == null) || (endS == null)) return null; try { CalendarDate start = CalendarDateFormatter.isoStringToCalendarDate(null, beginS); CalendarDate end = CalendarDateFormatter.isoStringToCalendarDate(null, endS); if ((start == null) || (end == null)) { return null; } CalendarDateRange dr = CalendarDateRange.of(start, end); // LOOK if (resS != null) // dr.setResolution(new TimeDuration(resS)); return dr; } catch (Exception e) { return null; } }
Example 5
Source File: FeatureDatasetCapabilitiesWriter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static CalendarDateRange getTimeSpan(Document doc) { Element root = doc.getRootElement(); Element timeSpan = root.getChild("TimeSpan"); if (timeSpan == null) return null; String beginS = timeSpan.getChildText("begin"); String endS = timeSpan.getChildText("end"); // String resS = timeSpan.getChildText("resolution"); if ((beginS == null) || (endS == null)) return null; try { CalendarDate start = CalendarDateFormatter.isoStringToCalendarDate(null, beginS); CalendarDate end = CalendarDateFormatter.isoStringToCalendarDate(null, endS); if ((start == null) || (end == null)) { return null; } CalendarDateRange dr = CalendarDateRange.of(start, end); // LOOK if (resS != null) // dr.setResolution(new TimeDuration(resS)); return dr; } catch (Exception e) { return null; } }
Example 6
Source File: NcssParamsBean.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
public CalendarDate getRequestedDate(Calendar cal) { if (date == null) return null; if (cal.equals(Calendar.getDefault())) return date; // otherwise must reparse return CalendarDateFormatter.isoStringToCalendarDate(cal, getTime()); }
Example 7
Source File: NcssGridParamsBean.java From tds with BSD 3-Clause "New" or "Revised" License | 5 votes |
public CalendarDate getRuntimeDate(Calendar cal) { if (runtimeDate == null) return null; if (cal.equals(Calendar.getDefault())) return runtimeDate; // otherwise must reparse if (getTime().equalsIgnoreCase("present")) { return CalendarDate.present(cal); } return CalendarDateFormatter.isoStringToCalendarDate(cal, getRuntime()); }
Example 8
Source File: CoordinateAxisTimeHelper.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
public CalendarDate makeCalendarDateFromOffset(String offset) { return CalendarDateFormatter.isoStringToCalendarDate(calendar, offset); }
Example 9
Source File: TimeParamsValidator.java From tds with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static CalendarDate isoString2Date(String isoString) { if ("present".equalsIgnoreCase(isoString)) return CalendarDate.present(); return CalendarDateFormatter.isoStringToCalendarDate(Calendar.getDefault(), isoString); }