List of usage examples for org.apache.commons.lang3.time DateFormatUtils format
public static String format(final Calendar calendar, final String pattern, final Locale locale)
Formats a calendar into a specific pattern in a locale.
From source file:io.lavagna.common.Json.java
public static String formatDate(Date date) { return DateFormatUtils.format(date, Constants.DATE_FORMAT, TimeZone.getTimeZone("Z")); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.message.MMXPubSubItem.java
private void parsePayload(Element payloadElement) { if (payloadElement != null) { Document d = payloadElement.getDocument(); Node mmxPayloadNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_PAYLOAD)); if (mmxPayloadNode != null) { String mtype = mmxPayloadNode.valueOf("@mtype"); String stamp = DateFormatUtils.format(new DateTime(mmxPayloadNode.valueOf("@stamp")).toDate(), "yyyy-MM-dd'T'HH:mm:ss'Z'", TimeZone.getTimeZone("UTC")); String data = mmxPayloadNode.getText(); payload = new MMXPubSubPayload(mtype, stamp, data); }// w ww . ja va 2s . c o m Node mmxMetaNode = d.selectSingleNode( String.format("/*[name()='%s']/*[name()='%s']", Constants.MMX_ELEMENT, Constants.MMX_META)); if (mmxMetaNode != null) { meta = getMapFromJsonString(mmxMetaNode.getText()); } } }
From source file:com.revimedia.tests.configuration.helpers.verifier.AutoRequest.java
public static void verifyA(ExtraDataAutoP extraData, LeadDataType leadDataType, String url) { ContactDataType contactData = leadDataType.getContactData(); DriverType driver = leadDataType.getQuoteRequest().getDrivers().getDriver(); InsuranceType insurance = leadDataType.getQuoteRequest().getInsurance(); VehicleType vehicleType = leadDataType.getQuoteRequest().getVehicles().getVehicle().get(0); if (url.contains("?style=s")) { // according to the spec for [auto/a/?style=s] http://docs.revimedia.com/pages/viewpage.action?pageId=3637399 extraData.setLeased("Yes"); extraData.setPrimaryUse("Commute To/From Work"); extraData.setAnnualMiles("12500"); extraData.setExpirationDateMonth(DataHelper.getCurrentDatePlus1Month()); }//from w w w . j a v a 2s .c o m //Fields from Step 1 assertThat(vehicleType.getYear(), is(extraData.getYear())); assertThat(vehicleType.getMake(), is(extraData.getMake())); assertThat(vehicleType.getModel(), is((extraData.getModel()).replace(".", "-"))); //Fields from Step 2 assertThat(vehicleType.getOwnership(), is(extraData.getLeased())); assertThat(vehicleType.getPrimaryUse(), is(extraData.getPrimaryUse())); assertThat(vehicleType.getAnnualMiles(), is(extraData.getAnnualMiles())); //Fields from Step 3 assertThat(insurance.getRequestedPolicy().getCoverageType(), is(extraData.getCoverageType())); if (extraData.getCurrentlyInsured().equalsIgnoreCase("No")) { extraData.setInsuranceCompany("Currently not insured"); assertThat(insurance.getCurrentPolicy().getInsuranceCompany(), is(extraData.getInsuranceCompany())); } else { assertThat(insurance.getCurrentPolicy().getInsuranceCompany(), is(extraData.getInsuranceCompany())); if (url.contains("?style=s")) { // assertThat(insurance.getCurrentPolicy().getExpirationDate(), is(extraData.getExpirationDateMonth())); assertThat(insurance.getCurrentPolicy().getExpirationDate(), is(DateFormatUtils.format(DateUtils.addMonths(new Date(), 1), "yyyy-MM-dd", Locale.US))); } else { assertThat(insurance.getCurrentPolicy().getExpirationDate(), is(DataHelper.dateTransformExpirationDate(extraData.getExpirationDateMonth()))); } assertThat(insurance.getCurrentPolicy().getInsuredSince(), is(DataHelper.dateTransformInsuredSince(extraData.getInsuredSinceYears()))); } //Fields from Step 4 assertThat(driver.getMaritalStatus(), is(extraData.getMaritalStatus())); if (driver.getOccupation().equalsIgnoreCase("Employeed")) { extraData.setOccupation("Employeed"); } assertThat(driver.getOccupation(), is(extraData.getOccupation())); assertThat(driver.getEducation(), is(extraData.getEducation())); assertThat(driver.getCreditRating(), is(extraData.getCreditRating())); if (extraData.getHomeOwner().equalsIgnoreCase("yes")) { extraData.setResidenceType("My own house"); } else { extraData.setResidenceType("I am renting"); } assertThat(contactData.getResidenceType(), is(extraData.getResidenceType())); }
From source file:com.erudika.para.utils.Utils.java
/** * Formats a date in a specific format.// w w w.j a v a 2s .c om * @param timestamp the Java timestamp * @param format the date format * @param loc the locale instance * @return a formatted date */ public static String formatDate(Long timestamp, String format, Locale loc) { if (StringUtils.isBlank(format)) { format = DateFormatUtils.ISO_DATE_FORMAT.getPattern(); } if (timestamp == null) { timestamp = timestamp(); } if (loc == null) { loc = Locale.US; } return DateFormatUtils.format(timestamp, format, loc); }
From source file:com.erudika.scoold.controllers.SigninController.java
private void setAuthCookie(String jwt, HttpServletRequest req, HttpServletResponse res) { int maxAge = Config.SESSION_TIMEOUT_SEC; String expires = DateFormatUtils.format(System.currentTimeMillis() + (maxAge * 1000), "EEE, dd-MMM-yyyy HH:mm:ss z", TimeZone.getTimeZone("GMT")); StringBuilder sb = new StringBuilder(); sb.append(Config.AUTH_COOKIE).append("=").append(jwt).append(";"); sb.append("Path=/;"); sb.append("Expires=").append(expires).append(";"); sb.append("Max-Age=").append(maxAge).append(";"); sb.append("HttpOnly;"); sb.append("SameSite=Strict"); res.addHeader(HttpHeaders.SET_COOKIE, sb.toString()); }
From source file:org.evosuite.continuous.persistency.StorageManager.java
/** * Create a new tmp folder for this CTG session * // w w w . jav a 2 s. c om * @return */ public boolean createNewTmpFolders() { if (!this.isStorageOk) { return false; } String time = DateFormatUtils.format(new Date(), "yyyy_MM_dd_HH_mm_ss", Locale.getDefault()); File tmp = null; if (Properties.CTG_GENERATION_DIR_PREFIX == null) tmp = new File(Properties.CTG_DIR + File.separator + TMP_PREFIX + time); else tmp = new File(Properties.CTG_DIR + File.separator + TMP_PREFIX + Properties.CTG_GENERATION_DIR_PREFIX + "_" + time); if (!tmp.mkdirs()) return false; // if we created the "tmp" folder or already exists, then it should be fine to create new folders in it this.tmpLogs = new File(tmp.getAbsolutePath() + File.separator + Properties.CTG_TMP_LOGS_DIR_NAME); if (!this.tmpLogs.exists() && !this.tmpLogs.mkdirs()) { return false; } this.tmpReports = new File(tmp.getAbsolutePath() + File.separator + Properties.CTG_TMP_REPORTS_DIR_NAME); if (!this.tmpReports.exists() && !this.tmpReports.mkdirs()) { return false; } this.tmpTests = new File(tmp.getAbsolutePath() + File.separator + Properties.CTG_TMP_TESTS_DIR_NAME); if (!this.tmpTests.exists() && !this.tmpTests.mkdirs()) { return false; } this.tmpPools = new File(tmp.getAbsolutePath() + File.separator + Properties.CTG_TMP_POOLS_DIR_NAME); if (!this.tmpPools.exists() && !this.tmpPools.mkdirs()) { return false; } this.tmpSeeds = new File(tmp.getAbsolutePath() + File.separator + Properties.CTG_SEEDS_DIR_NAME); if (!this.tmpSeeds.exists() && !this.tmpSeeds.mkdirs()) { return false; } return true; }