Example usage for org.apache.commons.lang3.time DateFormatUtils format

List of usage examples for org.apache.commons.lang3.time DateFormatUtils format

Introduction

In this page you can find the example usage for org.apache.commons.lang3.time DateFormatUtils format.

Prototype

public static String format(final Calendar calendar, final String pattern) 

Source Link

Document

Formats a calendar into a specific pattern.

Usage

From source file:org.rippleosi.common.util.DateFormatter.java

public static String toDateTimeString(Date input) {
    if (input == null) {
        return null;
    }//from w  w w. ja  v  a 2 s  . c  om

    return DateFormatUtils.format(input, "yyyy-MM-dd'T'HH:mm");
}

From source file:org.spdx.rdfparser.model.SpdxDocument.java

/**
 * @param documentContainer//from  w  w w .  ja  va  2 s  .  co  m
 * @param node
 * @throws InvalidSPDXAnalysisException
 */
public SpdxDocument(SpdxDocumentContainer documentContainer, Node node) throws InvalidSPDXAnalysisException {
    super(documentContainer, node);
    this.documentContainer = documentContainer;
    getMyPropertiesFromModel();
    if (this.getCreationInfo() == null) {
        String licenseListVersion = ListedLicenses.getListedLicenses().getLicenseListVersion();
        String creationDate = DateFormatUtils.format(Calendar.getInstance(), SpdxRdfConstants.SPDX_DATE_FORMAT);
        SPDXCreatorInformation creationInfo = new SPDXCreatorInformation(new String[] {}, creationDate, null,
                licenseListVersion);
        setCreationInfo(creationInfo);
    } else if (StringUtils.isBlank(this.getCreationInfo().getLicenseListVersion())) {
        this.getCreationInfo()
                .setLicenseListVersion(ListedLicenses.getListedLicenses().getLicenseListVersion());
    }

}

From source file:org.squashtest.tm.web.internal.controller.audittrail.RequirementAuditEventTableModelBuilder.java

private void populateCurrentItemData(String message, String eventType, RequirementAuditEvent event) {

    String formattedDate = DateFormatUtils.format(event.getDate(), "dd/MM/yyyy HH'h'mm");
    String escapedAuthor = HtmlUtils.htmlEscape(event.getAuthor());
    String escapedMessage = HtmlUtils.htmlEscape(message);

    Map<String, String> row = new HashMap<>(5);

    row.put("event-date", formattedDate);
    row.put("event-author", escapedAuthor);
    row.put("event-message", escapedMessage);
    row.put("event-type", eventType);
    row.put("event-id", String.valueOf(event.getId()));

    currentItemData = row;//from ww w.j  a  v a 2 s. c  o  m

}

From source file:paarmann.physikprofil.TimePreference.java

@Override
public CharSequence getSummary() {
    return (_value == null) ? null : DateFormatUtils.format(_value, "HH:mm");
}

From source file:psyriccio.voteflow.api.LawAPI.java

protected Map<String, String> getParams(Object obj) {
    Map<String, String> params = new HashMap<>();
    final Function<Date, String> formatDate = (Date t) -> {
        return DateFormatUtils.format(t, "yyyy-MM-dd");
    };/*ww w .  j av a  2 s.c  o m*/

    if (obj == null) {
        return params;
    }
    for (Method method : obj.getClass().getMethods()) {
        if (method.getParameterCount() == 0) {
            if (method.getName().startsWith("get") || method.getName().startsWith("is")) {
                String name = method.getName().replaceAll("get", "").replaceAll("is", "").toLowerCase();
                if (name.equals("class")) {
                    continue;
                }
                try {
                    Object objVal = method.invoke(obj);
                    if (objVal != null) {
                        String value = "";
                        if (objVal instanceof Boolean) {
                            value = ((Boolean) objVal) ? "1" : "0";
                        } else if (objVal instanceof Date) {
                            value = formatDate.apply((Date) objVal);
                        } else {
                            value = objVal.toString();
                        }
                        params.put(name, value);
                    }
                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                    Main.log.error("Exception: {}", ex);
                }
            }
        }
    }
    return params;
}

From source file:ren.hankai.cordwood.core.convert.StringToDateConverterTest.java

@Test
public void testConvertWithformat() throws Exception {
    final String format = "yyyy|MM|dd";
    final StringToDateConverter converter = new StringToDateConverter(format);

    final Date now = new Date();
    // 3?//w w w  . j  ava  2s.  com
    for (int i = 1; i <= testDays; i++) {
        final Date expDate = DateUtils.addDays(now, i);
        final String strDate = DateFormatUtils.format(expDate, format);
        final Date actual = converter.convert(strDate);
        Assert.assertTrue(DateUtils.isSameDay(actual, expDate));
    }
}

From source file:ren.hankai.cordwood.core.convert.StringToDateConverterTest.java

@Test
public void testConvertWithoutformat() throws Exception {
    final StringToDateConverter converter = new StringToDateConverter(null);

    final Date now = new Date();
    // 3?/* www.ja  v a  2s .  c o m*/
    for (int i = 1; i <= testDays; i++) {
        final Date expDate = DateUtils.addDays(now, i);
        String strDate = null;
        if ((i % 2) == 0) {
            strDate = DateFormatUtils.format(expDate, "yyyy-MM-dd");
            final Date actual = converter.convert(strDate);
            Assert.assertTrue(DateUtils.isSameDay(actual, expDate));
        } else {
            strDate = DateFormatUtils.format(expDate, "yyyy-MM-dd HH:mm:ss");
            final Date actual = converter.convert(strDate);
            Assert.assertTrue(DateUtils.truncatedEquals(actual, expDate, Calendar.SECOND));
        }
    }
}

