List of usage examples for java.time ZonedDateTime now
public static ZonedDateTime now(Clock clock)
From source file:org.openlmis.fulfillment.util.DateHelper.java
/** * Obtains the current date time from the system clock in the system time zone. * @return the current date time using the system clock *///from ww w.j ava 2s .c om public ZonedDateTime getCurrentDateTimeWithSystemZone() { return ZonedDateTime.now(clock); }
From source file:fi.helsinki.opintoni.service.TimeService.java
public String nowUTCAsString() { ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC); return utc.format(DateTimeFormatter.ISO_INSTANT); }
From source file:no.digipost.api.useragreements.client.filters.request.RequestDateInterceptor.java
private void setDateHeader(final HttpRequest httpRequest) { String dateOnRFC1123Format = DateUtils.formatDate(ZonedDateTime.now(GMT)); httpRequest.setHeader(DATE, dateOnRFC1123Format); log.debug(getClass().getSimpleName() + " satt headeren " + DATE + "=" + dateOnRFC1123Format); }
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.// ww w. j a v a 2 s . co 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:stroom.util.test.StroomTestUtil.java
public static File createUniqueTestDir(final File parentDir) throws IOException { if (!parentDir.isDirectory()) { throw new IOException( "The parent directory '" + FileUtil.getCanonicalPath(parentDir) + "' does not exist"); }//from w w w . j av a2s. c o m File dir = null; for (int i = 0; i < 100; i++) { dir = new File(parentDir, FORMAT.format(ZonedDateTime.now(ZoneOffset.UTC))); if (dir.mkdir()) { break; } else { dir = null; ThreadUtil.sleep(100); } } if (dir == null) { throw new IOException("Unable to create unique test dir in: " + FileUtil.getCanonicalPath(parentDir)); } return dir; }
From source file:keywhiz.auth.cookie.AuthenticatedEncryptedCookieFactoryTest.java
@Before public void setUp() { CookieConfig config = new CookieConfig(); config.setName("session"); cookieFactory = new AuthenticatedEncryptedCookieFactory(clock, MAPPER, ENCRYPTOR, config); validCookie = cookieFactory.getSessionCookie(USER, ZonedDateTime.now(clock)).toString(); expiredCookie = cookieFactory.getExpiredSessionCookie().toString(); }
From source file:alfio.util.EventUtil.java
public static boolean checkWaitingQueuePreconditions(Event event, List<SaleableTicketCategory> categories, ConfigurationManager configurationManager, Predicate<Event> noTicketsAvailable) { return findLastCategory(categories).map(lastCategory -> { ZonedDateTime now = ZonedDateTime.now(event.getZoneId()); if (isPreSales(event, categories)) { return configurationManager.getBooleanConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_PRE_REGISTRATION), false);/*w ww. ja v a 2 s . c om*/ } else if (configurationManager.getBooleanConfigValue( Configuration.from(event.getOrganizationId(), event.getId(), ENABLE_WAITING_QUEUE), false)) { return now.isBefore(lastCategory.getZonedExpiration()) && noTicketsAvailable.test(event); } return false; }).orElse(false); }
From source file:alfio.controller.api.support.PublicCategory.java
public boolean isActive() { ZonedDateTime now = ZonedDateTime.now(Clock.systemUTC()); return category.getUtcInception().isBefore(now) && now.isBefore(category.getUtcExpiration()); }
From source file:stroom.pipeline.server.writer.PathCreator.java
public static String replaceTimeVars(String path) { // Replace some of the path elements with system variables. final ZonedDateTime dateTime = ZonedDateTime.now(ZoneOffset.UTC); path = replace(path, "year", dateTime.getYear(), 4); path = replace(path, "month", dateTime.getMonthValue(), 2); path = replace(path, "day", dateTime.getDayOfMonth(), 2); path = replace(path, "hour", dateTime.getHour(), 2); path = replace(path, "minute", dateTime.getMinute(), 2); path = replace(path, "second", dateTime.getSecond(), 2); path = replace(path, "millis", dateTime.toInstant().toEpochMilli(), 3); path = replace(path, "ms", dateTime.toInstant().toEpochMilli(), 0); return path;//from w ww .j av a 2 s . c o m }
From source file:alfio.controller.api.support.PublicCategory.java
public boolean isFutureSale() { return ZonedDateTime.now(Clock.systemUTC()).isBefore(category.getUtcInception()); }