List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceTest.java
private DavResource createDavResourceFrom(OwncloudTestResourceImpl owncloudResource, Locale locale) { URI prefixedHref = resolveAsFileURI(owncloudResource.getHref()); String contentLanguage = Optional.ofNullable(locale).map(loc -> loc.getLanguage()).orElse(null); String name = owncloudResource.getBackendName(); String eTag = owncloudResource.getBackendETag(); Date davResourceDate = new Date(); if (owncloudResource.getLastModifiedAt() != null) { davResourceDate = Date/*w w w . j ava 2s . c o m*/ .from(owncloudResource.getLastModifiedAt().atZone(ZoneId.systemDefault()).toInstant()); } if (isRoot(owncloudResource.getHref())) { eTag = null; } try { return new OwncloudDavResource(prefixedHref.getPath(), davResourceDate, davResourceDate, owncloudResource.getMediaType().toString(), owncloudResource instanceof OwncloudFileResource ? ((OwncloudFileResource) owncloudResource).getContentLength() : null, eTag, name, contentLanguage); } catch (URISyntaxException e) { throw new IllegalArgumentException("DavResource couldn't be built by OwncloudResource", e); } }
From source file:org.jboss.as.test.integration.web.session.SessionManagementTestCase.java
@Test public void testSessionManagementOperations() throws Exception { try (CloseableHttpClient client = HttpClients.createDefault()) { ModelNode operation = new ModelNode(); operation.get(ModelDescriptionConstants.OP).set(LIST_SESSIONS); operation.get(ModelDescriptionConstants.OP_ADDR).set(PathAddress .parseCLIStyleAddress("/deployment=management.war/subsystem=undertow").toModelNode()); ModelNode opRes = managementClient.getControllerClient().execute(operation); Assert.assertEquals(opRes.toString(), "success", opRes.get(ModelDescriptionConstants.OUTCOME).asString()); Assert.assertEquals(Collections.emptyList(), opRes.get(ModelDescriptionConstants.RESULT).asList()); long c1 = System.currentTimeMillis(); HttpGet get = new HttpGet("http://" + TestSuiteEnvironment.getServerAddress() + ":8080/management/SessionPersistenceServlet"); HttpResponse res = client.execute(get); long c2 = System.currentTimeMillis(); String sessionId = null;//from www . j av a2 s. co m for (Header cookie : res.getHeaders("Set-Cookie")) { if (cookie.getValue().startsWith("JSESSIONID=")) { sessionId = cookie.getValue().split("=")[1].split("\\.")[0]; break; } } Assert.assertNotNull(sessionId); opRes = managementClient.getControllerClient().execute(operation); Assert.assertEquals(opRes.toString(), "success", opRes.get(ModelDescriptionConstants.OUTCOME).asString()); Assert.assertEquals(opRes.toString(), Collections.singletonList(new ModelNode(sessionId)), opRes.get(ModelDescriptionConstants.RESULT).asList()); operation.get(SESSION_ID).set(sessionId); opRes = executeOperation(operation, GET_SESSION_CREATION_TIME_MILLIS); long time1 = opRes.get(ModelDescriptionConstants.RESULT).asLong(); Assert.assertTrue(c1 <= time1); Assert.assertTrue(time1 <= c2); opRes = executeOperation(operation, GET_SESSION_CREATION_TIME); long sessionCreationTime = LocalDateTime .parse(opRes.get(ModelDescriptionConstants.RESULT).asString(), DateTimeFormatter.ISO_DATE_TIME) .toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli(); Assert.assertEquals(time1, sessionCreationTime); opRes = executeOperation(operation, GET_SESSION_LAST_ACCESSED_TIME_MILLIS); Assert.assertEquals(time1, opRes.get(ModelDescriptionConstants.RESULT).asLong()); opRes = executeOperation(operation, GET_SESSION_LAST_ACCESSED_TIME); long aTime2 = LocalDateTime .parse(opRes.get(ModelDescriptionConstants.RESULT).asString(), DateTimeFormatter.ISO_DATE_TIME) .toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli(); Assert.assertEquals(time1, aTime2); Assert.assertEquals(sessionCreationTime, aTime2); opRes = executeOperation(operation, LIST_SESSION_ATTRIBUTE_NAMES); List<ModelNode> resultList = opRes.get(ModelDescriptionConstants.RESULT).asList(); Assert.assertEquals(1, resultList.size()); Assert.assertEquals(opRes.toString(), "val", resultList.get(0).asString()); opRes = executeOperation(operation, LIST_SESSION_ATTRIBUTES); List<Property> properties = opRes.get(ModelDescriptionConstants.RESULT).asPropertyList(); Assert.assertEquals(opRes.toString(), 1, properties.size()); Property property = properties.get(0); Assert.assertEquals(opRes.toString(), "val", property.getName()); Assert.assertEquals(opRes.toString(), "0", property.getValue().asString()); //we want to make sure that the values will be different //so we wait 10ms Thread.sleep(10); long a1 = System.currentTimeMillis(); client.execute(get); long a2 = System.currentTimeMillis(); do { //because the last access time is updated after the request returns there is a possible race here //to get around this we execute this op in a loop and wait for the value to change //in 99% of cases this will only iterate once //because of the 10ms sleep above they should ways be different //we have a max wait time of 1s if something goes wrong opRes = executeOperation(operation, GET_SESSION_LAST_ACCESSED_TIME_MILLIS); time1 = opRes.get(ModelDescriptionConstants.RESULT).asLong(); if (time1 != sessionCreationTime) { break; } } while (System.currentTimeMillis() < a1 + 1000); Assert.assertTrue(a1 <= time1); Assert.assertTrue(time1 <= a2); opRes = executeOperation(operation, GET_SESSION_LAST_ACCESSED_TIME); long time2 = LocalDateTime .parse(opRes.get(ModelDescriptionConstants.RESULT).asString(), DateTimeFormatter.ISO_DATE_TIME) .toInstant(ZoneId.systemDefault().getRules().getOffset(Instant.now())).toEpochMilli(); Assert.assertEquals(time1, time2); operation.get(ATTRIBUTE).set("val"); opRes = executeOperation(operation, GET_SESSION_ATTRIBUTE); Assert.assertEquals("1", opRes.get(ModelDescriptionConstants.RESULT).asString()); executeOperation(operation, INVALIDATE_SESSION); opRes = executeOperation(operation, LIST_SESSIONS); Assert.assertEquals(Collections.emptyList(), opRes.get(ModelDescriptionConstants.RESULT).asList()); } }
From source file:com.buffalokiwi.api.APIDate.java
/** * Create a new APIDate using the local system offset * @param date date to use //from w w w. ja va2 s . c o m */ public APIDate(final Date date) { if (date == null) throw new IllegalArgumentException("date can't be null"); this.date = date.toInstant().atZone(ZoneId.systemDefault()); offset = ZoneId.systemDefault().getRules().getOffset(date.toInstant()); }
From source file:org.codice.ddf.admin.insecure.defaults.service.DefaultUsersDeletionScheduler.java
private String cronCalculator(Instant firstInstall) { Instant threeDayTimestamp = firstInstall.plus(Duration.ofDays(3).minus(Duration.ofMinutes(30))); LocalDateTime localDateTime = LocalDateTime.ofInstant(threeDayTimestamp, ZoneId.systemDefault()); return String.format("%d+%d+%d+%d+%d+?+%d", localDateTime.getSecond(), localDateTime.getMinute(), localDateTime.getHour(), localDateTime.getDayOfMonth(), localDateTime.getMonthValue(), localDateTime.getYear());/*from w w w . j ava 2 s.c om*/ }
From source file:org.openmrs.module.operationtheater.api.impl.OperationTheaterServiceImpl.java
@Override public Interval getLocationAvailableTime(Location location, LocalDate date) { Date date1 = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()); Date date2 = Date.from(date.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); List<AppointmentBlock> blocks = appointmentService.getAppointmentBlocks(date1, date2, location.getId() + ",", null, null); // List<AppointmentBlock> blocks = new ArrayList<AppointmentBlock>(); if (blocks.size() == 1) { // return new Interval(new DateTime(blocks.get(0).getStartDate()), new DateTime(blocks.get(0).getEndDate())); Instant startInstant = LocalDateTime.from(blocks.get(0).getStartDate().toInstant()) .toInstant(ZoneOffset.UTC); Instant endInstant = LocalDateTime.from(blocks.get(0).getEndDate().toInstant()) .toInstant(ZoneOffset.UTC); return Interval.of(startInstant, endInstant); } else if (blocks.size() > 1) { throw new APIException("There shouldn't be multiple appointment blocks per location and date"); }/* ww w. jav a 2 s . c o m*/ DateTimeFormatter timeFormatter = OTMetadata.AVAILABLE_TIME_FORMATTER; LocalDateTime availableStart = null; LocalDateTime availableEnd = null; for (LocationAttribute attribute : location.getAttributes()) { if (attribute.getAttributeType().getUuid().equals(OTMetadata.DEFAULT_AVAILABLE_TIME_BEGIN_UUID)) { LocalTime beginTime = LocalTime.parse((String) attribute.getValue(), timeFormatter); // availableStart = date.withTime(beginTime.getHourOfDay(), beginTime.getMinuteOfHour(), 0, 0); availableStart = date.atTime(beginTime.getHour(), beginTime.getMinute()); } else if (attribute.getAttributeType().getUuid().equals(OTMetadata.DEFAULT_AVAILABLE_TIME_END_UUID)) { LocalTime endTime = LocalTime.parse((String) attribute.getValue(), timeFormatter); // availableEnd = date.withTime(endTime.getHourOfDay(), endTime.getMinuteOfHour(), 0, 0); availableEnd = date.atTime(endTime.getHour(), endTime.getMinute()); } } if (availableStart != null && availableEnd != null) { return Interval.of(availableStart.toInstant(ZoneOffset.UTC), availableEnd.toInstant(ZoneOffset.UTC)); } throw new APIException("Available times not defined. please make sure that the attributes " + "'default available time begin' and 'default available time end' for the location " + location.getName() + " are defined"); }
From source file:eu.hansolo.tilesfx.tools.Location.java
public ZonedDateTime getZonedDateTime() { return getZonedDateTime(ZoneId.systemDefault()); }
From source file:org.opendatakit.briefcase.util.ExportAction.java
public static List<String> export(BriefcaseFormDefinition formDefinition, ExportConfiguration configuration, TerminationFuture terminationFuture) { List<String> errors = new ArrayList<>(); Optional<File> pemFile = configuration.mapPemFile(Path::toFile).filter(File::exists); if ((formDefinition.isFileEncryptedForm() || formDefinition.isFieldEncryptedForm()) && !pemFile.isPresent()) errors.add(formDefinition.getFormName() + " form is encrypted"); else/* ww w . java 2 s.com*/ try { export(configuration.mapExportDir(Path::toFile) .orElseThrow(() -> new RuntimeException("Wrong export configuration")), ExportType.CSV, formDefinition, pemFile.orElse(null), terminationFuture, configuration.mapStartDate( (LocalDate ld) -> Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant())) .orElse(null), configuration.mapEndDate( (LocalDate ld) -> Date.from(ld.atStartOfDay(ZoneId.systemDefault()).toInstant())) .orElse(null)); } catch (IOException ex) { errors.add("Export of form " + formDefinition.getFormName() + " has failed: " + ex.getMessage()); } return errors; }
From source file:alfio.controller.api.admin.EventApiController.java
@RequestMapping(value = "/events", method = GET, headers = "Authorization") public List<EventListItem> getAllEventsForExternal(Principal principal, HttpServletRequest request) { List<Integer> userOrganizations = userManager.findUserOrganizations(principal.getName()).stream() .map(Organization::getId).collect(toList()); return eventManager.getActiveEvents().stream() .filter(e -> userOrganizations.contains(e.getOrganizationId())) .sorted(Comparator.comparing(e -> e.getBegin().withZoneSameInstant(ZoneId.systemDefault()))) .map(s -> new EventListItem(s, request.getContextPath(), descriptionsLoader.eventDescriptions())) .collect(toList());/*from w ww .j a va 2 s. c om*/ }
From source file:de.sainth.recipe.backend.security.AuthFilter.java
private Cookie createCookie(RecipeManagerAuthenticationToken authentication, boolean secure) { String newToken = Jwts.builder() // .compressWith(new GzipCompressionCodec()) .setSubject(authentication.getPrincipal().toString()) .setExpiration(/*from w w w .j ava 2 s . com*/ Date.from(LocalDateTime.now().plusMinutes(30).atZone(ZoneId.systemDefault()).toInstant())) .claim(TOKEN_ROLE, authentication.getAuthorities().get(0).getAuthority()).setIssuedAt(new Date()) .signWith(SignatureAlgorithm.HS256, key).compact(); Cookie cookie = new Cookie(COOKIE_NAME, newToken); cookie.setSecure(secure); cookie.setHttpOnly(true); cookie.setMaxAge(30 * 60); return cookie; }
From source file:com.buffalokiwi.api.APIDate.java
/** * Retrieve the date in the local time zone * @return zoned time// ww w .j a v a2 s .c o m */ @Override public ZonedDateTime getLocalDate() { return date.withZoneSameInstant(ZoneId.systemDefault()); }