Java Code Examples for ucar.nc2.time.Calendar#get()
The following examples show how to use
ucar.nc2.time.Calendar#get() .
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: CatalogBuilder.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected Calendar readCalendar(String calendarAttribValue) { if (calendarAttribValue == null) { return Calendar.getDefault(); } Calendar calendar = Calendar.get(calendarAttribValue); if (calendar == null) { errlog.format(" ** Parse error: Bad calendar name = '%s'%n", calendarAttribValue); logger.debug(" ** Parse error: Bad calendar name = '{}}'", calendarAttribValue); return Calendar.getDefault(); } return calendar; }
Example 2
Source File: TestAggExisting.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CalendarDateUnit getCalendarDateUnit(Variable timeVar) { Attribute calAttr = timeVar.findAttributeIgnoreCase(CF.CALENDAR); assertThat(calAttr).isNotNull(); Calendar cal = Calendar.get(calAttr.getStringValue()); return CalendarDateUnit.withCalendar(cal, timeVar.getUnitsString()); }
Example 3
Source File: TestAggExistingNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CalendarDateUnit getCalendarDateUnit(Variable timeVar) { Attribute calAttr = timeVar.attributes().findAttributeIgnoreCase("calendar"); assertThat(calAttr).isNotNull(); Calendar cal = Calendar.get(calAttr.getStringValue()); return CalendarDateUnit.withCalendar(cal, timeVar.getUnitsString()); }
Example 4
Source File: TestDefaultCalendars.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testCfDefaultCalendar() throws IOException { String failMessage, found, expected; boolean testCond; String tstFile = TestDir.cdmLocalTestDataDir + "dataset/cfMissingCalendarAttr.nc"; // open the test file NetcdfDataset ncd = NetcdfDataset.openDataset(tstFile); // make sure this dataset used the cfConvention expected = cfConvention; found = ncd.getConventionUsed(); testCond = found.equals(expected); failMessage = format("This dataset used the %s convention, but should have used the %s convention.", found, expected); Assert.assertTrue(failMessage, testCond); // get the Time Coordinate Axis and read the values CoordinateAxis tca = ncd.findCoordinateAxis(AxisType.Time); Array times = tca.read(); ncd.close(); // first date in this file is 90 [hours since 2015-12-18T06:00:00], // which is 2015-12-22 00:00:00\ expected = "90"; found = Integer.toString(times.getInt(0)); testCond = found.equals(expected); failMessage = format("The first value in the times array should be %s. I got %s instead.", expected, found); Assert.assertTrue(failMessage, testCond); // look for the calendar attached to the time variable...if there isn't one, // then a default was not set and the assert will fail. Calendar cal = Calendar.get(tca.findAttributeIgnoreCase(CF.CALENDAR).getStringValue()); expected = defaultCFCalendar.toString(); found = cal.toString(); testCond = found.equals(expected); failMessage = format("The calendar should equal %s, but got %s instead. Failed to set a default calendar.", expected, found); Assert.assertTrue(failMessage, testCond); // convert the time value to a CalendarDate CoordinateAxisTimeHelper coordAxisTimeHelper = new CoordinateAxisTimeHelper(cal, tca.findAttributeIgnoreCase("units").getStringValue()); CalendarDate date = coordAxisTimeHelper.makeCalendarDateFromOffset(times.getInt(0)); // create the correct date as requested from NCSS String correctIsoDateTimeString = "2015-12-22T00:00:00Z"; CalendarDate correctDate = CalendarDate.parseISOformat(defaultCFCalendar.toString(), correctIsoDateTimeString); // If everything is correct, then the date and correct date should be the same expected = correctDate.toString(); found = date.toString(); testCond = date.equals(correctDate); failMessage = format("The correct date is %s, but I got %s instead.", expected, found); Assert.assertTrue(failMessage, testCond); }
Example 5
Source File: TestDefaultCalendars.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void testCoardsDefaultCalendar() throws IOException { String failMessage, found, expected; boolean testCond; String tstFile = TestDir.cdmLocalTestDataDir + "dataset/coardsMissingCalendarAttr.nc"; // open the test file NetcdfDataset ncd = NetcdfDataset.openDataset(tstFile); // make sure this dataset used the coardsConvention found = ncd.getConventionUsed(); expected = coardsConvention; testCond = found.equals(expected); failMessage = format("This dataset used the %s convention, but should have used the %s convention.", found, expected); Assert.assertTrue(failMessage, testCond); // get the Time Coordinate Axis and read the values CoordinateAxis tca = ncd.findCoordinateAxis(AxisType.Time); Array times = tca.read(); ncd.close(); // first date in this file is 1.766292E7 [hours since 0001-01-01T00:00:00], // which is 2008-06-27 00:00:00 found = Integer.toString(times.getInt(0)); expected = "17662920"; testCond = found.equals(expected); failMessage = format("The first value in the times array should be %s. I got %s instead.", expected, found); Assert.assertTrue(failMessage, testCond); // look for the calendar attached to the time variable...if there isn't one, // then a default was not set and the assert will fail. Calendar cal = Calendar.get(tca.findAttributeIgnoreCase(CF.CALENDAR).getStringValue()); found = cal.toString(); expected = defaultCoardsCalendar.toString(); testCond = found.equals(expected); failMessage = format("The calendar should equal %s, but got %s instead. Failed to add a default calendar.", expected, found); Assert.assertTrue(failMessage, testCond); // convert the time value to a CalendarDate CoordinateAxisTimeHelper coordAxisTimeHelper = new CoordinateAxisTimeHelper(cal, tca.findAttributeIgnoreCase("units").getStringValue()); CalendarDate date = coordAxisTimeHelper.makeCalendarDateFromOffset(times.getInt(0)); // read the correct date from the time attribute and turn it into a CalendarDate String correctIsoDateTimeString = tca.findAttributeIgnoreCase("correct_iso_time_value_str").getStringValue(); CalendarDate correctDate = CalendarDate.parseISOformat(defaultCoardsCalendar.toString(), correctIsoDateTimeString); // If everything is correct, then the date and correct date should be the same found = date.toString(); expected = correctDate.toString(); testCond = found.equals(expected); failMessage = format("The correct date is %s, but I got %s instead.", expected, found); Assert.assertTrue(failMessage, testCond); }
Example 6
Source File: TestAggExisting.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CalendarDateUnit getCalendarDateUnit(Variable timeVar) { Attribute calAttr = timeVar.findAttributeIgnoreCase(CF.CALENDAR); assertThat(calAttr).isNotNull(); Calendar cal = Calendar.get(calAttr.getStringValue()); return CalendarDateUnit.withCalendar(cal, timeVar.getUnitsString()); }
Example 7
Source File: TestAggExistingNew.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private CalendarDateUnit getCalendarDateUnit(Variable timeVar) { Attribute calAttr = timeVar.attributes().findAttributeIgnoreCase("calendar"); assertThat(calAttr).isNotNull(); Calendar cal = Calendar.get(calAttr.getStringValue()); return CalendarDateUnit.withCalendar(cal, timeVar.getUnitsString()); }