List of usage examples for java.util GregorianCalendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:org.eevolution.form.CRP.java
/** * Create Category Dataset based on date start and resource * @param start/* w ww . j ava 2 s .c o m*/ * @param resource * @return CategoryDataset */ protected CategoryDataset createDataset(Timestamp start, MResource resource) { GregorianCalendar gc1 = new GregorianCalendar(); gc1.setTimeInMillis(start.getTime()); gc1.clear(Calendar.MILLISECOND); gc1.clear(Calendar.SECOND); gc1.clear(Calendar.MINUTE); gc1.clear(Calendar.HOUR_OF_DAY); Timestamp date = start; String namecapacity = Msg.translate(Env.getCtx(), "Capacity"); String nameload = Msg.translate(Env.getCtx(), "Load"); String namesummary = Msg.translate(Env.getCtx(), "Summary"); MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID()); int days = 1; long hours = t.getTimeSlotHours(); DefaultCategoryDataset dataset = new DefaultCategoryDataset(); // Long Hours = new Long(hours); int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ", resource.getS_Resource_ID()); MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID); if (!uom.isHour()) { return dataset; } long summary = 0; while (days < 32) { String day = new String(new Integer(date.getDate()).toString()); long HoursLoad = getLoad(resource, date).longValue(); Long Hours = new Long(hours); switch (gc1.get(Calendar.DAY_OF_WEEK)) { case Calendar.SUNDAY: days++; if (t.isOnSunday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.MONDAY: days++; if (t.isOnMonday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.TUESDAY: days++; if (t.isOnTuesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.WEDNESDAY: days++; if (t.isOnWednesday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.THURSDAY: days++; if (t.isOnThursday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.FRIDAY: days++; if (t.isOnFriday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } case Calendar.SATURDAY: days++; if (t.isOnSaturday()) { dataset.addValue(hours, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary + Hours.intValue() - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } else { dataset.addValue(0, namecapacity, day); dataset.addValue(HoursLoad, nameload, day); dataset.addValue(summary, namesummary, day); summary = summary - (HoursLoad); gc1.add(Calendar.DATE, 1); date = new Timestamp(gc1.getTimeInMillis()); break; } } } return dataset; }
From source file:org.bimserver.plugins.MavenPluginLocation.java
public GregorianCalendar getVersionDate(String version) throws ArtifactResolutionException, ParseException, IOException { // byte[] jarContent = getJarContent(version, "plugin/version.properties"); // if (jarContent != null) { // Properties properties = new Properties(); // properties.load(new ByteArrayInputStream(jarContent)); // String buildDate = properties.getProperty("build.date"); // DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); // try { // Date parse = dateFormat.parse(buildDate); // GregorianCalendar gregorianCalendar = new GregorianCalendar(); // gregorianCalendar.setTimeInMillis(parse.getTime()); // return gregorianCalendar; // } catch (ParseException e) { // return null; // }//from w w w. ja v a 2 s. c o m // } // return null; Artifact versionArtifact = new DefaultArtifact(groupId, artifactId, "version", "properties", version.toString()); ArtifactRequest request = new ArtifactRequest(); request.setArtifact(versionArtifact); request.setRepositories(mavenPluginRepository.getRepositoriesAsList()); ArtifactResult resolveArtifact = mavenPluginRepository.getSystem() .resolveArtifact(mavenPluginRepository.getSession(), request); byte[] bytes = FileUtils.readFileToByteArray(resolveArtifact.getArtifact().getFile()); Properties properties = new Properties(); properties.load(new ByteArrayInputStream(bytes)); String buildDate = properties.getProperty("build.date"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); try { Date parse = dateFormat.parse(buildDate); GregorianCalendar gregorianCalendar = new GregorianCalendar(); gregorianCalendar.setTimeInMillis(parse.getTime()); return gregorianCalendar; } catch (ParseException e) { return null; } }
From source file:net.acesinc.nifi.processors.security.ConvertSecurityMarkingAndAttrListIntoJson.java
/** * Builds the Map of attributes that should be included in the JSON that is * emitted from this process./*from ww w . j a va 2s. com*/ * * @param ff * @param rawSecurityMarking * @param atrListForStringValues * @param atrListForIntValues * @param atrListForDoubleValues * @param atrListForLongEpochToGoToDateValues * @param secConfig * @return Map of values that are feed to a Jackson ObjectMapper * @throws java.io.IOException */ protected Map<String, Object> buildSecurityAttributesMapForFlowFileAndBringInFlowAttrs(FlowFile ff, String rawSecurityMarking, String atrListForStringValues, String atrListForIntValues, String atrListForDoubleValues, String atrListForLongEpochToGoToDateValues, FlowAttrSecurityConfig secConfig) throws IOException { final ComponentLog logger = getLogger(); Map<String, Object> atsToWrite = new HashMap<>(); //handle all the string values //If list of attributes specified get only those attributes. Otherwise write them all if (StringUtils.isNotBlank(atrListForStringValues)) { String[] ats = StringUtils.split(atrListForStringValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, val); } else { atsToWrite.put(cleanStr, ""); } } } } else { atsToWrite.putAll(ff.getAttributes()); } //handle all int values if (StringUtils.isNotBlank(atrListForIntValues)) { String[] ats = StringUtils.split(atrListForIntValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, Integer.parseInt(val)); } else { atsToWrite.put(cleanStr, null); } } } } //handle all double values if (StringUtils.isNotBlank(atrListForDoubleValues)) { String[] ats = StringUtils.split(atrListForDoubleValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { atsToWrite.put(cleanStr, Double.parseDouble(val)); } else { atsToWrite.put(cleanStr, null); } } } } //handle all date values if (StringUtils.isNotBlank(atrListForLongEpochToGoToDateValues)) { String[] ats = StringUtils.split(atrListForLongEpochToGoToDateValues, AT_LIST_SEPARATOR); if (ats != null) { for (String str : ats) { String cleanStr = str.trim(); String val = ff.getAttribute(cleanStr); if (val != null) { long epochTime = Long.parseLong(val); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeZone(TimeZone.getTimeZone(MONGO_TIME_ZONE)); gcal.setTimeInMillis(epochTime); SimpleDateFormat sdf = new SimpleDateFormat(MONGO_DATE_TEMPLATE); String mongoDate = sdf.format(gcal.getTime()); //to Date Map<String, String> isoDate = new HashMap<>(); isoDate.put("$date", mongoDate); atsToWrite.put(cleanStr, isoDate); } else { atsToWrite.put(cleanStr, null); } } } } //build the classification object for json if (StringUtils.isNotBlank(rawSecurityMarking)) { Classification classification = new Classification(); String cleanRawMarking = rawSecurityMarking.trim(); logger.debug("cleanRawMarking:=" + cleanRawMarking); List<String> levels = convertSecMarkingToLevelsFlowAttr(cleanRawMarking, secConfig); classification.setLevels(levels); List<String> convertedComps = convertSecMarkingToCompartmentsFlowAttr(cleanRawMarking, secConfig); classification.setCompartments(convertedComps); List<String> convertedRels = convertSecMarkingToReleasabilitiesFlowAttr(cleanRawMarking, secConfig); classification.setReleasabilities(convertedRels); List<String> convertedDissems = convertSecMarkingToDissemControlsFlowAttr(cleanRawMarking, secConfig); classification.setDisseminationControls(convertedDissems); atsToWrite.put("classification", classification); } else { //should not get here, but if we do, we need to throw illegal state as we should not be ingesting w/o classification, but instead force configuration changes throw new IllegalStateException( "This processor is reaching an illegal state. Please adjust configuration for rawSecurityMarking to not be blank or null."); } return atsToWrite; }
From source file:org.eclipse.smarthome.binding.wemo.handler.WemoHandler.java
@Override public void onValueReceived(String variable, String value, String service) { logger.debug("Received pair '{}':'{}' (service '{}') for thing '{}'", new Object[] { variable, value, service, this.getThing().getUID() }); updateStatus(ThingStatus.ONLINE);/*from www . j ava 2s . c o m*/ this.stateMap.put(variable, value); if (getThing().getThingTypeUID().getId().equals("insight")) { String insightParams = stateMap.get("InsightParams"); if (insightParams != null) { String[] splitInsightParams = insightParams.split("\\|"); if (splitInsightParams[0] != null) { OnOffType binaryState = null; binaryState = splitInsightParams[0].equals("0") ? OnOffType.OFF : OnOffType.ON; if (binaryState != null) { logger.trace("New InsightParam binaryState '{}' for device '{}' received", binaryState, getThing().getUID()); updateState(CHANNEL_STATE, binaryState); } } long lastChangedAt = 0; try { lastChangedAt = Long.parseLong(splitInsightParams[1]) * 1000; // convert s to ms } catch (NumberFormatException e) { logger.error("Unable to parse lastChangedAt value '{}' for device '{}'; expected long", splitInsightParams[1], getThing().getUID()); } GregorianCalendar cal = new GregorianCalendar(); cal.setTimeInMillis(lastChangedAt); State lastChangedAtState = new DateTimeType(cal); if (lastChangedAt != 0) { logger.trace("New InsightParam lastChangedAt '{}' for device '{}' received", lastChangedAtState, getThing().getUID()); updateState(CHANNEL_LASTCHANGEDAT, lastChangedAtState); } State lastOnFor = DecimalType.valueOf(splitInsightParams[2]); if (lastOnFor != null) { logger.trace("New InsightParam lastOnFor '{}' for device '{}' received", lastOnFor, getThing().getUID()); updateState(CHANNEL_LASTONFOR, lastOnFor); } State onToday = DecimalType.valueOf(splitInsightParams[3]); if (onToday != null) { logger.trace("New InsightParam onToday '{}' for device '{}' received", onToday, getThing().getUID()); updateState(CHANNEL_ONTODAY, onToday); } State onTotal = DecimalType.valueOf(splitInsightParams[4]); if (onTotal != null) { logger.trace("New InsightParam onTotal '{}' for device '{}' received", onTotal, getThing().getUID()); updateState(CHANNEL_ONTOTAL, onTotal); } State timespan = DecimalType.valueOf(splitInsightParams[5]); if (timespan != null) { logger.trace("New InsightParam timespan '{}' for device '{}' received", timespan, getThing().getUID()); updateState(CHANNEL_TIMESPAN, timespan); } State averagePower = DecimalType.valueOf(splitInsightParams[6]); // natively given in W if (averagePower != null) { logger.trace("New InsightParam averagePower '{}' for device '{}' received", averagePower, getThing().getUID()); updateState(CHANNEL_AVERAGEPOWER, averagePower); } BigDecimal currentMW = new BigDecimal(splitInsightParams[7]); State currentPower = new DecimalType(currentMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate // mW to W if (currentPower != null) { logger.trace("New InsightParam currentPower '{}' for device '{}' received", currentPower, getThing().getUID()); updateState(CHANNEL_CURRENTPOWER, currentPower); } BigDecimal energyTodayMWMin = new BigDecimal(splitInsightParams[8]); // recalculate mW-mins to Wh State energyToday = new DecimalType( energyTodayMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP)); if (energyToday != null) { logger.trace("New InsightParam energyToday '{}' for device '{}' received", energyToday, getThing().getUID()); updateState(CHANNEL_ENERGYTODAY, energyToday); } BigDecimal energyTotalMWMin = new BigDecimal(splitInsightParams[9]); // recalculate mW-mins to Wh State energyTotal = new DecimalType( energyTotalMWMin.divide(new BigDecimal(60000), RoundingMode.HALF_UP)); if (energyTotal != null) { logger.trace("New InsightParam energyTotal '{}' for device '{}' received", energyTotal, getThing().getUID()); updateState(CHANNEL_ENERGYTOTAL, energyTotal); } BigDecimal standByLimitMW = new BigDecimal(splitInsightParams[10]); State standByLimit = new DecimalType( standByLimitMW.divide(new BigDecimal(1000), RoundingMode.HALF_UP)); // recalculate // mW to W if (standByLimit != null) { logger.trace("New InsightParam standByLimit '{}' for device '{}' received", standByLimit, getThing().getUID()); updateState(CHANNEL_STANDBYLIMIT, standByLimit); } } } else { State state = stateMap.get("BinaryState").equals("0") ? OnOffType.OFF : OnOffType.ON; logger.debug("State '{}' for device '{}' received", state, getThing().getUID()); if (state != null) { if (getThing().getThingTypeUID().getId().equals("motion")) { updateState(CHANNEL_MOTIONDETECTION, state); if (state.equals(OnOffType.ON)) { State lastMotionDetected = new DateTimeType(); updateState(CHANNEL_LASTMOTIONDETECTED, lastMotionDetected); } } else { updateState(CHANNEL_STATE, state); } } } }
From source file:eu.stratosphere.client.web.JobsServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String action = req.getParameter(ACTION_PARAM_NAME); if (action.equals(ACTION_LIST_VALUE)) { GregorianCalendar cal = new GregorianCalendar(); File[] files = destinationDir.listFiles(); Arrays.<File>sort(files, FILE_SORTER); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType(CONTENT_TYPE_PLAIN); PrintWriter writer = resp.getWriter(); for (int i = 0; i < files.length; i++) { if (!files[i].getName().endsWith(".jar")) { continue; }//from ww w . java2 s .co m cal.setTimeInMillis(files[i].lastModified()); writer.println(files[i].getName() + '\t' + (cal.get(GregorianCalendar.MONTH) + 1) + '/' + cal.get(GregorianCalendar.DAY_OF_MONTH) + '/' + cal.get(GregorianCalendar.YEAR) + ' ' + cal.get(GregorianCalendar.HOUR_OF_DAY) + ':' + cal.get(GregorianCalendar.MINUTE) + ':' + cal.get(GregorianCalendar.SECOND)); } } else if (action.equals(ACTION_DELETE_VALUE)) { String filename = req.getParameter(FILENAME_PARAM_NAME); if (filename == null || filename.length() == 0) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { File f = new File(destinationDir, filename); if (!f.exists() || f.isDirectory()) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } f.delete(); resp.setStatus(HttpServletResponse.SC_OK); } } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } }
From source file:org.miloss.fgsms.common.Utility.java
/** * Parses the date/time stamp from a given input parameter using one of the * following formats<br> <ul> <li>mm/dd/yyyy</li> <li>mm/dd/yyyy * hh:mm:ss</li> <li>EEE MMM dd HH:mm:ss zzz yyyy - this is the standard * output from the unix date command</li> <li>EEE mm/dd/yyyy HH:mm:ss.ms - * this is the standard output from the windows command echo %date% * %time%</li> <li>yyyy-MM-ddThh:mm:ss.zzzzzzz</li> <li>Epoch time (ms)</li> * <li>PnYnMnDTnHnMnS - XML lexical representation</li> </ul> * * @param s the input string// w ww . j a v a 2s . c o m * @return a non-null instance of Calendar matching the interpreted date. * @throws Exception if the date cannot be parsed */ public static Calendar parseDateTime(String s) throws Exception { //this is what the calendar widget gives us SimpleDateFormat f1 = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat f2 = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); //std unix date format SimpleDateFormat f3 = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); //std windows date format SimpleDateFormat f4 = new SimpleDateFormat("EEE MM/dd/yyyy HH:mm:ss.ms"); SimpleDateFormat f5 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.zzzzzzz"); Date d = null; try { d = f1.parse(s, new ParsePosition(0)); } catch (Exception ex) { } if (d == null) { try { d = f2.parse(s, new ParsePosition(0)); } catch (Exception ex) { } } if (d == null) { try { d = f3.parse(s, new ParsePosition(0)); } catch (Exception ex) { } } if (d == null) { try { d = f4.parse(s, new ParsePosition(0)); } catch (Exception ex) { } } if (d == null) { try { d = f5.parse(s, new ParsePosition(0)); } catch (Exception ex) { } } if (d != null) { GregorianCalendar gcal = new GregorianCalendar(); gcal.setTime(d); return (gcal); } try { long timestamp = Long.parseLong(s); GregorianCalendar gcal = new GregorianCalendar(); gcal.setTimeInMillis(timestamp); return (gcal); } catch (Exception x) { } throw new Exception("Unable to parse the date, see documentation for correct usage"); }
From source file:org.geotools.gce.imagemosaic.ImageMosaicPostgisIndexOnlineTest.java
/** * Complex test for Postgis indexing on db. * //w ww. j a v a2s .c om * @throws Exception */ @Test public void testSortingAndLimiting() throws Exception { final File workDir = new File(TestData.file(this, "."), tempFolderName2); assertTrue(workDir.mkdir()); FileUtils.copyFile(TestData.file(this, "watertemp.zip"), new File(workDir, "watertemp.zip")); TestData.unzipFile(this, tempFolderName2 + "/watertemp.zip"); final URL timeElevURL = TestData.url(this, tempFolderName2); //place datastore.properties file in the dir for the indexing FileWriter out = null; try { out = new FileWriter(new File(TestData.file(this, "."), tempFolderName2 + "/datastore.properties")); final Set<Object> keyset = fixture.keySet(); for (Object key : keyset) { final String key_ = (String) key; final String value = fixture.getProperty(key_); out.write(key_.replace(" ", "\\ ") + "=" + value.replace(" ", "\\ ") + "\n"); } out.flush(); } finally { if (out != null) { IOUtils.closeQuietly(out); } } // now start the test final AbstractGridFormat format = TestUtils.getFormat(timeElevURL); assertNotNull(format); ImageMosaicReader reader = TestUtils.getReader(timeElevURL, format); assertNotNull(reader); final String[] metadataNames = reader.getMetadataNames(); assertNotNull(metadataNames); assertEquals(12, metadataNames.length); assertEquals("true", reader.getMetadataValue("HAS_TIME_DOMAIN")); assertEquals("true", reader.getMetadataValue("HAS_ELEVATION_DOMAIN")); // dispose and create new reader reader.dispose(); final MyImageMosaicReader reader1 = new MyImageMosaicReader(timeElevURL); final RasterManager rasterManager = reader1.getRasterManager(reader1.getGridCoverageNames()[0]); // query final SimpleFeatureType type = rasterManager.granuleCatalog.getType("waterTempPG2"); Query query = null; if (type != null) { // creating query query = new Query(type.getTypeName()); // sorting and limiting // max number of elements query.setMaxFeatures(1); // sorting final SortBy[] clauses = new SortBy[] { new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"), SortOrder.DESCENDING), new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"), SortOrder.ASCENDING), }; query.setSortBy(clauses); } // checking that we get a single feature and that feature is correct final Collection<GranuleDescriptor> features = new ArrayList<GranuleDescriptor>(); rasterManager.getGranuleDescriptors(query, new GranuleCatalogVisitor() { @Override public void visit(GranuleDescriptor granule, Object o) { features.add(granule); } }); assertEquals(features.size(), 1); GranuleDescriptor granule = features.iterator().next(); SimpleFeature sf = granule.getOriginator(); assertNotNull(sf); Object ingestion = sf.getAttribute("ingestion"); assertTrue(ingestion instanceof Timestamp); final GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); gc.setTimeInMillis(1225497600000l); assertEquals(0, (((Timestamp) ingestion).compareTo(gc.getTime()))); Object elevation = sf.getAttribute("elevation"); assertTrue(elevation instanceof Integer); assertEquals(((Integer) elevation).intValue(), 0); // Reverting order (the previous timestamp shouldn't match anymore) final SortBy[] clauses = new SortBy[] { new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("ingestion"), SortOrder.ASCENDING), new SortByImpl(FeatureUtilities.DEFAULT_FILTER_FACTORY.property("elevation"), SortOrder.DESCENDING), }; query.setSortBy(clauses); // checking that we get a single feature and that feature is correct features.clear(); rasterManager.getGranuleDescriptors(query, new GranuleCatalogVisitor() { @Override public void visit(GranuleDescriptor granule, Object o) { features.add(granule); } }); assertEquals(features.size(), 1); granule = features.iterator().next(); sf = granule.getOriginator(); assertNotNull(sf); ingestion = sf.getAttribute("ingestion"); assertTrue(ingestion instanceof Timestamp); assertNotSame(0, (((Timestamp) ingestion).compareTo(gc.getTime()))); elevation = sf.getAttribute("elevation"); assertTrue(elevation instanceof Integer); assertNotSame(((Integer) elevation).intValue(), 0); }
From source file:uk.nhs.cfh.dsp.srth.demographics.person.utils.PatientUtilsServiceImpl.java
public Patient createRandomPatient(int minAge) { GregorianCalendar gc = new GregorianCalendar(1900, 0, 1); long centuryStart = gc.getTimeInMillis(); // rewind time to now - 1 GregorianCalendar gc2 = new GregorianCalendar(); gc2.setTime(Calendar.getInstance().getTime()); gc2.add(Calendar.YEAR, -minAge); long todayMinusMinYears = gc2.getTimeInMillis(); // use a random value to generate values between century start and today long randomTime = (long) (Math.random() * (todayMinusMinYears - centuryStart)) + centuryStart; // use random time to set calendar gc.setTimeInMillis(randomTime); // create and return patient with dob as random time return createRandomPatient(gc); }
From source file:org.mozilla.gecko.updater.UpdateService.java
private Calendar getLastAttemptDate() { long lastAttempt = mPrefs.getLong(KEY_LAST_ATTEMPT_DATE, -1); if (lastAttempt < 0) return null; GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); cal.setTimeInMillis(lastAttempt); return cal;// w ww. j av a 2 s . c o m }
From source file:TimePeriod.java
/** * Gibt zurck, wie oft der bergebene Wochentag im Zeitraum vorkommt. * /*from w w w . j av a 2 s . c o m*/ * @param wochentag * Sonntag = 1 * @return */ public int getNumberOfWeekdays(int wochentag) { int ergebnis = 0; GregorianCalendar temp = new GregorianCalendar(); temp.setTime(from.getTime()); // Schleife ber alle Tage int aktuellerTag; while (temp.before(to)) { aktuellerTag = temp.get(Calendar.DAY_OF_WEEK); if (aktuellerTag == wochentag) ergebnis++; temp.setTimeInMillis(temp.getTimeInMillis() + ONE_DAY); } return ergebnis; }