List of usage examples for java.sql Date getYear
@Deprecated public int getYear()
From source file:History.PieChart_DB.java
public static void main(String[] args) throws Exception { String mobilebrands[] = { "IPhone 5s", "SamSung Grand", "MotoG", "Nokia Lumia" }; int statOfRepair = 0; java.util.Date now = new java.util.Date(); String adminDate = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate(); /* Create MySQL Database Connection */ Class.forName("com.mysql.jdbc.Driver"); Connection connect = ConnectDatabase.connectDb("win", "win016"); Statement statement = connect.createStatement(); ResultSet resultSet = statement .executeQuery("SELECT COUNT(transID) AS statRepair FROM `Transaction` WHERE dateTime LIKE \'" + adminDate + "%\' AND action LIKE 'Repair'"); DefaultPieDataset dataset = new DefaultPieDataset(); while (resultSet.next()) { dataset.setValue(resultSet.getString("statRepair"), Double.parseDouble(resultSet.getString("unit_sale"))); }// w w w .ja v a 2 s. c o m JFreeChart chart = ChartFactory.createPieChart("History", // chart title dataset, // data true, // include legend true, false); int width = 560; /* Width of the image */ int height = 370; /* Height of the image */ File pieChart = new File("Pie_Chart.jpeg"); ChartUtilities.saveChartAsJPEG(pieChart, chart, width, height); }
From source file:Main.java
public static String formatTimeAgo(long time) { long diff = System.currentTimeMillis() - time; long day = diff / DAY; if (day > 0) { if (day > 5) { Date date = new Date(time); if (date.getYear() != Calendar.getInstance().getTime().getYear()) { return FULL_FORMAT.format(date); } else { return FORMAT.format(date); }/*from www .ja v a 2 s . c om*/ } else { return day + (day == 1 ? " day ago" : " days ago"); } } long hour = diff / HOUR; if (hour > 0) { return hour + (hour == 1 ? " hour ago" : " hours ago"); } long minute = diff / MINUTE; if (minute > 0) { return minute + (minute == 1 ? " minute ago" : " minutes ago"); } return "Just now"; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Creates a table cell from the value in the current row of the given result * set and the given column index. The type of the value is determined by the * given value type.//w ww. j ava 2 s . c o m * * @param rs The result set holding the data from the sql table. The result * points to the current row. * @param valueType The value type of the column that the cell belongs to. * @param column The column index. Indexes are 0-based. * * @return The table cell. * * @throws SQLException Thrown when the connection to the database failed. */ private static TableCell buildTableCell(ResultSet rs, ValueType valueType, int column) throws SQLException { Value value = null; // SQL indexes are 1- based. column = column + 1; switch (valueType) { case BOOLEAN: value = BooleanValue.getInstance(rs.getBoolean(column)); break; case NUMBER: value = new NumberValue(rs.getDouble(column)); break; case DATE: Date date = rs.getDate(column); // If date is null it is handled later. if (date != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the year, month and date in the gregorian calendar. // Use the 'set' method with those parameters, and not the 'setTime' // method with the date parameter, since the Date object contains the // current time zone and it's impossible to change it to 'GMT'. gc.set(date.getYear() + 1900, date.getMonth(), date.getDate()); value = new DateValue(gc); } break; case DATETIME: Timestamp timestamp = rs.getTimestamp(column); // If timestamp is null it is handled later. if (timestamp != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the year, month, date, hours, minutes and seconds in the // gregorian calendar. Use the 'set' method with those parameters, // and not the 'setTime' method with the timestamp parameter, since // the Timestamp object contains the current time zone and it's // impossible to change it to 'GMT'. gc.set(timestamp.getYear() + 1900, timestamp.getMonth(), timestamp.getDate(), timestamp.getHours(), timestamp.getMinutes(), timestamp.getSeconds()); // Set the milliseconds explicitly, as they are not saved in the // underlying date. gc.set(Calendar.MILLISECOND, timestamp.getNanos() / 1000000); value = new DateTimeValue(gc); } break; case TIMEOFDAY: Time time = rs.getTime(column); // If time is null it is handled later. if (time != null) { GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT")); // Set the hours, minutes and seconds of the time in the gregorian // calendar. Set the year, month and date to be January 1 1970 like // in the Time object. // Use the 'set' method with those parameters, // and not the 'setTime' method with the time parameter, since // the Time object contains the current time zone and it's // impossible to change it to 'GMT'. gc.set(1970, Calendar.JANUARY, 1, time.getHours(), time.getMinutes(), time.getSeconds()); // Set the milliseconds explicitly, otherwise the milliseconds from // the time the gc was initialized are used. gc.set(GregorianCalendar.MILLISECOND, 0); value = new TimeOfDayValue(gc); } break; default: String colValue = rs.getString(column); if (colValue == null) { value = TextValue.getNullValue(); } else { value = new TextValue(rs.getString(column)); } break; } // Handle null values. if (rs.wasNull()) { return new TableCell(Value.getNullValueFromValueType(valueType)); } else { return new TableCell(value); } }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
/** * Returns the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. * @param date Date to convert to ordinal, since 01/01/01 * @return The ordinal representing the date *//*from w w w . j a va2s .com*/ public static int dateToOrdinal(Date date) { // BigDate.toOrdinal returns the ordinal since 1970, so we add up the days from 01/01/01 to 1970 return BigDate.toOrdinal(date.getYear() + 1900, date.getMonth() + 1, date.getDate()) + DAYS_BEFORE_1970; }
From source file:org.kuali.kra.subaward.service.impl.SubAwardServiceImpl.java
@Override public String getCalculatedFollowupDateForAjaxCall(String baseDate) { final String empty = ""; String[] elements = baseDate.split("/"); if (elements.length == 3) { try {/*from w w w . j a v a2s . com*/ int month = Integer.parseInt(elements[0]); int day = Integer.parseInt(elements[1]); int year = Integer.parseInt(elements[2]); if (year < 100) { year = year + 2000; } Date requestedDate = new Date(year, month - 1, day - 1); Date followUpDate = getCalculatedFollowupDate(requestedDate); return (followUpDate.getMonth() + 1) + "/" + (followUpDate.getDate() + 1) + "/" + followUpDate.getYear(); } catch (Exception e) { LOG.error(e.getMessage(), e); } } return empty; }
From source file:org.apache.tajo.storage.jdbc.JdbcScanner.java
protected void convertTuple(ResultSet resultSet, VTuple tuple) { try {//from w w w. j a v a2 s . c om for (int column_idx = 0; column_idx < targets.length; column_idx++) { final Column c = targets[column_idx]; final int resultIdx = column_idx + 1; switch (c.getDataType().getType()) { case INT1: case INT2: tuple.put(column_idx, DatumFactory.createInt2(resultSet.getShort(resultIdx))); break; case INT4: tuple.put(column_idx, DatumFactory.createInt4(resultSet.getInt(resultIdx))); break; case INT8: tuple.put(column_idx, DatumFactory.createInt8(resultSet.getLong(resultIdx))); break; case FLOAT4: tuple.put(column_idx, DatumFactory.createFloat4(resultSet.getFloat(resultIdx))); break; case FLOAT8: tuple.put(column_idx, DatumFactory.createFloat8(resultSet.getDouble(resultIdx))); break; case CHAR: tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx))); break; case VARCHAR: case TEXT: // TODO - trim is unnecessary in many cases, so we can use it for certain cases tuple.put(column_idx, DatumFactory.createText(resultSet.getString(resultIdx).trim())); break; case DATE: final Date date = resultSet.getDate(resultIdx); tuple.put(column_idx, DatumFactory.createDate(1900 + date.getYear(), 1 + date.getMonth(), date.getDate())); break; case TIME: final Time time = resultSet.getTime(resultIdx); tuple.put(column_idx, new TimeDatum( DateTimeUtil.toTime(time.getHours(), time.getMinutes(), time.getSeconds(), 0))); break; case TIMESTAMP: tuple.put(column_idx, DatumFactory .createTimestampDatumWithJavaMillis(resultSet.getTimestamp(resultIdx).getTime())); break; case BINARY: case VARBINARY: case BLOB: tuple.put(column_idx, DatumFactory.createBlob(resultSet.getBytes(resultIdx))); break; default: throw new TajoInternalError(new UnsupportedDataTypeException(c.getDataType().getType().name())); } } } catch (SQLException s) { throw new TajoInternalError(s); } }
From source file:org.arasthel.almeribus.Principal.java
@Override public void onPostCreate(Bundle savedInstanceState) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); long ultimaActualizacion = sp.getLong("ultima_actualizacion", 0); Date fechaUltima = new Date(ultimaActualizacion); long nuevoTiempo = System.currentTimeMillis(); Date nuevaFecha = new Date(nuevoTiempo); necesitaActualizacion = false;//from www.ja v a2 s . co m if (nuevaFecha.getDay() != fechaUltima.getDay() || nuevaFecha.getMonth() != fechaUltima.getMonth() || nuevaFecha.getYear() != fechaUltima.getYear()) { necesitaActualizacion = true; } // We load the bus stop info from Surbus server cargarParadas(); if (savedInstanceState == null && !necesitaActualizacion && !loaded) { savedInstanceState = new Bundle(); savedInstanceState.putBoolean("SlidingActivityHelper.open", true); } super.onPostCreate(savedInstanceState); }
From source file:edu.arizona.kra.budget.distributionincome.CustomBudgetUnrecoveredFandAAuditRule.java
@SuppressWarnings("rawtypes") @Override/*ww w.ja v a 2 s. co m*/ public boolean processRunAuditBusinessRules(Document document) { Budget budget = ((BudgetDocument) document).getBudget(); if (getAuditErrorMap().containsKey(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY)) { List auditErrors = ((AuditCluster) getAuditErrorMap().get(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY)) .getAuditErrorList(); auditErrors.clear(); } // Returns if unrecovered f and a is not applicable if (!budget.isUnrecoveredFandAApplicable()) { return true; } List<BudgetUnrecoveredFandA> unrecoveredFandAs = budget.getBudgetUnrecoveredFandAs(); boolean retval = true; // Forces full allocation of unrecovered f and a if (budget.getUnallocatedUnrecoveredFandA().isGreaterThan(BudgetDecimal.ZERO) && budget.isUnrecoveredFandAEnforced()) { retval = false; if (unrecoveredFandAs.size() == 0) { getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } for (int i = 0; i < unrecoveredFandAs.size(); i++) { getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].amount", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } } Integer fiscalYear = null; int i = 0; int j = 0; BudgetParent budgetParent = ((BudgetDocument) document).getParentDocument().getBudgetParent(); Date projectStartDate = budgetParent.getRequestedStartDateInitial(); Date projectEndDate = budgetParent.getRequestedEndDateInitial(); // Forces inclusion of source account boolean duplicateEntryFound = false; for (BudgetUnrecoveredFandA unrecoveredFandA : unrecoveredFandAs) { fiscalYear = unrecoveredFandA.getFiscalYear(); if (null == fiscalYear || fiscalYear.intValue() <= 0) { retval = false; getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_FISCALYEAR_MISSING, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } if (fiscalYear != null && (fiscalYear < projectStartDate.getYear() + YEAR_CONSTANT || fiscalYear > projectEndDate.getYear() + YEAR_CONSTANT)) { getAuditWarnings() .add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear", KeyConstants.AUDIT_WARNING_BUDGET_DISTRIBUTION_FISCALYEAR_INCONSISTENT, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } if (!duplicateEntryFound) { j = 0; for (BudgetUnrecoveredFandA unrecoveredFandAForComparison : unrecoveredFandAs) { if (i != j && unrecoveredFandA.getFiscalYear() != null && unrecoveredFandAForComparison.getFiscalYear() != null && unrecoveredFandA.getFiscalYear().intValue() == unrecoveredFandAForComparison .getFiscalYear().intValue() && unrecoveredFandA.getApplicableRate() .equals(unrecoveredFandAForComparison.getApplicableRate()) && unrecoveredFandA.getOnCampusFlag() .equalsIgnoreCase(unrecoveredFandAForComparison.getOnCampusFlag()) && StringUtils.equalsIgnoreCase(unrecoveredFandA.getSourceAccount(), unrecoveredFandAForComparison.getSourceAccount()) && unrecoveredFandA.getAmount().equals(unrecoveredFandAForComparison.getAmount())) { retval = false; getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "]", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_DUPLICATE_UNRECOVERED_FA, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); duplicateEntryFound = true; break; } j++; } } i++; } return retval; }
From source file:org.kuali.kra.budget.distributionincome.BudgetUnrecoveredFandAAuditRule.java
public boolean processRunAuditBusinessRules(Document document) { Budget budget = ((BudgetDocument) document).getBudget(); if (getAuditErrorMap().containsKey(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY)) { List auditErrors = ((AuditCluster) getAuditErrorMap().get(BUDGET_UNRECOVERED_F_AND_A_ERROR_KEY)) .getAuditErrorList();//from w w w .ja v a2s. co m auditErrors.clear(); } // getAuditErrors().clear(); // Returns if unrecovered f and a is not applicable if (!budget.isUnrecoveredFandAApplicable()) { return true; } List<BudgetUnrecoveredFandA> unrecoveredFandAs = budget.getBudgetUnrecoveredFandAs(); boolean retval = true; // Forces full allocation of unrecovered f and a if (budget.getUnallocatedUnrecoveredFandA().isGreaterThan(BudgetDecimal.ZERO) && budget.isUnrecoveredFandAEnforced()) { retval = false; if (unrecoveredFandAs.size() == 0) { getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } for (int i = 0; i < unrecoveredFandAs.size(); i++) { getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].amount", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_UNALLOCATED_NOT_ZERO, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } } String source = null; Integer fiscalYear = null; int i = 0; int j = 0; BudgetParent budgetParent = budget.getBudgetDocument().getParentDocument().getBudgetParent(); Date projectStartDate = budgetParent.getRequestedStartDateInitial(); Date projectEndDate = budgetParent.getRequestedEndDateInitial(); // Forces inclusion of source account boolean duplicateEntryFound = false; for (BudgetUnrecoveredFandA unrecoveredFandA : unrecoveredFandAs) { source = unrecoveredFandA.getSourceAccount(); fiscalYear = unrecoveredFandA.getFiscalYear(); if (null == source || source.length() == 0) { retval = false; getAuditErrors() .add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].sourceAccount", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_SOURCE_MISSING, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } if (null == fiscalYear || fiscalYear.intValue() <= 0) { retval = false; getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_FISCALYEAR_MISSING, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } if (fiscalYear != null && (fiscalYear < projectStartDate.getYear() + YEAR_CONSTANT || fiscalYear > projectEndDate.getYear() + YEAR_CONSTANT)) { getAuditWarnings() .add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "].fiscalYear", KeyConstants.AUDIT_WARNING_BUDGET_DISTRIBUTION_FISCALYEAR_INCONSISTENT, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); } if (!duplicateEntryFound) { j = 0; for (BudgetUnrecoveredFandA unrecoveredFandAForComparison : unrecoveredFandAs) { if (i != j && unrecoveredFandA.getFiscalYear() != null && unrecoveredFandAForComparison.getFiscalYear() != null && unrecoveredFandA.getFiscalYear().intValue() == unrecoveredFandAForComparison .getFiscalYear().intValue() && unrecoveredFandA.getApplicableRate() .equals(unrecoveredFandAForComparison.getApplicableRate()) && unrecoveredFandA.getOnCampusFlag() .equalsIgnoreCase(unrecoveredFandAForComparison.getOnCampusFlag()) && StringUtils.equalsIgnoreCase(unrecoveredFandA.getSourceAccount(), unrecoveredFandAForComparison.getSourceAccount()) && unrecoveredFandA.getAmount().equals(unrecoveredFandAForComparison.getAmount())) { retval = false; getAuditErrors().add(new AuditError("document.budget.budgetUnrecoveredFandA[" + i + "]", KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_DUPLICATE_UNRECOVERED_FA, Constants.BUDGET_DISTRIBUTION_AND_INCOME_PAGE + "." + Constants.BUDGET_UNRECOVERED_F_AND_A_PANEL_ANCHOR, params)); duplicateEntryFound = true; break; } j++; } } i++; } return retval; }
From source file:org.kuali.coeus.common.budget.impl.distribution.BudgetUnrecoveredFandAAuditRule.java
protected boolean verifySourceAccount(Budget budget, List<BudgetUnrecoveredFandA> unrecoveredFandAs) { boolean retval = true; String source = null;/*w w w.j ava 2 s . c o m*/ Integer fiscalYear = null; int i = 0; int j = 0; BudgetParent budgetParent = budget.getBudgetParent(); Date projectStartDate = budgetParent.getRequestedStartDateInitial(); Date projectEndDate = budgetParent.getRequestedEndDateInitial(); BudgetConstants.BudgetAuditRules budgetUnrecoveredFARule = BudgetConstants.BudgetAuditRules.UNRECOVERED_FA; List<AuditError> auditErrors = getAuditErrors(budgetUnrecoveredFARule, true); List<AuditError> auditWarnings = getAuditErrors(budgetUnrecoveredFARule, false); // Forces inclusion of source account boolean duplicateEntryFound = false; for (BudgetUnrecoveredFandA unrecoveredFandA : unrecoveredFandAs) { source = unrecoveredFandA.getSourceAccount(); fiscalYear = unrecoveredFandA.getFiscalYear(); if (StringUtils.isEmpty(source) || source.length() == 0) { auditErrors.add(new AuditError(budgetUnrecoveredFARule.getPageId(), KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_SOURCE_MISSING, budgetUnrecoveredFARule.getPageId(), params)); retval = false; } if (fiscalYear == null || fiscalYear.intValue() <= 0) { auditErrors.add(new AuditError(budgetUnrecoveredFARule.getPageId(), KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_FISCALYEAR_MISSING, budgetUnrecoveredFARule.getPageId(), params)); retval = false; } if (fiscalYear != null && (fiscalYear < projectStartDate.getYear() + YEAR_CONSTANT || fiscalYear > projectEndDate.getYear() + YEAR_CONSTANT)) { auditWarnings.add(new AuditError(budgetUnrecoveredFARule.getPageId(), KeyConstants.AUDIT_WARNING_BUDGET_DISTRIBUTION_FISCALYEAR_INCONSISTENT, budgetUnrecoveredFARule.getPageId(), params)); retval = true; } if (!duplicateEntryFound) { j = 0; for (BudgetUnrecoveredFandA unrecoveredFandAForComparison : unrecoveredFandAs) { if (i != j && unrecoveredFandA.getFiscalYear() != null && unrecoveredFandAForComparison.getFiscalYear() != null && unrecoveredFandA.getFiscalYear().intValue() == unrecoveredFandAForComparison .getFiscalYear().intValue() && unrecoveredFandA.getApplicableRate() .equals(unrecoveredFandAForComparison.getApplicableRate()) && unrecoveredFandA.getOnCampusFlag() .equalsIgnoreCase(unrecoveredFandAForComparison.getOnCampusFlag()) && StringUtils.equalsIgnoreCase(unrecoveredFandA.getSourceAccount(), unrecoveredFandAForComparison.getSourceAccount()) && unrecoveredFandA.getAmount().equals(unrecoveredFandAForComparison.getAmount())) { auditErrors.add(new AuditError(budgetUnrecoveredFARule.getPageId(), KeyConstants.AUDIT_ERROR_BUDGET_DISTRIBUTION_DUPLICATE_UNRECOVERED_FA, budgetUnrecoveredFARule.getPageId(), params)); duplicateEntryFound = true; retval = false; break; } j++; } } i++; } return retval; }