List of usage examples for java.util Calendar DATE
int DATE
To view the source code for java.util Calendar DATE.
Click Source Link
get
and set
indicating the day of the month. From source file:net.sourceforge.eclipsetrader.core.ui.dialogs.ExchangeRateDialog.java
protected Control createDialogArea(Composite parent) { Composite content = new Composite(parent, SWT.NONE); GridLayout gridLayout = new GridLayout(6, false); gridLayout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); gridLayout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); gridLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); gridLayout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); content.setLayout(gridLayout);/*from w w w . j a va 2 s . co m*/ content.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); Label label = new Label(content, SWT.NONE); label.setText(Messages.ExchangeRateDialog_Date); label.setLayoutData(new GridData(60, SWT.DEFAULT)); text = new Text(content, SWT.BORDER); text.setSize(80, SWT.DEFAULT); GridData gridData = new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false, 5, 1); gridData.widthHint = 80; text.setLayoutData(gridData); text.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { try { Date date = dateParse.parse(text.getText()); text.setText(dateFormat.format(date)); } catch (Exception e1) { text.setText(dateFormat.format(Calendar.getInstance().getTime())); } update(); } }); text.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.ARROW_UP) { try { Calendar calendar = Calendar.getInstance(); calendar.setTime(dateParse.parse(text.getText())); calendar.add(Calendar.DATE, 1); text.setText(dateFormat.format(calendar.getTime())); } catch (Exception e1) { text.setText(dateFormat.format(Calendar.getInstance().getTime())); } update(); } else if (e.keyCode == SWT.ARROW_DOWN) { try { Calendar calendar = Calendar.getInstance(); calendar.setTime(dateParse.parse(text.getText())); calendar.add(Calendar.DATE, -1); text.setText(dateFormat.format(calendar.getTime())); } catch (Exception e1) { text.setText(dateFormat.format(Calendar.getInstance().getTime())); } update(); } } }); label = new Label(content, SWT.NONE); from = new Combo(content, SWT.READ_ONLY); from.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false)); from.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { update(); } }); label = new Label(content, SWT.NONE); label.setText(Messages.ExchangeRateDialog_To); to = new Combo(content, SWT.READ_ONLY); to.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, false, false)); to.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { update(); } }); label = new Label(content, SWT.NONE); label.setText(Messages.ExchangeRateDialog_Equals); ratio = new Spinner(content, SWT.BORDER); ratio.setMinimum(1); ratio.setMaximum(999999999); ratio.setDigits(4); ratio.setIncrement(100); List list = CurrencyConverter.getInstance().getCurrencies(); Collections.sort(list, new Comparator() { public int compare(Object arg0, Object arg1) { return ((String) arg0).compareTo((String) arg1); } }); for (Iterator iter = list.iterator(); iter.hasNext();) { String symbol = (String) iter.next(); from.add(symbol); to.add(symbol); } text.setText(dateFormat.format(Calendar.getInstance().getTime())); String locale = Currency.getInstance(Locale.getDefault()).getCurrencyCode(); from.setText(locale.equals(Messages.ExchangeRateDialog_DefaultTo) ? Messages.ExchangeRateDialog_DefaultFrom : Messages.ExchangeRateDialog_DefaultTo); to.setText(locale.equals(Messages.ExchangeRateDialog_DefaultTo) ? Messages.ExchangeRateDialog_DefaultTo : Messages.ExchangeRateDialog_DefaultFrom); update(); return content; }
From source file:biblivre3.administration.reports.BaseBiblivreReport.java
private String getFileName(ReportsDTO dto) { final String reportName = dto.getType().getName(); final Calendar c = Calendar.getInstance(); final int dia = c.get(Calendar.DATE); final int mes = c.get(Calendar.MONTH) + 1; final int hora = c.get(Calendar.HOUR_OF_DAY); final int minuto = c.get(Calendar.MINUTE); return reportName + dia + mes + hora + minuto + ".pdf"; }
From source file:com.pm.myshop.controller.OrderController.java
@RequestMapping(value = "/checkout/guest", method = RequestMethod.POST) public String checkoutGuestPost(@Valid @ModelAttribute("customer") Customer customer, BindingResult result, Model model) throws IOException { if (result.hasErrors()) return "checkoutGuest"; Cart cart = (Cart) session.getAttribute("cart"); if (!"success".equals(authenticateCard(customer.getAccount().getCardNumber(), cart.getGrandTotal(), customer.getAccount().getCardCvv()))) { session.setAttribute("cardError", "Card Not Valid or Insufficient Fund"); return "checkoutGuest"; }//w w w .j a va2 s.c om Orders order = new Orders(); order.setCustomer(customer); order.setCart(cart); order.setShipping(customer.getAddress()); Date date = new Date(); order.setOrderDate(date); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.DATE, 7); date = cal.getTime(); order.setShippingDate(date); // orderService.saveOrder(order); model.addAttribute("order", order); return "order"; }
From source file:axiom.util.Logging.java
/** * Returns the timestamp for the next Midnight * * @return next midnight timestamp in milliseconds *//*from w ww . j av a 2s . co m*/ static long nextMidnight() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DATE, 1 + cal.get(Calendar.DATE)); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 1); // for testing, rotate the logs every minute: // cal.set (Calendar.MINUTE, 1 + cal.get(Calendar.MINUTE)); return cal.getTime().getTime(); }
From source file:gov.nih.nci.cabig.caaers.utils.DateUtils.java
/** * Compares two dates. The time fields are ignored. * // ww w. j a v a 2 s. com * @param d1 - * Date 1 * @param d2 - * Date 2 * @return 0 if same, -1 if d1 is less than d2. */ public static int compareDate(Date d1, Date d2) { if (d1 == null && d2 == null) return 0; if (d1 == null && d2 != null) return -1; if (d1 != null && d2 == null) return 1; Calendar c1 = Calendar.getInstance(); c1.setTime(d1); Calendar c2 = Calendar.getInstance(); c2.setTime(d2); int x = c1.get(Calendar.YEAR); int y = c2.get(Calendar.YEAR); if (x != y) return x - y; x = c1.get(Calendar.MONTH); y = c2.get(Calendar.MONTH); if (x != y) return x - y; x = c1.get(Calendar.DATE); y = c2.get(Calendar.DATE); return x - y; }
From source file:net.sf.statcvs.output.xml.chart.ModuleActivityChart.java
private ContourDataset createDataset() { List dirs = content.getDirectories(); List dateList = new ArrayList(); Date firstDate = content.getFirstDate(); Date lastDate = content.getLastDate(); Calendar cal = new GregorianCalendar(); cal.setTime(firstDate);/*from w ww . j av a2 s . c o m*/ while (cal.getTime().before(lastDate)) { dateList.add(cal.getTime()); cal.add(Calendar.DATE, 1); } dateList.add(lastDate); Double[][] values = new Double[dateList.size()][dirs.size()]; for (int i = 0; i < dateList.size(); i++) { Iterator dirsIt = dirs.iterator(); IntegerMap changesMap = new IntegerMap(); while (dirsIt.hasNext()) { Directory dir = (Directory) dirsIt.next(); RevisionIterator revIt = new RevisionSortIterator(dir.getRevisionIterator()); while (revIt.hasNext()) { CvsRevision rev = revIt.next(); Date revDate = rev.getDate(); Date currDate = (Date) dateList.get(i); Date nextDate = null; if (i < dateList.size() - 1) { nextDate = (Date) dateList.get(i + 1); } if (revDate.equals(currDate) || (revDate.after(currDate) && revDate.before(nextDate))) { changesMap.inc(dir); } } } Iterator cIt = changesMap.iteratorSortedByKey(); while (cIt.hasNext()) { Directory dir = (Directory) cIt.next(); int dirIndex = dirs.indexOf(dir); //values[i][dirIndex] = new Double(changesMap.getPercent(dir)); values[i][dirIndex] = new Double(changesMap.getPercentOfMaximum(dir)); } } int numValues = dateList.size() * dirs.size(); Date[] oDateX = new Date[numValues]; Double[] oDoubleY = new Double[numValues]; Double[] oDoubleZ = new Double[numValues]; for (int x = 0; x < dateList.size(); x++) { for (int y = 0; y < dirs.size(); y++) { int index = (x * dirs.size()) + y; oDateX[index] = (Date) dateList.get(x); oDoubleY[index] = new Double(y); if ((values[x][y] != null) && ((values[x][y].isNaN()) || (values[x][y].equals(new Double(0))))) { values[x][y] = null; } oDoubleZ[index] = values[x][y]; } } oDoubleZ[0] = new Double(0.0); return new DefaultContourDataset(getTitle(), oDateX, oDoubleY, oDoubleZ); }
From source file:org.openmrs.module.facilitydata.web.controller.FacilityDataCompletionAnalysisFormController.java
@RequestMapping("/module/facilitydata/completionAnalysis.form") public void viewForm(ModelMap map, HttpServletRequest request, @ModelAttribute("query") FacilityDataQuery query) { FacilityDataService fds = Context.getService(FacilityDataService.class); if (query.getSchema() != null) { Date validFrom = query.getSchema().getValidFrom(); if (query.getFromDate() != null && validFrom != null && query.getFromDate().before(validFrom)) { query.setFromDate(validFrom); }/*from w w w.jav a 2s . co m*/ if (query.getFromDate() == null) { Date minEntryDate = fds.getMinEnteredStartDateForSchema(query.getSchema()); if (minEntryDate == null) { minEntryDate = new Date(); } query.setFromDate(minEntryDate); } Date validTo = query.getSchema().getValidTo(); if (query.getToDate() != null && validTo != null && query.getToDate().after(validTo)) { query.setToDate(validTo); } if (query.getToDate() == null) { query.setToDate(new Date()); } Calendar cal = Calendar.getInstance(); Frequency frequency = query.getSchema().getForm().getFrequency(); if (frequency == Frequency.MONTHLY) { cal.setTime(query.getFromDate()); if (cal.get(Calendar.DATE) > 1) { cal.set(Calendar.DATE, 1); query.setFromDate(cal.getTime()); } cal.setTime(query.getToDate()); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); query.setToDate(cal.getTime()); } int numExpected = 0; List<Integer> daysOfWeek = FacilityDataConstants.getDailyReportDaysOfWeek(); Map<FacilityDataFormQuestion, Integer> numValuesByQuestion = new LinkedHashMap<FacilityDataFormQuestion, Integer>(); Map<FacilityDataFormQuestion, Double> numericTotals = new HashMap<FacilityDataFormQuestion, Double>(); Map<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>> codedTotals = new HashMap<FacilityDataFormQuestion, Map<FacilityDataCodedOption, Integer>>(); cal.setTime(query.getFromDate()); while (cal.getTime().compareTo(query.getToDate()) <= 0) { if (frequency != Frequency.DAILY || daysOfWeek.contains(cal.get(Calendar.DAY_OF_WEEK))) { numExpected++; } cal.add(frequency.getCalendarField(), frequency.getCalendarIncrement()); } List<FacilityDataValue> values = fds.evaluateFacilityDataQuery(query); Map<FacilityDataFormQuestion, Map<Location, FacilityDataValue>> latestValuesForQuestion = new HashMap<FacilityDataFormQuestion, Map<Location, FacilityDataValue>>(); for (FacilityDataValue v : values) { Integer numValues = numValuesByQuestion.get(v.getQuestion()); numValuesByQuestion.put(v.getQuestion(), numValues == null ? 1 : numValues + 1); FacilityDataQuestionType type = v.getQuestion().getQuestion().getQuestionType(); if (type instanceof CodedFacilityDataQuestionType) { Map<FacilityDataCodedOption, Integer> m = codedTotals.get(v.getQuestion()); if (m == null) { m = new HashMap<FacilityDataCodedOption, Integer>(); codedTotals.put(v.getQuestion(), m); } Integer num = m.get(v.getValueCoded()); num = num == null ? 1 : num + 1; m.put(v.getValueCoded(), num); } else { PeriodApplicability pa = v.getQuestion().getQuestion().getPeriodApplicability(); if (pa == PeriodApplicability.DURING_PERIOD) { Double num = numericTotals.get(v.getQuestion()); if (num == null) { num = new Double(0); } num += v.getValueNumeric(); numericTotals.put(v.getQuestion(), num); } else { Map<Location, FacilityDataValue> valueForQuestion = latestValuesForQuestion .get(v.getQuestion()); if (valueForQuestion == null) { valueForQuestion = new HashMap<Location, FacilityDataValue>(); latestValuesForQuestion.put(v.getQuestion(), valueForQuestion); } FacilityDataValue valueForLocation = valueForQuestion.get(v.getFacility()); if (valueForLocation == null || valueForLocation.getToDate().before(v.getToDate())) { valueForQuestion.put(v.getFacility(), v); } } } } if (!latestValuesForQuestion.isEmpty()) { for (FacilityDataFormSection section : query.getSchema().getSections()) { for (FacilityDataFormQuestion question : section.getQuestions()) { Double d = new Double(0); Map<Location, FacilityDataValue> m = latestValuesForQuestion.get(question); if (m != null) { for (FacilityDataValue v : m.values()) { if (v != null) { d += v.getValueNumeric(); } } numericTotals.put(question, d); } } } } if (query.getFacility() == null) { numExpected = numExpected * getLocations().size(); } else { Set<Location> allFacilities = FacilityDataUtil.getAllLocationsInHierarchy(query.getFacility()); List<Location> supportedFacilities = FacilityDataConstants.getSupportedFacilities(); allFacilities.retainAll(supportedFacilities); numExpected = numExpected * allFacilities.size(); } map.addAttribute("numExpected", numExpected); map.addAttribute("numValuesByQuestion", numValuesByQuestion); map.addAttribute("numericTotals", numericTotals); map.addAttribute("codedTotals", codedTotals); } }
From source file:org.jasig.schedassist.web.owner.statistics.VisitorHistoryFormController.java
/** * //from ww w. j av a 2 s . c o m * @return */ @RequestMapping(method = RequestMethod.GET) protected String setupForm( @RequestParam(value = "noscript", required = false, defaultValue = "false") boolean noscript, final ModelMap model) { VisitorHistoryFormBackingObject fbo = new VisitorHistoryFormBackingObject(); Date today = new Date(); Date sevenDaysAgo = DateUtils.addDays(today, -7); // truncate sevenDaysAgo to midnight sevenDaysAgo = DateUtils.truncate(sevenDaysAgo, Calendar.DATE); fbo.setStartTime(sevenDaysAgo); fbo.setEndTime(today); model.addAttribute("command", fbo); if (noscript) { return "statistics/visitor-history-form-noscript"; } else { return "statistics/visitor-history-form"; } }
From source file:cn.mljia.common.notify.utils.DateUtils.java
/** * ???/* ww w.jav a2 s . co m*/ * * @param date * 1 * @param otherDate * 2 * @param withUnit * ??Calendar field? * @return 0, 0 ??0 */ public static int compareDate(Date date, Date otherDate, int withUnit) { Calendar dateCal = Calendar.getInstance(); dateCal.setTime(date); Calendar otherDateCal = Calendar.getInstance(); otherDateCal.setTime(otherDate); switch (withUnit) { case Calendar.YEAR: dateCal.clear(Calendar.MONTH); otherDateCal.clear(Calendar.MONTH); case Calendar.MONTH: dateCal.set(Calendar.DATE, 1); otherDateCal.set(Calendar.DATE, 1); case Calendar.DATE: dateCal.set(Calendar.HOUR_OF_DAY, 0); otherDateCal.set(Calendar.HOUR_OF_DAY, 0); case Calendar.HOUR: dateCal.clear(Calendar.MINUTE); otherDateCal.clear(Calendar.MINUTE); case Calendar.MINUTE: dateCal.clear(Calendar.SECOND); otherDateCal.clear(Calendar.SECOND); case Calendar.SECOND: dateCal.clear(Calendar.MILLISECOND); otherDateCal.clear(Calendar.MILLISECOND); case Calendar.MILLISECOND: break; default: throw new IllegalArgumentException("withUnit ?? " + withUnit + " ????"); } return dateCal.compareTo(otherDateCal); }