From source file:ubic.gemma.core.analysis.report.ArrayDesignReportServiceImpl.java

@Override
public void generateAllArrayDesignReport() {
    ArrayDesignReportServiceImpl.log.info("Generating report summarizing all platforms ... ");

    // obtain time information (for timestamp)
    Date d = new Date(System.currentTimeMillis());
    String timestamp = DateFormatUtils.format(d, "yyyy.MM.dd HH:mm");

    long numCsBioSequences = arrayDesignService.numAllCompositeSequenceWithBioSequences();
    long numCsBlatResults = arrayDesignService.numAllCompositeSequenceWithBlatResults();
    long numCsGenes = arrayDesignService.numAllCompositeSequenceWithGenes();
    long numGenes = arrayDesignService.numAllGenes();

    // create a surrogate ArrayDesignValue object to represent the total of all platforms
    ArrayDesignValueObject adVo = new ArrayDesignValueObject(-1L);
    adVo.setNumProbeSequences(Long.toString(numCsBioSequences));
    adVo.setNumProbeAlignments(Long.toString(numCsBlatResults));
    adVo.setNumProbesToGenes(Long.toString(numCsGenes));
    adVo.setNumGenes(Long.toString(numGenes));
    adVo.setDateCached(timestamp);/*from   www  .  ja  v a  2s .  co  m*/
    // remove file first
    File f = new File(ArrayDesignReportServiceImpl.HOME_DIR + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_DIR + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_SUMMARY);
    if (f.exists()) {
        if (!f.canWrite() || !f.delete()) {
            ArrayDesignReportServiceImpl.log.warn("Cannot write to file.");
            return;
        }
    }
    try (FileOutputStream fos = new FileOutputStream(ArrayDesignReportServiceImpl.HOME_DIR + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_DIR + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_SUMMARY);
            ObjectOutputStream oos = new ObjectOutputStream(fos)) {
        oos.writeObject(adVo);
    } catch (Throwable e) {
        // cannot write to file. Just fail gracefully.
        ArrayDesignReportServiceImpl.log.error("Cannot write to file.");
    }
    ArrayDesignReportServiceImpl.log.info("Done making reports");
}

From source file:ubic.gemma.core.analysis.report.ArrayDesignReportServiceImpl.java

@Override
public void generateArrayDesignReport(ArrayDesignValueObject adVo) {

    ArrayDesign ad = arrayDesignService.load(adVo.getId());
    if (ad == null)
        return;//www.ja  va 2  s. c o  m

    // obtain time information (for timestamp)
    Date d = new Date(System.currentTimeMillis());
    String timestamp = DateFormatUtils.format(d, "yyyy.MM.dd HH:mm");

    long numProbes = arrayDesignService.getCompositeSequenceCount(ad);
    long numCsBioSequences = arrayDesignService.numCompositeSequenceWithBioSequences(ad);
    long numCsBlatResults = arrayDesignService.numCompositeSequenceWithBlatResults(ad);
    long numCsGenes = arrayDesignService.numCompositeSequenceWithGenes(ad);
    long numGenes = arrayDesignService.numGenes(ad);

    adVo.setDesignElementCount((int) numProbes);
    adVo.setNumProbeSequences(Long.toString(numCsBioSequences));
    adVo.setNumProbeAlignments(Long.toString(numCsBlatResults));
    adVo.setNumProbesToGenes(Long.toString(numCsGenes));
    adVo.setNumGenes(Long.toString(numGenes));
    adVo.setDateCached(timestamp);

    // check the directory exists.
    String reportDir = ArrayDesignReportServiceImpl.HOME_DIR + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_DIR;
    File reportDirF = new File(reportDir);
    if (!reportDirF.exists()) {
        EntityUtils.mkdirs(reportDirF);
    }

    String reportFileName = reportDir + File.separatorChar
            + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_FILE_NAME_PREFIX + "." + adVo.getId();
    File f = new File(reportFileName);

    if (f.exists()) {
        if (!f.canWrite() || !f.delete()) {
            ArrayDesignReportServiceImpl.log.error(
                    "Report exists but cannot overwrite, leaving the old one in place: " + reportFileName);
            return;
        }
    }

    try (FileOutputStream fos = new FileOutputStream(reportFileName);
            ObjectOutputStream oos = new ObjectOutputStream(fos)) {
        oos.writeObject(adVo);
    } catch (Throwable e) {
        ArrayDesignReportServiceImpl.log.error("Cannot write to file: " + reportFileName);
        return;
    }
    ArrayDesignReportServiceImpl.log.info("Generated report for " + ad);
}

From source file:ubic.gemma.core.analysis.report.ArrayDesignReportServiceImpl.java

private String getLastEvent(Long id, Class<? extends AuditEventType> eventType) {
    ArrayDesign ad = arrayDesignService.load(id);

    if (ad == null)
        return "";

    List<AuditEvent> events2 = auditEventService.getEvents(ad);

    String analysisEventString;//from   w  w  w .j a va  2s . c o m
    List<AuditEvent> events = new ArrayList<>();

    for (AuditEvent event : events2) {
        if (event == null)
            continue; // legacy of ordered-list which could end up with gaps; should not be needed
        // any more
        if (event.getEventType() != null && eventType.isAssignableFrom(event.getEventType().getClass())) {
            events.add(event);
        }
    }

    if (events.size() == 0) {
        return "[None]";
    }

    // add the most recent events to the report. There should always be at least one creation event.
    AuditEvent lastEvent = events.get(events.size() - 1);
    analysisEventString = DateFormatUtils.format(lastEvent.getDate(), "yyyy.MMM.dd hh:mm aa");

    return analysisEventString;
}