List of usage examples for java.util Calendar SHORT_FORMAT
int SHORT_FORMAT
To view the source code for java.util Calendar SHORT_FORMAT.
Click Source Link
From source file:eu.squadd.timesheets.eolas.TimeTemplate.java
public String prepareTimesheet(String[] args) { String response = null;/*from w w w.ja va 2 s .c o m*/ try { String[] ym = args[0].split("/"); month = Integer.parseInt(ym[0]); year = Integer.parseInt(ym[1]); Calendar cal = Calendar.getInstance(TimeZone.getDefault()); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); int days = cal.getActualMaximum(Calendar.DAY_OF_MONTH); monthName = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT_FORMAT, Locale.ENGLISH); String periodName = monthName + "-" + year; cal.set(Calendar.DATE, 1); String dayOfWeek = new SimpleDateFormat("EE").format(cal.getTime()); System.out.println("Month: " + periodName); System.out.println("Days in month: " + days); System.out.println("Month starts in: " + dayOfWeek); Map<String, String> bankHolidays = year == 2016 ? publicHolidays2016 : publicHolidays2017; Map<String, String> holidays = this.extractHolidays(args); HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(template)); HSSFSheet sheet = wb.getSheet("timesheet"); //getSheetAt(0); HSSFRow currentRow; SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); sheet.getRow(4).getCell(1).setCellValue(periodName); int row = 7; int startRow = 0; int i = 1; while (i <= days) { currentRow = sheet.getRow(row); if (currentRow.getRowNum() > 47) break; String day = currentRow.getCell(0).getStringCellValue(); if (day.startsWith("Total")) { evaluator.evaluateFormulaCell(currentRow.getCell(2)); evaluator.evaluateFormulaCell(currentRow.getCell(4)); row++; continue; } if (startRow == 0) { if (dayOfWeek.equals(day.substring(0, 3))) { startRow = currentRow.getRowNum(); System.out.println("Starting row found: " + startRow + 1); } else { row++; continue; } } cal.set(Calendar.DATE, i); String date = sdf.format(cal.getTime()); if (!day.equals("Saturday") && !day.equals("Sunday") && bankHolidays.get(date) == null && holidays.get(date) == null) { currentRow.getCell(1).setCellValue(date); currentRow.getCell(2).setCellValue(defaultHours); // regular hours //currentRow.getCell(3).setCellValue(defaultHours); // overtime hours currentRow.getCell(4).setCellValue(defaultHours); // total hours } i++; row++; } currentRow = sheet.getRow(46); evaluator.evaluateFormulaCell(currentRow.getCell(2)); evaluator.evaluateFormulaCell(currentRow.getCell(4)); currentRow = sheet.getRow(47); evaluator.evaluateFormulaCell(currentRow.getCell(2)); evaluator.evaluateFormulaCell(currentRow.getCell(4)); response = outFilePath.replace("#MONTH#", periodName); wb.write(new FileOutputStream(response)); } catch (IOException ex) { Logger.getLogger(Timesheets.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Timesheet created."); return response; }