List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance(int style, Locale aLocale)
From source file:org.openmrs.util.OpenmrsUtil.java
/** * Get the current user's time format Will look similar to "hh:mm a". Depends on user's locale. * // w w w . j a va 2 s . c o m * @return a simple time format * @should return a pattern with two h characters in it * @should not allow the returned SimpleDateFormat to be modified * @since 1.9 */ public static SimpleDateFormat getTimeFormat(Locale locale) { if (timeFormatCache.containsKey(locale)) { return (SimpleDateFormat) timeFormatCache.get(locale).clone(); } SimpleDateFormat sdf = (SimpleDateFormat) DateFormat.getTimeInstance(DateFormat.SHORT, locale); String pattern = sdf.toPattern(); if (!(pattern.contains("hh") || pattern.contains("HH"))) { // otherwise, change the pattern to be a two digit hour pattern = pattern.replaceFirst("h", "hh").replaceFirst("H", "HH"); sdf.applyPattern(pattern); } timeFormatCache.put(locale, sdf); return (SimpleDateFormat) sdf.clone(); }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Get log text of import status./*from w w w .ja v a 2 s. c om*/ * * @param importStatus The import status. * @return The log text of import status. */ private String logImportStatus(ImportStatus importStatus) { Date now = new Date(); StringBuilder sb = new StringBuilder(CRLF); sb.append("Service Credit imported a data file from the bank lockbox on "); sb.append(DateFormat.getDateInstance(DateFormat.LONG, Locale.US).format(now)); sb.append(" at "); sb.append(DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(now)).append(".").append(CRLF); sb.append("Lockbox data imported into the ").append(databaseString); sb.append(" database on server ").append(datasourceString); sb.append(" from computer ").append(workstationId).append("."); sb.append(CRLF).append(CRLF); sb.append("# Lines in file = ") .append(importStatus.getNumberDuplicateRecords() + importStatus.getNumberDiscreteRecords()) .append(CRLF); if (importStatus.getNumberDiscreteRecords() > 0) { sb.append("# New Lines = ").append(importStatus.getNumberDiscreteRecords()).append(CRLF); } sb.append("# Duplicate Lines = ").append(importStatus.getNumberDuplicateRecords()).append(CRLF); sb.append(CRLF); int failedInserts = importStatus.getNumberBadChangeRecords() + importStatus.getNumberNoMatchChangeRecords() + importStatus.getNumberBadAchPayments() + importStatus.getNumberBadCheckPayments(); int successfulInserts = importStatus.getNumberGoodChangeRecords() + importStatus.getNumberGoodAchPayments() + importStatus.getNumberGoodCheckPayments(); sb.append("# Records Processed = ") .append(importStatus.getNumberBadDataRecords() + importStatus.getNumberGoodSummaryRecords() + importStatus.getNumberBadSummaryRecords() + importStatus.getNumberDupeAchPayments() + importStatus.getNumberDupeCheckPayments() + failedInserts + successfulInserts) .append(CRLF); sb.append("# Check Payments = ").append(importStatus.getNumberGoodCheckPayments() + importStatus.getNumberBadCheckPayments() + importStatus.getNumberDupeCheckPayments()) .append(CRLF); sb.append("# Good Check Payments = ").append(importStatus.getNumberGoodCheckPayments()).append(CRLF); sb.append("# Bad Check Payments = ").append(importStatus.getNumberBadCheckPayments()).append(CRLF); sb.append("# Dupe Check Payments = ").append(importStatus.getNumberDupeCheckPayments()).append(CRLF); sb.append("# ACH Payments = ").append(importStatus.getNumberGoodAchPayments() + importStatus.getNumberBadAchPayments() + importStatus.getNumberDupeAchPayments()).append(CRLF); sb.append("# Good ACH Payments = ").append(importStatus.getNumberGoodAchPayments()).append(CRLF); sb.append("# Bad ACH Payments = ").append(importStatus.getNumberBadAchPayments()).append(CRLF); sb.append("# Dupe ACH Payments = ").append(importStatus.getNumberDupeAchPayments()).append(CRLF); sb.append("# Bad Change Records = ").append(importStatus.getNumberBadChangeRecords()).append(CRLF); sb.append("# Good Change Records = ").append(importStatus.getNumberGoodChangeRecords()).append(CRLF); sb.append("# No Match Change Records = ").append(importStatus.getNumberNoMatchChangeRecords()).append(CRLF); sb.append("# Invalid Summary Records = ").append(importStatus.getNumberBadSummaryRecords()).append(CRLF); sb.append("# Valid Summary Records = ").append(importStatus.getNumberGoodSummaryRecords()).append(CRLF); sb.append("# Successful Transactions = ").append(successfulInserts).append(CRLF); sb.append("# Failed Transactions = ").append(failedInserts).append(CRLF); sb.append("# Invalid Lines = ").append(importStatus.getNumberBadDataRecords()).append(CRLF); sb.append(CRLF); sb.append("Total Check Payments = ").append(importStatus.getTotalCheckPayments()).append(CRLF); sb.append("Total ACH Payments = ").append(importStatus.getTotalACHPayments()).append(CRLF); sb.append("Total of Accepted Payments = ") .append(importStatus.getTotalCheckPayments().add(importStatus.getTotalACHPayments())).append(CRLF); if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) == 0) { sb.append("Total in File = ").append(importStatus.getFileSummaryTotal()).append(CRLF); } else { sb.append("Total in File Summary (checksum) = ").append(importStatus.getFileSummaryTotal()) .append(CRLF); sb.append("Total of Processed Transactions = ").append(importStatus.getTransactionsTotal()) .append(CRLF); sb.append(CRLF).append(CRLF); sb.append("ERROR: THE BANK FILE CONTAINED ").append(importStatus.getFileSummaryTotal()).append(" BUT ") .append(importStatus.getTransactionsTotal()) .append(" WAS IMPORTED INTO THE SERVICE CREDIT DATABASE. "); if (importStatus.getNumberGoodSummaryRecords() > 0) { if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) > 0) { sb.append("THE PROGRAM IMPORTED ") .append(importStatus.getTransactionsTotal() .subtract(importStatus.getFileSummaryTotal())) .append(" MORE THAN THE BANK TOTAL.").append(CRLF); } else if (Double.compare(importStatus.getTransactionsTotal().doubleValue(), importStatus.getFileSummaryTotal().doubleValue()) < 0) { sb.append("THE PROGRAM IMPORTED ") .append(importStatus.getFileSummaryTotal() .subtract(importStatus.getTransactionsTotal())) .append(" LESS THAN THE BANK TOTAL.").append(CRLF); } } } sb.append(CRLF); int failedCount = importStatus.getNumberBadDataRecords() + importStatus.getNumberBadSummaryRecords() + failedInserts; if (failedCount > 0) { sb.append("ERROR: ").append(failedCount).append(" RECORDS FAILED PROCESSING.").append(CRLF); } else { sb.append("No bad records in this batch.").append(CRLF); } if (failedInserts > 0) { sb.append("ERROR: ").append(failedInserts).append(" TRANSACTIONS COULD NOT BE READ INTO THE DATABASE!") .append(CRLF); } if (importStatus.getNumberBadSummaryRecords() > 0) { sb.append("ERROR: ").append(importStatus.getNumberBadSummaryRecords()) .append(" CHECKSUMS COULD NOT BE PROCESSED!").append(CRLF); } if (importStatus.getNumberDuplicateRecords() > 0) { sb.append(importStatus.getNumberDuplicateRecords()).append(" DUPLICATE RECORDS FROM THE BANK") .append(CRLF); } sb.append(successfulInserts).append(" = number of successful calls to the ProcessImportRecord function.") .append(CRLF); if (failedInserts > 0) { sb.append(failedInserts).append(" NUMBER OF FAILED CALLS TO THE PROCESSIMPORTRECORD FUNCTION!") .append(CRLF); } sb.append(CRLF); // Log pending payment transactions collated sb.append(" Accepted Payments: ").append( importStatus.getNumberAcceptedCheckPayments() + importStatus.getNumberAcceptedAchPayments()); sb.append(CRLF); sb.append(" Unresolved Payments: ").append( importStatus.getNumberUnresolvedCheckPayments() + importStatus.getNumberUnresolvedAchPayments()); sb.append(CRLF); sb.append(" Suspended Payments: ").append( importStatus.getNumberSuspendedCheckPayments() + importStatus.getNumberSuspendedAchPayments()); sb.append(CRLF); sb.append("-----------------------------------"); sb.append(CRLF); sb.append("Pending payments processed: ").append(importStatus.getNumberAcceptedCheckPayments() + importStatus.getNumberAcceptedAchPayments() + importStatus.getNumberUnresolvedCheckPayments() + importStatus.getNumberUnresolvedAchPayments() + importStatus.getNumberSuspendedCheckPayments() + importStatus.getNumberSuspendedAchPayments()); sb.append(CRLF); return sb.toString(); }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Sends the notification by email.// ww w. jav a 2 s. co m * <p/> * This method does not throw any exception. * * @param mailMessage The message of the mail. * @param mailSubject The subject of the email. * @param processType The name of the current processor. It is used to distinguish the recipient of the email. */ private void notifyByEmail(String mailMessage, String mailSubject, String processType) { mailMessage = mailMessage.replace("@#$%EndingTime%$#@", DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(new Date())); String recipient = processType.equals("BillProcessing") ? billMailRecipient : generalMailRecipient; logger.info( "Send email to " + recipient + ", subject = [" + mailSubject + "]. Message:" + CRLF + mailMessage); MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(message); try { helper.setTo(recipient); helper.setSubject(mailSubject); helper.setText(mailMessage); mailSender.send(message); } catch (MessagingException e) { logger.error("Error sending email to " + recipient + ", subject = [" + mailSubject + "].", e); } catch (MailSendException e) { logger.error("Error sending email to " + recipient + ", subject = [" + mailSubject + "].", e); } }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Audit the lock box import file error. * @param subject the error subject//from ww w . j a va 2s. c om * @param description the error description */ private void auditError(String subject, String description) { AuditRecord record = new AuditRecord(); record.setUsername("Batch Process Module"); record.setDate(new Date()); record.setIpAddress("N/A"); record.setActionName("Lock Box Import Error"); List<AuditParameterRecord> list = new ArrayList<AuditParameterRecord>(); AuditParameterRecord param = new AuditParameterRecord(); param.setItemId(0L); param.setItemType("Lock Box Import"); param.setPropertyName("subject"); param.setPreviousValue("N/A"); param.setNewValue(subject); list.add(param); AuditParameterRecord param2 = new AuditParameterRecord(); param2.setItemId(0L); param2.setItemType("Lock Box Import"); param2.setPropertyName("error description"); param2.setPreviousValue("N/A"); param2.setNewValue(description.replace("@#$%EndingTime%$#@", DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(new Date()))); list.add(param2); record.setParameters(list); persistEntity(record); }
From source file:gov.opm.scrd.batchprocessing.jobs.BatchProcessingJob.java
/** * Saves the process messages.// www . j a v a 2s. co m * @param procMessage the process message */ private void savePaymentStatusPrint(String procMessage) { PaymentStatementPrint psp = new PaymentStatementPrint(); psp.setDate(new Date()); psp.setMessage(procMessage.replace("@#$%EndingTime%$#@", DateFormat.getTimeInstance(DateFormat.LONG, Locale.US).format(new Date()))); persistEntity(psp); }
From source file:org.exoplatform.outlook.OutlookServiceImpl.java
/** * Generate message summary text.//from ww w.j a v a 2s . co m * * @param message {@link String} * @return {@link String} */ protected String messageSummary(OutlookMessage message) { String fromEmail = message.getFrom().getEmail(); String fromName = message.getFrom().getDisplayName(); Date time = message.getCreated().getTime(); Locale locale = Locale.ENGLISH; ResourceBundle res = resourceBundleService.getResourceBundle("locale.outlook.Outlook", locale); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale); DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, locale); StringBuilder fromLine = new StringBuilder(); fromLine.append(fromName); fromLine.append('<'); fromLine.append(fromEmail); fromLine.append('>'); StringBuilder summary = new StringBuilder(); summary.append(res.getString("Outlook.activity.from")); summary.append(": <a href='mailto:"); summary.append(fromEmail); summary.append("' target='_top'>"); summary.append(ContentReader.simpleEscapeHtml(fromLine.toString())); summary.append("</a> "); summary.append(res.getString("Outlook.activity.on")); summary.append(' '); summary.append(dateFormat.format(time)); summary.append(' '); summary.append(res.getString("Outlook.activity.at")); summary.append(' '); summary.append(timeFormat.format(time)); return summary.toString(); }
From source file:de.innovationgate.wga.server.api.WGA.java
/** * Returns an OpenWGA date format/*from w ww . j a va2 s. co m*/ * @param pattern The date format pattern * @param locale A locale to use for locale-dependent date parts. Specify null to let the current WebTML context choose the locale. * @throws WGException */ public DateFormat getDateFormat(String pattern, Locale locale) throws WGException { // Select language for language dependent date formats if (locale == null) { locale = chooseLocale(locale); } // Language Fallback(s) if (WGUtils.isEmpty(pattern)) { return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale); } // For default patterns String lcPattern = pattern.toLowerCase(); if (lcPattern.endsWith("date") || lcPattern.endsWith("time")) { int patternLength; if (lcPattern.startsWith("short")) { patternLength = DateFormat.SHORT; } else if (lcPattern.startsWith("medium")) { patternLength = DateFormat.MEDIUM; } else if (lcPattern.startsWith("long")) { patternLength = DateFormat.LONG; } else { patternLength = DateFormat.FULL; } if (lcPattern.endsWith("datetime")) { return new TextualDateFormat(locale, DateFormat.getDateTimeInstance(patternLength, patternLength, locale)); } else if (lcPattern.endsWith("time")) { return new TextualDateFormat(locale, DateFormat.getTimeInstance(patternLength, locale)); } else { return new TextualDateFormat(locale, DateFormat.getDateInstance(patternLength, locale)); } } else if (lcPattern.equals("iso8601")) { return new ISO8601DateFormat(); } // For custom patterns SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, locale); dateFormat.setLenient(false); return new TextualDateFormat(locale, dateFormat); }