List of usage examples for java.util Date getYear
@Deprecated public int getYear()
From source file:org.ms123.common.data.query.JPASelectBuilderPostgresql.java
protected Object getDate(Object data, Map<String, Object> rule) { try {// w w w . j a v a 2 s .c o m Date d = new Date(); try { if (data instanceof Long) { d = new Date((Long) data); } else { d = new Date(Long.valueOf((String) rule.get("data"))); } } catch (Exception e) { try { if (data instanceof String) { d = new SimpleDateFormat( (((String) data).indexOf("T") > 0) ? "yyyy-MM-dd'T'HH:mm" : "yyyy-MM-dd") .parse((String) data, new ParsePosition(0)); if (d == null) d = new Date(); } } catch (Exception e1) { System.out.println("E:" + e); } } String op = (String) rule.get("op"); if (op.equals("eq") || op.equals("ceq") || op.equals("neq")) { String day = d.getDate() + ""; String month = d.getMonth() + ""; String year = (d.getYear() + 1900) + ""; data = day + "/" + month + "/" + year; } else if (op.equals("in") || op.equals("inn")) { } else { int paramCount = m_queryBuilder.getParamCount(); data = ":param" + paramCount; System.out.println("param" + paramCount + ":" + d); m_queryBuilder.getQueryParams().put("param" + paramCount, d); m_queryBuilder.incParamCount(); } } catch (Exception e) { e.printStackTrace(); data = "''"; } return data; }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java
public void testLoadTable1() throws Exception { IPentahoSession session = new StandaloneSession("test"); KettleSystemListener.environmentInit(session); ModelInfo info = createModel();//from www . ja v a 2 s . c o m CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta()); // create the model String tableName = info.getStageTableName(); try { gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null); } catch (CsvTransformGeneratorException e) { // table might not be there yet, it is OK } // generate the database table gen.createOrModifyTable(session); // load the table loadTable(gen, info, true, session); // check the results long rowCount = this.getRowCount(tableName); assertEquals((long) 235, rowCount); DatabaseMeta databaseMeta = getDatabaseMeta(); assertNotNull(databaseMeta); Database database = new Database(databaseMeta); assertNotNull(database); database.connect(); Connection connection = null; Statement stmt = null; ResultSet sqlResult = null; try { connection = database.getConnection(); assertNotNull(connection); stmt = database.getConnection().createStatement(); // check the first row Date testDate = new Date(); testDate.setDate(1); testDate.setHours(0); testDate.setMinutes(0); testDate.setMonth(0); testDate.setSeconds(0); testDate.setYear(110); boolean ok = stmt.execute("select * from " + tableName); assertTrue(ok); sqlResult = stmt.getResultSet(); assertNotNull(sqlResult); ok = sqlResult.next(); assertTrue(ok); // test the values assertEquals((long) 3, sqlResult.getLong(1)); assertEquals(25677.96525, sqlResult.getDouble(2)); assertEquals((long) 1231, sqlResult.getLong(3)); assertEquals(testDate.getYear(), sqlResult.getDate(4).getYear()); assertEquals(testDate.getMonth(), sqlResult.getDate(4).getMonth()); assertEquals(testDate.getDate(), sqlResult.getDate(4).getDate()); assertEquals(testDate.getHours(), sqlResult.getTime(4).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), sqlResult.getTime(4).getSeconds()); // assertEquals( testDate, cells[3] ); assertEquals("Afghanistan", sqlResult.getString(5)); assertEquals((long) 11, sqlResult.getLong(6)); assertEquals(111.9090909, sqlResult.getDouble(7)); assertEquals(false, sqlResult.getBoolean(8)); } finally { sqlResult.close(); stmt.close(); connection.close(); } }
From source file:com.edgenius.wiki.ext.calendar.service.CalendarServiceImpl.java
/** * Check if this repeat event appear in given period. * @param event//from ww w .j av a 2 s . com * @param start * @param end */ @SuppressWarnings("deprecation") private List<CalendarEvent> getRepeatEventsInPeriod(CalendarEvent event, Date start, Date end) { String rule = event.getRepeatRule(); if (StringUtils.isBlank(rule)) return null; //if first event is after scope, then return null if (event.getStart().after(end)) return null; String[] parts = rule.split(","); if (parts.length != 5) { return null; } if (parts[4].length() != 0) { //if end is early than start, then simple return null. try { Date rEnd = ruleDateParser.parse(parts[4]); if (rEnd.before(start)) return null; } catch (ParseException e) { log.error("Unable to parse end date of event " + event.getUid()); } } //parse and calculate according to type, repeat and step int step = NumberUtils.toInt(parts[2]) + 1; List<Date[]> candidates = new ArrayList<Date[]>(); Date evtS = event.getStart(); Date evtE = event.getEnd(); Date candidateS; Date candidateE; if ("yearly".equals(parts[0])) { if ((start.getYear() - evtS.getYear()) % step == 0) { int idx = start.getYear(); do { } while (idx <= end.getYear()); } } else if ("monthly".equals(parts[0])) { } else if ("weekly".equals(parts[0])) { } else if ("daily".equals(parts[0])) { } return null; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.impl.DeIdentifiedExportServiceImpl.java
private List<Encounter> randomizeEncounterDates(List<Obs> patientObsList) { Integer flag = 0;//from w ww .jav a2 s .c o m List<Date> randomizedEncounterDateList = new ArrayList<Date>(); List<Encounter> en = new ArrayList<Encounter>(); for (Obs o : patientObsList) { en.add(o.getEncounter()); } int year, month, date; try { for (int i = 0; i < patientObsList.size(); i++) { Date d = new Date(); if (flag == 0) { d.setDate(en.get(0).getEncounterDatetime().getDate()); d.setMonth(en.get(0).getEncounterDatetime().getMonth()); d.setYear(en.get(0).getEncounterDatetime().getYear()); flag = 1; } else { d.setDate(en.get(i - 1).getEncounterDatetime().getDate()); d.setMonth(en.get(i - 1).getEncounterDatetime().getMonth()); d.setYear(en.get(i - 1).getEncounterDatetime().getYear()); } year = d.getYear() + 1900; month = d.getMonth(); date = d.getDate(); //Randomize year = randBetween(year + 1, year + 2); month = randBetween(month, 12); date = randBetween(date, 30); //Set date d.setYear(year - 1900); d.setMonth(month); d.setDate(date); en.get(i).setEncounterDatetime(d); randomizedEncounterDateList.add(d); } } catch (APIException e) { log.error("Exception in randomizing encounter dates", e); } return en; }
From source file:com.ridgelineapps.wallpaper.photosite.FlickrUtils.java
String formatDate(Date date) { date = new Date(date.getTime() - (1000 * 60 * 60 * 24)); String year = "" + (date.getYear() + 1900); String month = "" + (date.getMonth() + 1); String day = "" + (date.getDate()); if (month.length() < 2) { month = "0" + month; }/*from w ww.j av a2s . com*/ if (day.length() < 2) { day = "0" + day; } return year + "-" + month + "-" + day; }
From source file:com.krawler.esp.servlets.importProjectPlanCSV.java
public String getActualDuration(Date stdate, Date enddate, int[] NonWorkDays, String[] holidays) { int noofdays = 0; java.text.SimpleDateFormat sdf1 = new java.text.SimpleDateFormat("yyyy-MM-dd"); try {//from w w w . j a va 2 s . co m Calendar c1 = Calendar.getInstance(); while (stdate.compareTo(enddate) < 0) { if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0 && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) { noofdays++; } c1.set(stdate.getYear() + 1900, stdate.getMonth(), stdate.getDate()); c1.add(Calendar.DATE, 1); stdate = sdf1.parse(sdf1.format(c1.getTime())); } if (stdate.compareTo(enddate) == 0) { if (Arrays.binarySearch(NonWorkDays, stdate.getDay()) < 0 && Arrays.binarySearch(holidays, sdf1.format(stdate)) < 0) { noofdays++; } } } catch (ParseException ex) { Logger.getLogger(importProjectPlanCSV.class.getName()).log(Level.SEVERE, null, ex); } return noofdays + "d"; }
From source file:com.homeworkreminder.Main.java
@SuppressWarnings("deprecation") private static boolean initInfoListForDate(Date date) { // TODO Auto-generated method stub // find the corresponding list<Task> in the hashmap // give this list to the listview Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, date.getYear() + 1900); c.set(Calendar.MONTH, date.getMonth()); c.set(Calendar.DAY_OF_MONTH, date.getDate()); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0);// w w w .j ava2 s. c om c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); List<Task> l = TaskMap.get(c); if (l == null) { tv_calendar_notaskfordate.setVisibility(View.VISIBLE); List<Task> i = new ArrayList<Task>(); info_adapter = new InfoListAdapter(context, R.layout.calendar_info_single_row, i); info_list.setAdapter(info_adapter); info_list.setVisibility(View.GONE); return false; } else { if (!l.isEmpty()) { info_list.setVisibility(View.VISIBLE); tv_calendar_notaskfordate.setVisibility(View.GONE); info_adapter = new InfoListAdapter(context, R.layout.calendar_info_single_row, l); info_list.setAdapter(info_adapter); info_list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub Intent intent = new Intent(context, EditTask.class); Bundle b = new Bundle(); b.putInt("id", info_adapter.getId(position)); intent.putExtra("info", b); context.startActivity(intent); } }); return true; } else { info_list.setVisibility(View.GONE); tv_calendar_notaskfordate.setVisibility(View.VISIBLE); return false; } } }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorTest.java
public void testGoodTransform() throws Exception { IPentahoSession session = new StandaloneSession("test"); KettleSystemListener.environmentInit(session); ModelInfo info = createModel();//from w w w . j av a 2 s.c o m CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta()); gen.preview(session); DataRow rows[] = info.getData(); assertNotNull(rows); assertEquals(235, rows.length); Date testDate = new Date(); testDate.setDate(1); testDate.setHours(0); testDate.setMinutes(0); testDate.setMonth(0); testDate.setSeconds(0); testDate.setYear(110); // test the first row // test the data types DataRow row = rows[0]; assertNotNull(row); Object cells[] = row.getCells(); assertNotNull(cells); // assertEquals( 8, cells.length ); assertTrue(cells[0] instanceof Long); assertTrue(cells[1] instanceof Double); assertTrue(cells[2] instanceof Long); assertTrue(cells[3] instanceof Date); assertTrue(cells[4] instanceof String); assertTrue(cells[5] instanceof Long); assertTrue(cells[6] instanceof Double); assertTrue(cells[7] instanceof Boolean); // test the values assertEquals((long) 3, cells[0]); assertEquals(25677.96525, cells[1]); assertEquals((long) 1231, cells[2]); assertEquals(testDate.getYear(), ((Date) cells[3]).getYear()); assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth()); assertEquals(testDate.getDate(), ((Date) cells[3]).getDate()); assertEquals(testDate.getHours(), ((Date) cells[3]).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds()); // assertEquals( testDate, cells[3] ); assertEquals("Afghanistan", cells[4]); assertEquals((long) 11, cells[5]); assertEquals(111.9090909, cells[6]); assertEquals(false, cells[7]); // test the second row testDate.setDate(2); // test the data types row = rows[1]; assertNotNull(row); cells = row.getCells(); assertNotNull(cells); assertTrue(cells[0] instanceof Long); assertTrue(cells[1] instanceof Double); assertTrue(cells[2] instanceof Long); assertTrue(cells[3] instanceof Date); assertTrue(cells[4] == null); assertTrue(cells[5] instanceof Long); assertTrue(cells[6] instanceof Double); assertTrue(cells[7] instanceof Boolean); // test the values assertEquals((long) 4, cells[0]); assertEquals(24261.81026, cells[1]); assertEquals((long) 1663, cells[2]); assertEquals(testDate.getYear(), ((Date) cells[3]).getYear()); assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth()); assertEquals(testDate.getDate(), ((Date) cells[3]).getDate()); assertEquals(testDate.getHours(), ((Date) cells[3]).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds()); // assertEquals( testDate, cells[3] ); assertEquals(null, cells[4]); // IfNull value does not seem to work assertEquals((long) 7, cells[5]); assertEquals(237.5714286, cells[6]); assertEquals(true, cells[7]); }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java
public void testGoodTransform() throws Exception { IPentahoSession session = new StandaloneSession("test"); KettleSystemListener.environmentInit(session); String KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL = System.getProperty("KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL", "N"); ModelInfo info = createModel();//from ww w .j av a2s .c o m CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta()); gen.preview(session); DataRow rows[] = info.getData(); assertNotNull(rows); assertEquals(235, rows.length); Date testDate = new Date(); testDate.setDate(1); testDate.setHours(0); testDate.setMinutes(0); testDate.setMonth(0); testDate.setSeconds(0); testDate.setYear(110); // test the first row // test the data types DataRow row = rows[0]; assertNotNull(row); Object cells[] = row.getCells(); assertNotNull(cells); // assertEquals( 8, cells.length ); assertTrue(cells[0] instanceof Long); assertTrue(cells[1] instanceof Double); assertTrue(cells[2] instanceof Long); assertTrue(cells[3] instanceof Date); assertTrue(cells[4] instanceof String); assertTrue(cells[5] instanceof Long); assertTrue(cells[6] instanceof Double); assertTrue(cells[7] instanceof Boolean); // test the values assertEquals((long) 3, cells[0]); assertEquals(25677.96525, cells[1]); assertEquals((long) 1231, cells[2]); assertEquals(testDate.getYear(), ((Date) cells[3]).getYear()); assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth()); assertEquals(testDate.getDate(), ((Date) cells[3]).getDate()); assertEquals(testDate.getHours(), ((Date) cells[3]).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds()); // assertEquals( testDate, cells[3] ); assertEquals("Afghanistan", cells[4]); assertEquals((long) 11, cells[5]); assertEquals(111.9090909, cells[6]); assertEquals(false, cells[7]); // test the second row testDate.setDate(2); // test the data types row = rows[1]; assertNotNull(row); cells = row.getCells(); assertNotNull(cells); assertTrue(cells[0] instanceof Long); assertTrue(cells[1] instanceof Double); assertTrue(cells[2] instanceof Long); assertTrue(cells[3] instanceof Date); if ("Y".equals(KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL)) { assertTrue("".equals(cells[4])); } else { assertTrue(cells[4] == null); } assertTrue(cells[5] instanceof Long); assertTrue(cells[6] instanceof Double); assertTrue(cells[7] instanceof Boolean); // test the values assertEquals((long) 4, cells[0]); assertEquals(24261.81026, cells[1]); assertEquals((long) 1663, cells[2]); assertEquals(testDate.getYear(), ((Date) cells[3]).getYear()); assertEquals(testDate.getMonth(), ((Date) cells[3]).getMonth()); assertEquals(testDate.getDate(), ((Date) cells[3]).getDate()); assertEquals(testDate.getHours(), ((Date) cells[3]).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), ((Date) cells[3]).getSeconds()); // assertEquals( testDate, cells[3] ); if ("Y".equals(KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL)) { assertEquals("", cells[4]); assertEquals(cells[4], ""); } else { assertEquals(null, cells[4]); // IfNull value does not seem to work } assertEquals((long) 7, cells[5]); assertEquals(237.5714286, cells[6]); assertEquals(true, cells[7]); }
From source file:beproject.MainGUI.java
private void scheduleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_scheduleButtonActionPerformed String movieName = movieNameTextField.getText(), releaseDate = releaseDateTextField.getText(), theatre = theatreTextField.getText(); int t;// www . j av a 2 s . c om boolean isSequel = isSequelYesRadioButton.isSelected(); if (movieName.equals("") || theatre.equals("")) { JOptionPane.showMessageDialog(null, "Fields cannot be left blank"); return; } try { t = Integer.parseInt(theatre); } catch (NumberFormatException e) { JOptionPane.showMessageDialog(null, "Invalid theatre count."); return; } //TODO DATABASE CHECK if (movieName.length() >= 30) { JOptionPane.showMessageDialog(null, "Movie name length too large."); return; } if (movieName.contains("'") || movieName.contains("\"")) { JOptionPane.showMessageDialog(null, "Movie name cannot contain special characters"); return; } try { //java.util.Date d1=new java.util.Date(); DateFormat format = new SimpleDateFormat("DD-MM-YYYY"); Date date = format.parse(releaseDate); if (date.getYear() > 199) { releaseDate = ""; } } catch (ParseException e) { releaseDate = ""; } if (releaseDate.equals("")) { JOptionPane.showMessageDialog(null, "Invalid release date."); return; } String tmp = "insert into movienames values ('" + movieName + "', STR_TO_DATE('" + releaseDate + "','%d-%m-%Y'), " + isSequel + ", " + t + ")"; String tmp1 = "insert into category values('" + movieName + "'," + cat1CheckBox.isSelected() + "," + cat2CheckBox.isSelected() + "," + cat3CheckBox.isSelected() + "," + cat4CheckBox.isSelected() + "," + cat5CheckBox.isSelected() + ")"; try { stmt.execute(tmp); stmt.execute(tmp1); for (String i : actorList) { stmt.execute("insert into movieactorassoc values('" + movieName + "', '" + i + "')"); } } catch (SQLException e) { ExceptionManager.handleException(e, ""); } actorList.clear(); JOptionPane.showMessageDialog(null, "Scheduled"); movieNameTextField.setText(""); releaseDateTextField.setText(""); actorNameTextField.setText(""); actorTwitterHandleTextField.setText(""); for (Object i : jPanel1.getComponents()) { if (i instanceof JCheckBox) { ((JCheckBox) i).setSelected(false); } } }