List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:org.psystems.dicom.browser.server.stat.StatDailyLoadChartServlet.java
/** * Returns a sample dataset./*from w w w . java 2 s . c o m*/ * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long time = calendarEnd.getTimeInMillis(); time = time - (time % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(time); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, "??? (DCM-)", "ALL_DCM_SIZE", calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset); getMetrics(connection, "? (JPG-)", "ALL_IMAGE_SIZE", calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } return dataset; }
From source file:com.QuarkLabs.BTCeClient.adapters.OrdersAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { View v = null;/*from www . ja v a 2s . c om*/ TextView timestamp; final JSONObject dataToDisplay = getItem(position); TextView orderID; TextView type; TextView amount; TextView pair; TextView rate; switch (mListType) { case Transactions: if (convertView == null) { v = mInflater.inflate(R.layout.fragment_trans_history_item, parent, false); } else { v = convertView; } TextView description = (TextView) v.findViewById(R.id.TransHistoryDesc); timestamp = (TextView) v.findViewById(R.id.TransHistoryTimestamp); amount = (TextView) v.findViewById(R.id.TransHistoryAmount); try { Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); description.setText(dataToDisplay.getString("desc")); calendar.setTimeInMillis(Long.parseLong(dataToDisplay.getString("timestamp")) * 1000L); timestamp.setText(mDateFormat.format(calendar.getTime())); amount.setText(dataToDisplay.getString("amount") + dataToDisplay.getString("currency")); } catch (JSONException e) { e.printStackTrace(); } break; case Trades: if (convertView == null) { v = mInflater.inflate(R.layout.fragment_trade_history_item, parent, false); } else { v = convertView; } pair = (TextView) v.findViewById(R.id.TradeHistoryPair); rate = (TextView) v.findViewById(R.id.TradeHistoryRate); amount = (TextView) v.findViewById(R.id.TradeHistoryAmount); type = (TextView) v.findViewById(R.id.TradeHistoryType); orderID = (TextView) v.findViewById(R.id.TradeHistoryOrderID); timestamp = (TextView) v.findViewById(R.id.TradeHistoryTimestamp); try { String pairValue = dataToDisplay.getString("pair"); Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); orderID.setText(dataToDisplay.getString("order_id")); calendar.setTimeInMillis(Long.parseLong(dataToDisplay.getString("timestamp")) * 1000L); timestamp.setText(mDateFormat.format(calendar.getTime())); pair.setText(pairValue.replace("_", "/").toUpperCase(Locale.US)); rate.setText(dataToDisplay.getString("rate") + " " + pairValue.substring(4).toUpperCase(Locale.US)); amount.setText( dataToDisplay.getString("amount") + " " + pairValue.substring(0, 3).toUpperCase(Locale.US)); type.setText(dataToDisplay.getString("type")); } catch (JSONException e) { e.printStackTrace(); } break; case ActiveOrders: if (convertView == null) { v = mInflater.inflate(R.layout.fragment_active_orders_item, parent, false); } else { v = convertView; } pair = (TextView) v.findViewById(R.id.ActiveOrderPair); type = (TextView) v.findViewById(R.id.ActiveOrderType); amount = (TextView) v.findViewById(R.id.ActiveOrderAmount); rate = (TextView) v.findViewById(R.id.ActiveOrderRate); timestamp = (TextView) v.findViewById(R.id.ActiveOrderTimestamp); orderID = (TextView) v.findViewById(R.id.ActiveOrderID); ImageView remove = (ImageView) v.findViewById(R.id.removeOrder); remove.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final int order_id = dataToDisplay.optInt("id"); new AlertDialog.Builder(mContext).setTitle("Remove confirmation") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new CancelActiveOrder().execute(order_id); } }).setNegativeButton("No", null).setMessage("Are you sure you want to delete OrderID=" + dataToDisplay.optString("id") + "?") .show(); } }); try { String pairValue = dataToDisplay.getString("pair"); Calendar calendar = Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()); pair.setText(pairValue.replace("_", "/").toUpperCase(Locale.US)); type.setText(dataToDisplay.getString("type")); amount.setText( dataToDisplay.getString("amount") + " " + pairValue.substring(0, 3).toUpperCase(Locale.US)); rate.setText(dataToDisplay.getString("rate") + " " + pairValue.substring(4).toUpperCase(Locale.US)); calendar.setTimeInMillis(Long.parseLong(dataToDisplay.getString("timestamp_created")) * 1000L); timestamp.setText(mDateFormat.format(calendar.getTime())); orderID.setText(String.valueOf(mData.get(position).optInt("id"))); } catch (JSONException e) { e.printStackTrace(); } default: break; } return v; }
From source file:moller.javapeg.program.gui.frames.ImageRepositoryStatisticsViewer.java
private Component createWeekDayStatistics() { int[] weekdays = new int[] { 0, 0, 0, 0, 0, 0, 0 }; ImageMetaDataContext imdc = ImageMetaDataContext.getInstance(); Calendar calendar = Calendar.getInstance(); Map<String, Long> dateTimeValues = imdc.getDateTimeValues(); for (String imagePath : dateTimeValues.keySet()) { calendar.setTimeInMillis(dateTimeValues.get(imagePath)); ++weekdays[calendar.get(Calendar.DAY_OF_WEEK) - 1]; }/*from w ww . j a v a 2 s. c o m*/ DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String title = getLang().get("imagestatisticsviewer.chart.weekday.title"); for (int i = 0; i < weekdays.length; i++) { dataSet.setValue(weekdays[i], title, getWeekDayAsString(i + 1)); } return createChart(dataSet, title); }
From source file:com.adobe.communities.ugc.migration.importer.MessagesImportServlet.java
private void importMessages(final SlingHttpServletRequest request, final JsonParser jsonParser, final Map<String, Object> messageModifiers) throws ServletException { if (!jsonParser.getCurrentToken().equals(JsonToken.START_ARRAY)) { throw new ServletException("unexpected starting token " + jsonParser.getCurrentToken().asString()); }/*from w w w. j a v a 2 s . c o m*/ try { jsonParser.nextToken(); //presumably, we will advance to a "start object" token while (!jsonParser.getCurrentToken().equals(JsonToken.END_ARRAY)) { final Map<String, Map<String, Boolean>> recipientModifiers = new HashMap<String, Map<String, Boolean>>(); final Map<String, Object> props = new HashMap<String, Object>(); final Map<String, Object> messageModifier = new HashMap<String, Object>(); List<FileDataSource> attachments = new ArrayList<FileDataSource>(); String sender = ""; jsonParser.nextToken(); //field name while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String fieldName = jsonParser.getCurrentName(); jsonParser.nextToken(); //value if (fieldName.equals("senderId")) { sender = URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8"); } else if (fieldName.equals("added")) { final Calendar calendar = new GregorianCalendar(); calendar.setTimeInMillis(jsonParser.getLongValue()); messageModifier.put("added", calendar); } else if (fieldName.equals("recipients")) { // build the string for the "to" property and also create the modifiers we'll need later final StringBuilder recipientString = new StringBuilder(); //iterate over each key (each being a recipient id) if (jsonParser.getCurrentToken().equals(JsonToken.START_OBJECT)) { jsonParser.nextToken(); // should get first recipientId while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String recipientId = jsonParser.getCurrentName(); jsonParser.nextToken(); //start object jsonParser.nextToken(); //first label final Map<String, Boolean> interactionModifiers = new HashMap<String, Boolean>(); while (!jsonParser.getCurrentToken().equals(JsonToken.END_OBJECT)) { final String label = jsonParser.getCurrentName(); jsonParser.nextToken(); final Boolean labelValue = jsonParser.getBooleanValue(); interactionModifiers.put(label, labelValue); jsonParser.nextToken(); //next label or end object } try { final String userPath = userPropertiesService.getAuthorizablePath(recipientId); recipientModifiers.put(userPath, interactionModifiers); recipientString.append(recipientId); } catch (final RepositoryException e) { // log the fact that a recipient specified in the json file doesn't exist in this // environment throw new ServletException( "A recipient specified in the migration file couldn't " + "be found in this environment", e); } jsonParser.nextToken(); // next recipientId or end object if (jsonParser.getCurrentToken().equals(JsonToken.FIELD_NAME)) { recipientString.append(';'); } } props.put("to", recipientString); messageModifier.put("recipientDetails", recipientModifiers); } } else if (fieldName.equals(ContentTypeDefinitions.LABEL_ATTACHMENTS)) { UGCImportHelper.getAttachments(jsonParser, attachments); } else { props.put(fieldName, URLDecoder.decode(jsonParser.getValueAsString(), "UTF-8")); } jsonParser.nextToken(); //either next field name or end object } final Random range = new Random(); final String key = String.valueOf(range.nextInt(Integer.MAX_VALUE)) + String.valueOf(range.nextInt(Integer.MAX_VALUE)); // we're going to temporarily overwrite the subject (to do a search) and need to track its initial value if (props.containsKey("subject")) { messageModifier.put("subject", props.get("subject")); } else { messageModifier.put("subject", ""); } props.put("subject", key); //use subject as the search key messageModifiers.put(key, messageModifier); try { short result = messagingService.create(request.getResourceResolver(), request.getResource(), sender, props, attachments, clientUtilsFactory.getClientUtilities(xss, request, socialUtils)); if (result != 200) { throw new ServletException("Message sending failed. Return code was " + result); } } catch (final OperationException e) { throw new ServletException("Unable to create a message through the operation service", e); } jsonParser.nextToken(); //either END_ARRAY or START_OBJECT } } catch (final IOException e) { throw new ServletException("Encountered exception while parsing json content", e); } }
From source file:com.qcadoo.mes.orderGroups.OrderGroupsServiceTest.java
private Object getDateWithTimeInterval(final int additionalDays) { Calendar cal = Calendar.getInstance(); if (additionalDays == 0) { return null; } else {//from w ww . j a v a 2s . co m cal.setTimeInMillis(now); cal.add(Calendar.DAY_OF_MONTH, additionalDays); } return cal.getTime(); }
From source file:org.hawkular.alerter.elasticsearch.ElasticsearchQuery.java
private Date intervalDate() { String interval = properties.get(INTERVAL); int value = getIntervalValue(interval); switch (getIntervalUnit(interval)) { case HOURS://from w w w. j av a 2 s .com value = value * 3600 * 1000; break; case MINUTES: value = value * 60 * 1000; break; case SECONDS: value = value * 1000; break; } Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis() - value); return cal.getTime(); }
From source file:com.wildplot.android.ankistats.HourlyBreakdown.java
public boolean calculateBreakdown(int type) { mTitle = R.string.stats_breakdown;//from ww w . j ava 2s .co m mAxisTitles = new int[] { R.string.stats_time_of_day, R.string.stats_percentage_correct, R.string.stats_reviews }; mValueLabels = new int[] { R.string.stats_percentage_correct, R.string.stats_answers }; mColors = new int[] { R.color.stats_counts, R.color.stats_hours }; mType = type; String lim = _revlogLimitWholeOnly().replaceAll("[\\[\\]]", ""); if (lim.length() > 0) { lim = " and " + lim; } Calendar sd = GregorianCalendar.getInstance(); sd.setTimeInMillis(mCollectionData.getCrt() * 1000); Calendar cal = Calendar.getInstance(); TimeZone tz = TimeZone.getDefault(); /* date formatter in local timezone */ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); sdf.setTimeZone(tz); /* print your timestamp and double check it's the date you expect */ String localTime = sdf.format(new Date(mCollectionData.getCrt() * 1000)); // I assume your timestamp is in seconds and you're converting to milliseconds? int pd = _periodDays(); if (pd > 0) { lim += " and id > " + ((mCollectionData.getDayCutoff() - (86400 * pd)) * 1000); } int hourOfDay = sd.get(GregorianCalendar.HOUR_OF_DAY); long cutoff = mCollectionData.getDayCutoff(); long cut = cutoff - sd.get(Calendar.HOUR_OF_DAY) * 3600; ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "select " + "23 - ((cast((" + cut + " - id/1000) / 3600.0 as int)) % 24) as hour, " + "sum(case when ease = 1 then 0 else 1 end) / " + "cast(count() as float) * 100, " + "count() " + "from revlog where type in (0,1,2) " + lim + " " + "group by hour having count() > 30 order by hour"; Log.d(AnkiStatsApplication.TAG, sd.get(Calendar.HOUR_OF_DAY) + " : " + cutoff + " breakdown query: " + query); try { cur = mAnkiDb.getDatabase().rawQuery(query, null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for breakdown, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine // if (list.size() == 0 || list.get(0)[0] > 0) { // list.add(0, new double[] { 0, 0, 0 }); // } // if (num == -1 && list.size() < 2) { // num = 31; // } // if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) { // list.add(new double[] { num, 0, 0 }); // } else if (type == Utils.TYPE_LIFE && list.size() < 2) { // list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0, 0 }); // } for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int intHour = (int) data[0]; int hour = (intHour - 4) % 24; if (hour < 0) hour += 24; data[0] = hour; list.set(i, data); } Collections.sort(list, new Comparator<double[]>() { @Override public int compare(double[] s1, double[] s2) { if (s1[0] < s2[0]) return -1; if (s1[0] > s2[0]) return 1; return 0; } }); mSeriesList = new double[4][list.size()]; mPeak = 0.0; mMcount = 0.0; double minHour = Double.MAX_VALUE; double maxHour = 0; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int hour = (int) data[0]; //double hour = data[0]; if (hour < minHour) minHour = hour; if (hour > maxHour) maxHour = hour; double pct = data[1]; if (pct > mPeak) mPeak = pct; mSeriesList[0][i] = hour; mSeriesList[1][i] = pct; mSeriesList[2][i] = data[2]; if (i == 0) { mSeriesList[3][i] = pct; } else { double prev = mSeriesList[3][i - 1]; double diff = pct - prev; diff /= 3.0; diff = Math.round(diff * 10.0) / 10.0; mSeriesList[3][i] = prev + diff; } if (data[2] > mMcount) mMcount = data[2]; if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) mSeriesList[1][i]; } mMaxElements = (int) (maxHour - minHour); return list.size() > 0; }
From source file:TimeSpan.java
/** * Returns {@code true} if the end date occurs after the start date during * the period of time represented by this time span. *///from w w w . j av a2 s . c o m public boolean insideRange(long startDate, long endDate) { Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTimeInMillis(startDate); c2.setTimeInMillis(endDate); return isInRange(c1, c2); }