List of usage examples for java.util Date setDate
@Deprecated public void setDate(int date)
From source file:com.krawler.spring.crm.common.crmManagerDAOImpl.java
/** * To convert a date and time selected separately by user into corresponding combined datetime * from users selected timezone to systems timezone * * The first step is to keep track of the time difference in order to change the date if required. * Two time only objects dtold and dtcmp are created for this purpose. * * The date passed and the time passed that are in system timezone are formatted without * timezone and then parsed into the required timezone and then the time values are set * back to the date value sent.//from w w w .j a v a 2 s.co m * **/ public Date converttz(String timeZoneDiff, Date dt, String time) { Calendar cal = Calendar.getInstance(); try { if (timeZoneDiff == null || timeZoneDiff.isEmpty()) { timeZoneDiff = "-7:00"; } String val; SimpleDateFormat sdf = new SimpleDateFormat("HHmm 'Hrs'"); Date dtold = sdf.parse("0000 Hrs"); if (!time.endsWith("Hrs")) { sdf = new SimpleDateFormat("hh:mm a"); dtold = sdf.parse("00:00 AM"); } SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm a"); sdf2.setTimeZone(TimeZone.getTimeZone("GMT" + timeZoneDiff)); // Setting the timezone passed Date dt1 = sdf.parse(time); // Setting the passed time to the date object in system timezone sdf.setTimeZone(TimeZone.getTimeZone("GMT" + timeZoneDiff)); // Setting the timezone passed Date dtcmp = sdf.parse(time); // Parsing the time to timezone using passed values dt1.setMonth(dt.getMonth()); // Setting the date values sent to the system time only value dt1.setDate(dt.getDate()); dt1.setYear(dt.getYear()); dt1 = sdf2.parse(sdf1.format(dt1)); // Parsing datetime into required timezone dt.setHours(dt1.getHours()); // Setting the time values into the sent date dt.setMinutes(dt1.getMinutes()); dt.setSeconds(0); cal.setTime(dt); if (dtcmp.compareTo(dtold) < 0) { // Comparing for time value change cal.add(Calendar.DATE, -1); // in order to change the date accordingly } dtold.setDate(2); if (dtcmp.compareTo(dtold) > 0 || dtcmp.compareTo(dtold) == 0) { cal.add(Calendar.DATE, 1); } } catch (ParseException ex) { System.out.println(ex); } finally { return cal.getTime(); } }
From source file:com.progym.custom.fragments.FoodProgressYearlyLineFragment.java
public void setYearProgressData(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);//from w w w.ja v a2 s.c om ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(viewChart); } catch (Exception edsx) { edsx.printStackTrace(); } } }); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set January as first month date.setMonth(0); date.setDate(1); int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); CategorySeries seriesProtein = new CategorySeries("Protein"); CategorySeries seriesFat = new CategorySeries("Fat"); CategorySeries seriesCarbs = new CategorySeries("Carbs"); List<Ingridient> list; Date dt = date; for (int element : x) { list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM)); // init "average" data double totalProtein = 0, totalFat = 0, totalCarbs = 0, totalCallories = 0; for (Ingridient ingridient : list) { totalProtein += ingridient.protein; totalFat += ingridient.fat; totalCarbs += ingridient.carbohydrates; totalCallories += ingridient.kkal; } seriesProtein.add((double) Math.round(totalProtein * 100) / 100); seriesFat.add((double) Math.round(totalFat * 100) / 100); seriesCarbs.add((double) Math.round(totalCarbs * 100) / 100); // calculate maximum Y axis values yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs); // increment month dt = DateUtils.addMonths(dt, 1); } int[] colors = new int[] { getActivity().getResources().getColor(R.color.green), getActivity().getResources().getColor(R.color.orange), getActivity().getResources().getColor(R.color.purple) }; final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors); setChartSettings(renderer, String.format("Protein/Carbohydrates/Fat statistic for %s year", Utils.getSpecificDateValue(DATE, "yyyy")), "Months", "Amount (g) ", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY, Color.LTGRAY); renderer.getSeriesRendererAt(0).setDisplayChartValues(true); renderer.getSeriesRendererAt(1).setDisplayChartValues(true); renderer.getSeriesRendererAt(2).setDisplayChartValues(true); renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f); renderer.getSeriesRendererAt(1).setChartValuesTextSize(15f); renderer.getSeriesRendererAt(2).setChartValuesTextSize(15f); // renderer.getSeriesRendererAt(0).setChartValuesTextAlign(Align.CENTER); // renderer.getSeriesRendererAt(1).setChartValuesTextAlign(Align.LEFT); // renderer.getSeriesRendererAt(2).setChartValuesTextAlign(Align.RIGHT); renderer.setXLabels(0); // renderer.setYLabels(10); // renderer.setXLabelsAlign(Align.LEFT); // renderer.setYLabelsAlign(Align.LEFT); // renderer.setPanEnabled(true, false); renderer.setClickEnabled(false); renderer.setZoomEnabled(false); renderer.setPanEnabled(false, false); renderer.setZoomButtonsVisible(false); renderer.setPanLimits(new double[] { 1, 11 }); // renderer.setZoomEnabled(false); // renderer.setZoomRate(1.1f); renderer.setShowGrid(true); renderer.setShowLegend(true); renderer.setFitLegend(true); for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) { renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]); } dataset.addSeries(seriesProtein.toXYSeries()); dataset.addSeries(seriesFat.toXYSeries()); dataset.addSeries(seriesCarbs.toXYSeries()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { viewChart = ChartFactory.getLineChartView(getActivity(), dataset, renderer/* , Type.STACKED */); rlRootGraphLayout.addView(viewChart, 0); if (isLeftIn) { rightIn.setDuration(1000); viewChart.startAnimation(rightIn); } else { leftIn.setDuration(1000); viewChart.startAnimation(leftIn); } } catch (Exception edsx) { edsx.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:com.zoho.creator.jframework.XMLParser.java
private static void parseAndSetCalendarRecords(ZCView zcView, Node calendarNode) { zcView.setGrouped(true);/*from w w w . j a v a 2 s . c o m*/ NodeList eventsList = calendarNode.getChildNodes(); int year = zcView.getRecordsMonthYear().getTwo() - 1900; int month = zcView.getRecordsMonthYear().getOne(); GregorianCalendar cureentmnthcalendar = new GregorianCalendar(); Date currentDate = new Date(); for (int i = 0; i < eventsList.getLength(); i++) { Node eventNode = eventsList.item(i); NamedNodeMap eventAttrMap = eventNode.getAttributes(); long recordid = Long.parseLong(eventAttrMap.getNamedItem("id").getNodeValue()); //No I18N String title = getChildNodeValue(eventNode, "title"); //eventAttrMap.getNamedItem("title").getNodeValue(); //No I18N boolean isAllDay = Boolean.parseBoolean(eventAttrMap.getNamedItem("allDay").getNodeValue()); //No I18N // 07/31/2013 08:00:00 String dateFormat = "MM/dd/yyyy HH:mm:ss"; //No I18N if (isAllDay) { dateFormat = "MM/dd/yyyy"; //No I18N } Date startTime = getDateValue(eventAttrMap.getNamedItem("start").getNodeValue(), dateFormat); //No I18N ZCRecord record = zcView.getRecord(recordid); record.setEventTitle(title); if (isAllDay) { zcView.setIsAllDay(isAllDay); Node endNode = eventAttrMap.getNamedItem("end");//No I18N Date endTime = null; if (endNode != null) { endTime = getDateValue(endNode.getNodeValue(), dateFormat); } int startDay = -1; if (startTime != null) { startDay = startTime.getDate(); } int endDay = -1; if (endTime != null) { endDay = endTime.getDate(); } if (endDay != -1) { currentDate.setDate(1); currentDate.setMonth(month); currentDate.setYear(year); currentDate.setMinutes(0); currentDate.setHours(0); currentDate.setSeconds(0); cureentmnthcalendar.setTime(currentDate); cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, -6); currentDate = cureentmnthcalendar.getTime(); for (int j = 0; j < 42; j++) { if ((currentDate.getDate() == startTime.getDate() && currentDate.getMonth() == startTime.getMonth() && currentDate.getYear() == startTime.getYear()) || (currentDate.after(startTime) && currentDate.before(endTime)) || (currentDate.getDate() == endTime.getDate() && currentDate.getMonth() == endTime.getMonth() && currentDate.getYear() == endTime.getYear())) { zcView.setEvent(record, currentDate); } cureentmnthcalendar.add(cureentmnthcalendar.DAY_OF_MONTH, 1); currentDate = cureentmnthcalendar.getTime(); } //Collections.sort(eventRecords); } record.setEventDate(startTime); } else { // 07/31/2013 08:00:00 Date endTime = getDateValue(eventAttrMap.getNamedItem("end").getNodeValue(), dateFormat); //No I18N record.setStartTime(startTime); record.setEndTime(endTime); Calendar startCalendar = new GregorianCalendar(); startCalendar.setTime(startTime); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); startCalendar.set(Calendar.MILLISECOND, 0); Calendar endCalendar = new GregorianCalendar(); endCalendar.setTime(endTime); endCalendar.set(Calendar.HOUR_OF_DAY, 0); endCalendar.set(Calendar.MINUTE, 0); endCalendar.set(Calendar.SECOND, 0); endCalendar.set(Calendar.MILLISECOND, 0); Date eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); while ((startCalendar.get(Calendar.YEAR) != endCalendar.get(Calendar.YEAR)) || (startCalendar.get(Calendar.MONTH) != endCalendar.get(Calendar.MONTH)) || (startCalendar.get(Calendar.DATE) != endCalendar.get(Calendar.DATE))) { startCalendar.add(Calendar.DATE, 1); eventDate = new Date(startCalendar.getTimeInMillis()); zcView.setEvent(record, eventDate); } } } List<ZCGroup> zcGroups = zcView.getGroups(); HashMap<Date, List<ZCRecord>> eventsMap = zcView.getEventRecordsMap(); SortedSet<Date> keys = new TreeSet<Date>(eventsMap.keySet()); for (Date eventDate : keys) { List<ZCRecord> eventRecords = eventsMap.get(eventDate); List<String> groupHeaderValues = new ArrayList<String>(); SimpleDateFormat dateFormat = new SimpleDateFormat(zcView.getDateFormat()); //No I18N groupHeaderValues.add(dateFormat.format(eventDate)); ZCGroup zcGroup = new ZCGroup(groupHeaderValues); zcGroups.add(zcGroup); for (int i = 0; i < eventRecords.size(); i++) { ZCRecord eventRecord = eventRecords.get(i); zcGroup.addRecord(eventRecord); } } zcView.sortRecordsForCalendar(); }