List of usage examples for java.time.format DateTimeFormatter ofPattern
public static DateTimeFormatter ofPattern(String pattern)
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceIntegrationTest.java
@Test public void GetCitationsByDOBAndLicenseSuccessful() throws ParseException { String dateString = "05/18/1987"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); List<Citation> citations = mockCitationDataSource.getByLicenseAndDOB("S878479512", "MO", date); assertThat(citations, is(notNullValue())); assertThat(citations.size(), is(3)); assertThat(citations.get(0).first_name, is("Brenda")); }
From source file:org.ligoj.app.plugin.prov.aws.auth.AWS4SignerForAuthorizationHeader.java
/** * Computes an AWS4 signature for a request, ready for inclusion as an * 'Authorization' header.// w w w.j av a 2 s . c o m * * @param query * the query * @return The computed authorization string for the request. This value needs * to be set as the header 'Authorization' on the subsequent HTTP * request. */ public String computeSignature(final AWS4SignatureQuery query) { // first get the date and time for the subsequent request, and convert // to ISO 8601 format for use in signature generation final ZonedDateTime now = ZonedDateTime.now(clock); final String dateTimeStamp = DateTimeFormatter.ofPattern(ISO8601_FORMAT).format(now); final String bodyHash; if (query.getBody() == null) { bodyHash = EMPTY_BODY_SHA256; } else { bodyHash = hash(query.getBody()); } // update the headers with required 'x-amz-date' and 'host' values query.getHeaders().put("x-amz-date", dateTimeStamp); query.getHeaders().put("x-amz-content-sha256", bodyHash); query.getHeaders().put("Host", query.getHost()); // canonicalize the headers; we need the set of header names as well as // the names and values to go into the signature process final String canonicalizedHeaderNames = getCanonicalizeHeaderNames(query.getHeaders()); final String canonicalizedHeaders = getCanonicalizedHeaderString(query.getHeaders()); // if any query string parameters have been supplied, canonicalize them final String canonicalizedQueryParameters = getCanonicalizedQueryString(query.getQueryParameters()); // canonicalize the various components of the request final String canonicalRequest = getCanonicalRequest(query.getPath(), query.getMethod(), canonicalizedQueryParameters, canonicalizedHeaderNames, canonicalizedHeaders, bodyHash); // construct the string to be signed final String dateStamp = DateTimeFormatter.ofPattern(DATE_FORMAT).format(now); final String scope = dateStamp + "/" + query.getRegion() + "/" + query.getService() + "/" + TERMINATOR; final String stringToSign = getStringToSign(dateTimeStamp, scope, canonicalRequest); // compute the signing key final byte[] kSecret = (SCHEME + query.getSecretKey()).getBytes(); final byte[] kDate = sign(dateStamp, kSecret); final byte[] kRegion = sign(query.getRegion(), kDate); final byte[] kService = sign(query.getService(), kRegion); final byte[] kSigning = sign(TERMINATOR, kService); final byte[] signature = sign(stringToSign, kSigning); final String credentialsAuthorizationHeader = "Credential=" + query.getAccessKey() + "/" + scope; final String signedHeadersAuthorizationHeader = "SignedHeaders=" + canonicalizedHeaderNames; final String signatureAuthorizationHeader = "Signature=" + Hex.encodeHexString(signature); return SCHEME + "-" + ALGORITHM + " " + credentialsAuthorizationHeader + ", " + signedHeadersAuthorizationHeader + ", " + signatureAuthorizationHeader; }
From source file:agendapoo.Model.Usuario.java
/** * LocalDate possui o formato da data seguindo esse modelo "yyyy-MM-dd", esse * mtodo tem como objetivo retornar a String da LocalDate com sua data * no formato "dd/MM/yyyy".// ww w . ja v a2 s . c o m * @return String contendo a data formatada no padro dd/MM/yyyy. */ public String getFormattedDate() { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy"); return dataNascimento.format(dtf); }
From source file:com.haulmont.chile.core.datatypes.impl.LocalDateDatatype.java
@Override public LocalDate parse(String value, Locale locale) throws ParseException { if (StringUtils.isBlank(value)) { return null; }//ww w . ja va 2 s . c o m FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale); if (formatStrings == null) { return parse(value); } DateTimeFormatter formatter = DateTimeFormatter.ofPattern(formatPattern); return LocalDate.parse(value.trim(), formatter); }
From source file:rapture.dp.invocable.workflow.LoadFile.java
@Override public String invoke(CallingContext ctx) { String archiveUriPrefix = "blob://archive/"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss"); String dateTime = LocalDateTime.now().format(formatter); // create a unique uri path to store file in and for other steps use Kernel.getDecision().setContextLiteral(ctx, getWorkerURI(), "folderName", dateTime); // get the context variable passed into workflow String absFilePath = Kernel.getDecision().getContextValue(ctx, getWorkerURI(), "filetoupload"); log.info("Loading File:" + absFilePath); try {/*from w w w. ja va 2 s. co m*/ File f = new File(absFilePath); byte[] data = FileUtils.readFileToByteArray(f); String uri = archiveUriPrefix + dateTime + "/" + f.getName(); Kernel.getBlob().putBlob(ctx, uri, data, MediaType.MICROSOFT_EXCEL.toString()); if (Kernel.getBlob().getBlob(ctx, uri) != null) { log.info("File written to " + uri + " with size " + Kernel.getBlob().getBlobSize(ctx, uri)); Kernel.getDecision().setContextLiteral(ctx, getWorkerURI(), "blobUri", uri); } else { log.error("Problem writing file to " + uri); return "error"; } } catch (IOException e) { log.error("Exception " + e.getMessage(), e); return "error"; } return "ok"; }
From source file:svc.data.citations.datasources.mock.MockCitationDataSourceTest.java
@SuppressWarnings("unchecked") @Test// ww w. j a va2s .co m public void returnsCitationGivenCitationNumberAndDOB() throws ParseException { final Violation VIOLATION = new Violation(); VIOLATION.id = 4; final List<Violation> VIOLATIONS = Lists.newArrayList(VIOLATION); final Citation CITATION = new Citation(); CITATION.id = 3; final String CITATIONNUMBER = "F3453"; String dateString = "08/05/1965"; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); LocalDate date = LocalDate.parse(dateString, formatter); when(jdbcTemplate.query(Matchers.anyString(), Matchers.anyMap(), Matchers.<RowMapper<Citation>>any())) .thenReturn(Lists.newArrayList(CITATION)); List<Citation> citations = mockCitationDataSource.getByCitationNumberAndDOB(CITATIONNUMBER, date); when(violationManagerMock.getViolationsByCitationNumber(Matchers.anyString())).thenReturn(VIOLATIONS); assertEquals(citations.size(), 1); assertThat(citations.get(0).id, is(3)); }
From source file:Main.java
/** * Converts a LocalDate (ISO) value to a ChronoLocalDate date using the * provided Chronology, and then formats the ChronoLocalDate to a String using * a DateTimeFormatter with a SHORT pattern based on the Chronology and the * current Locale.//from w w w. j a v a2s .com * * @param localDate * - the ISO date to convert and format. * @param chrono * - an optional Chronology. If null, then IsoChronology is used. */ public static String toString(LocalDate localDate, Chronology chrono) { if (localDate != null) { Locale locale = Locale.getDefault(Locale.Category.FORMAT); ChronoLocalDate cDate; if (chrono == null) { chrono = IsoChronology.INSTANCE; } try { cDate = chrono.date(localDate); } catch (DateTimeException ex) { System.err.println(ex); chrono = IsoChronology.INSTANCE; cDate = localDate; } String pattern = "M/d/yyyy GGGGG"; DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(pattern); return dateFormatter.format(cDate); } else { return ""; } }
From source file:de.fhws.ifactory.api.utils.UserCSVToRequestTransformer.java
@Override protected UserViewModel transformCSVRecordToModel(CSVRecord record) { // ###(csv_headers) You can edit below this line ### final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.datePattern); formatter.withLocale(Locale.GERMANY); final UserViewModel model = new UserViewModel(); model.setFirstName(record.get("firstName")); model.setLastName(record.get("lastName")); model.setRole(Integer.parseInt(record.get("role"))); model.setIsGuest(Integer.parseInt(record.get("isGuest"))); model.setId(Integer.parseInt(record.get("id"))); model.setEmail(record.get("email")); return model; // ###(csv_headers) You can edit above this line ### }
From source file:de.fhws.ifactory.api.utils.SessionCSVToRequestTransformer.java
@Override protected SessionViewModel transformCSVRecordToModel(CSVRecord record) { // ###(csv_headers) You can edit below this line ### final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.datePattern); formatter.withLocale(Locale.GERMANY); final SessionViewModel model = new SessionViewModel(); model.setId(Integer.parseInt(record.get("id"))); model.setSecret(record.get("secret")); return model; // ###(csv_headers) You can edit above this line ### }
From source file:org.cyberjos.jcconf2014.node.CloudNodeImpl.java
/** * Constructor./*from w w w . j a va 2s. c o m*/ */ public CloudNodeImpl() { this.nodeName = "Node-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss-SSS")); Runtime.getRuntime().addShutdownHook(new Thread(() -> { logger.info("Shutdown hook is invoked."); this.deactivate(); try { Thread.currentThread().join(); } catch (final Exception ex) { logger.warn("An error is occurred while shuting down.", ex); } Hazelcast.shutdownAll(); })); }