Example usage for java.time ZoneId systemDefault

List of usage examples for java.time ZoneId systemDefault

Introduction

In this page you can find the example usage for java.time ZoneId systemDefault.

Prototype

public static ZoneId systemDefault() 

Source Link

Document

Gets the system default time-zone.

Usage

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testIncreaseEventSeatsWithABoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);//w ww .  j  a v a 2 s .  c  o m
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 40, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(20, tickets.size());
    assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() != null).count());
}

From source file:org.silverpeas.core.calendar.notification.CalendarContributionReminderUserNotificationTest.java

@Test
public void durationReminderWithAnotherUserZoneIdOnSimpleEventOf2HoursShouldWork() throws Exception {
    receiver.getUserPreferences().setZoneId(ZoneId.of("Asia/Muscat"));
    final DurationReminder durationReminder = initReminderBuilder(
            setupSimpleEventOn2Hours(ZoneId.systemDefault())).triggerBefore(0, TimeUnit.MINUTE, "");
    triggerDateTime(durationReminder);//from ww  w  .j  a v a2  s  .  c o  m
    final Map<String, String> titles = computeNotificationTitles(durationReminder);
    assertThat(titles.get(DE), is("Reminder about the event super test - 21.02.2018 21:00 - 23:00 (UTC)"));
    assertThat(titles.get(EN), is("Reminder about the event super test - 02/21/2018 21:00 - 23:00 (UTC)"));
    assertThat(titles.get(FR), is("Rappel sur l'vnement super test - 21/02/2018 21:00 - 23:00 (UTC)"));
    final Map<String, String> contents = computeNotificationContents(durationReminder);
    assertThat(contents.get(DE),
            is("REMINDER: The event <b>super test</b> will be on 21.02.2018 from 21:00 to 23:00 (UTC)."));
    assertThat(contents.get(EN),
            is("REMINDER: The event <b>super test</b> will be on 02/21/2018 from 21:00 to 23:00 (UTC)."));
    assertThat(contents.get(FR),
            is("RAPPEL : L'vnement <b>super test</b> aura lieu le 21/02/2018 de 21:00  23:00 (UTC)."));
}

From source file:com.jsmartframework.web.manager.ExpressionHandler.java

private void setExpressionDate(String expr, String jParam) throws ServletException {
    if (isReadOnlyParameter(jParam)) {
        return;/*  w  ww  .  j a v a 2  s.co  m*/
    }

    Matcher matcher = EL_PATTERN.matcher(expr);
    if (matcher.find()) {

        String beanMethod = matcher.group(1);
        String[] methodSign = beanMethod.split(Constants.EL_SEPARATOR);

        if (methodSign.length > 0 && WebContext.containsAttribute(methodSign[0])) {
            beanMethod = String.format(Constants.JSP_EL, beanMethod);

            ELContext context = WebContext.getPageContext().getELContext();
            ValueExpression valueExpr = WebContext.getExpressionFactory().createValueExpression(context,
                    beanMethod, Object.class);
            String value = WebContext.getRequest().getParameter(TagHandler.J_DATE + jParam);

            if (StringUtils.isNotBlank(value)) {
                Throwable throwable = null;
                try {
                    valueExpr.setValue(context, value);
                    return;
                } catch (Exception ex) {
                    throwable = ex;
                }

                Long timeMillis = Long.parseLong(value);
                try {
                    valueExpr.setValue(context, new Date(timeMillis));
                    return;
                } catch (Exception ex) {
                    throwable = ex;
                }

                try {
                    valueExpr.setValue(context,
                            Instant.ofEpochMilli(timeMillis).atZone(ZoneId.systemDefault()).toLocalDateTime());
                    return;
                } catch (Exception ex) {
                    throwable = ex;
                }

                try {
                    valueExpr.setValue(context, new DateTime(timeMillis));
                    return;
                } catch (Exception ex) {
                    throwable = ex;
                }

                if (throwable != null) {
                    throw new ServletException(throwable.getMessage());
                }
            } else {
                valueExpr.setValue(context, null);
            }
        }
    }
}

From source file:com.github.aptd.simulation.datamodel.CXMLReader.java

/**
 * create the train list/*  ww w.  java 2 s . c  om*/
 *
 * @param p_network network component
 * @param p_agents map with agent asl scripts
 * @param p_factory factory
 * @return unmodifiable map with trains
 */
private static Pair<Map<String, ITrain<?>>, Map<String, IDoor<?>>> train(final Network p_network,
        final Map<String, String> p_agents, final IFactory p_factory, final ITime p_time,
        final double p_minfreetimetoclose) {
    final String l_dooragent = IStatefulElement.getDefaultAsl("door");
    final Map<String, IElement.IGenerator<ITrain<?>>> l_generators = new ConcurrentHashMap<>();
    final Set<IAction> l_actions = CCommon.actionsFromPackage().collect(Collectors.toSet());
    final IElement.IGenerator<IDoor<?>> l_doorgenerator = doorgenerator(p_factory, l_dooragent, l_actions,
            p_time);
    final Map<String, AtomicLong> l_doorcount = Collections.synchronizedMap(new HashMap<>());
    final Map<String, IDoor<?>> l_doors = Collections.synchronizedMap(new HashMap<>());
    return new ImmutablePair<>(
            Collections.<String, ITrain<?>>unmodifiableMap(
                    p_network.getTimetable().getTrains().getTrain().parallelStream()
                            .filter(i -> hasagentname(i.getAny3())).map(i -> agentname(i, i.getAny3()))
                            .map(i -> l_generators
                                    .computeIfAbsent(i.getRight(),
                                            a -> traingenerator(p_factory, p_agents.get(i.getRight()),
                                                    l_actions, p_time))
                                    .generatesingle(i.getLeft().getId(),
                                            i.getLeft().getTrainPartSequence().stream().flatMap(ref -> {
                                                // @todo support multiple train parts
                                                final EOcpTT[] l_tts = ((ETrainPart) ref.getTrainPartRef()
                                                        .get(0).getRef()).getOcpsTT().getOcpTT()
                                                                .toArray(new EOcpTT[0]);
                                                final CTrain.CTimetableEntry[] l_entries = new CTrain.CTimetableEntry[l_tts.length];
                                                for (int j = 0; j < l_tts.length; j++) {
                                                    final EArrivalDepartureTimes l_times = l_tts[j].getTimes()
                                                            .stream()
                                                            .filter(t -> t.getScope()
                                                                    .equalsIgnoreCase("published"))
                                                            .findAny().orElseThrow(() -> new CSemanticException(
                                                                    "missing published times"));
                                                    l_entries[j] = new CTrain.CTimetableEntry(
                                                            j < 1 ? 0.0
                                                                    : ((ETrack) l_tts[j - 1].getSectionTT()
                                                                            .getTrackRef().get(0).getRef())
                                                                                    .getTrackTopology()
                                                                                    .getTrackEnd().getPos()
                                                                                    .doubleValue(),
                                                            ((EOcp) l_tts[j].getOcpRef()).getId(),
                                                            l_tts[j].getStopDescription().getOtherAttributes()
                                                                    .getOrDefault(PLATFORM_REF_ATTRIBUTE, null),
                                                            l_times.getArrival() == null ? null
                                                                    : l_times.getArrival().toGregorianCalendar()
                                                                            .toZonedDateTime()
                                                                            .with(LocalDate.from(p_time
                                                                                    .current()
                                                                                    .atZone(ZoneId
                                                                                            .systemDefault())))
                                                                            .toInstant(),
                                                            l_times.getDeparture() == null ? null
                                                                    : l_times.getDeparture()
                                                                            .toGregorianCalendar()
                                                                            .toZonedDateTime()
                                                                            .with(LocalDate.from(p_time
                                                                                    .current()
                                                                                    .atZone(ZoneId
                                                                                            .systemDefault())))
                                                                            .toInstant());
                                                }
                                                return Arrays.stream(l_entries);
                                            }), i.getLeft().getTrainPartSequence().stream()
                                                    // @todo support multiple train parts
                                                    .map(s -> (ETrainPart) s.getTrainPartRef().get(0).getRef())
                                                    .map(p -> (EFormation) p.getFormationTT().getFormationRef())
                                                    .flatMap(f -> f.getTrainOrder().getVehicleRef().stream())
                                                    .map(r -> new ImmutablePair<BigInteger, TDoors>(
                                                            r.getVehicleCount(),
                                                            ((EVehicle) r.getVehicleRef()).getWagon()
                                                                    .getPassenger().getDoors()))
                                                    .flatMap(v -> IntStream
                                                            .range(0,
                                                                    v.getLeft().intValue() * v.getRight()
                                                                            .getNumber().intValue())
                                                            .mapToObj(j -> l_doors.computeIfAbsent("door-"
                                                                    + i.getLeft().getId() + "-"
                                                                    + l_doorcount
                                                                            .computeIfAbsent(i.getLeft()
                                                                                    .getId(),
                                                                                    id -> new AtomicLong(1L))
                                                                            .getAndIncrement(),
                                                                    id -> l_doorgenerator.generatesingle(id,
                                                                            i.getLeft().getId(),
                                                                            v.getRight().getEntranceWidth()
                                                                                    .doubleValue()
                                                                                    / v.getRight().getNumber()
                                                                                            .longValue(),
                                                                            p_minfreetimetoclose))))
                                                    .collect(Collectors.toList())))
                            .collect(Collectors.toMap(IElement::id, i -> i))),
            l_doors);
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testDecreaseEventSeatsWithAnUnboundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            false, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);//from w  w  w .jav  a2 s  .  com
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, tickets.size());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}

From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java

/**
 * Enriches existing scheduler job with the following data:
 * - sets current date as 'beginDate' if this parameter wasn't defined;
 * - sets current system time zone offset as 'timeZoneOffset' if this parameter wasn't defined.
 *
 * @param dto current scheduler job/*from ww  w .  jav  a  2  s.  c  om*/
 */
private void enrichSchedulerJobIfNecessary(SchedulerJobDTO dto) {
    if (Objects.isNull(dto.getBeginDate()) || StringUtils.isBlank(dto.getBeginDate().toString())) {
        dto.setBeginDate(LocalDate.now());
    }
    if (Objects.isNull(dto.getTimeZoneOffset()) || StringUtils.isBlank(dto.getTimeZoneOffset().toString())) {
        dto.setTimeZoneOffset(OffsetDateTime.now(ZoneId.systemDefault()).getOffset());
    }
}

From source file:sopho.Ofeloumenoi.EditOfeloumenoiController.java

@FXML
public void Save(ActionEvent event) throws IOException {

    if (barcode.getText().isEmpty() || onoma.getText().isEmpty() || eponimo.getText().isEmpty()
            || patronimo.getText().isEmpty()) { //checking if the user has filled the required fields

        sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                "?!",
                "  ?   ? .  ?  ?   Barcode, ,   ? ?  ?  ?",
                "error");
        cm.showAndWait();//w ww  .ja v  a2  s . c  o m

    } else if (!NumberUtils.isNumber(barcode.getText()) && !barcode.getText().isEmpty()) {
        sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                "?!",
                "  barcode ?  ?  ??. ?    ?  .",
                "error");
        cm.showAndWait();
    } else if (!NumberUtils.isNumber(eisodima.getText()) && !eisodima.getText().isEmpty()) {
        sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                "?!",
                "   ?  ?  ??. ?    ?  .",
                "error");
        cm.showAndWait();
    } else {//the user has filled the required fields. We can proceed.
        sopho.DBClass db = new sopho.DBClass();
        Connection conn = null;
        PreparedStatement pst = null;
        ResultSet rset = null;

        String teknaDB = ""; //we create a var to push data to db.
        for (int i = 0; i < tekna.getItems().size(); i++) {//we are converting the table rows to a single comma separated string to push it to the database in a single entry.
            tableManager tbl = (tableManager) tekna.getItems().get(i);
            if (!tbl.getEtos().equals("?  ")) { //we are checking if the user has actually entered a number
                teknaDB += tbl.getEtos() + ","; //we have to call getEtos from the tableManager class to get the actual value. We add the value to teknaDB and seperate with comma.
                arithmosTeknon++;
            }
        }
        if (arithmosTeknon > 0) {// we need to catch the case that the user has not added any data to the table.
            teknaDB = teknaDB.substring(0, teknaDB.length() - 1); // we have to remove the last comma.
        }
        conn = db.ConnectDB();

        try {
            // we can push the data to database...
            String sql = "UPDATE ofeloumenoi SET barcode=?, eponimo=?, onoma=?, patronimo=?, mitronimo=?, imGennisis=?, dieuthinsi=?, dimos=?, tilefono=?, anergos=?, epaggelma=?, eisodima=?, eksartiseis=?, photoID=?, afm=?, tautotita=?, ethnikotita=?, metanastis=?, roma=?, oikKatastasi=?, hasTekna=?, arithmosTeknon=?, ilikiesTeknon=?, politeknos=?, monogoneiki=?, mellousaMama=?, amea=?, asfForeas=?, xronios=?, pathisi=?, anoTon60=?, monaxikos=?, emfiliVia=?, spoudastis=?, anenergos=?, loipa=? WHERE barcode=?";
            pst = conn.prepareStatement(sql);
            //now we will set the values to the sql statement
            pst.setString(1, barcode.getText());
            pst.setString(2, eponimo.getText());
            pst.setString(3, onoma.getText());
            pst.setString(4, patronimo.getText());
            pst.setString(5, mitronimo.getText());
            //now we have to convert the imGennisis to a suitable format to be able to push it to the database
            if (imGennisis.getValue() != null) {
                Date date = Date.from(imGennisis.getValue().atStartOfDay(ZoneId.systemDefault()).toInstant());
                java.sql.Date sqlDate = new java.sql.Date(date.getTime());
                pst.setDate(6, sqlDate);
            } else {
                pst.setDate(6, null);
            }
            pst.setString(7, dieuthinsi.getText());
            pst.setString(8, dimos.getText());
            pst.setString(9, tilefono.getText());
            pst.setInt(10, anergos.isSelected() ? 1 : 0); //set 1 if selected and 0 if not. We will use this method for all the checkboxes.
            pst.setString(11, epaggelma.getText());
            pst.setString(12, eisodima.getText());
            pst.setString(13, eksartiseis.getText());
            pst.setString(14, PhotoID);
            pst.setString(15, afm.getText());
            pst.setString(16, tautotita.getText());
            pst.setString(17, ethnikotita.getText());
            pst.setInt(18, metanastis.isSelected() ? 1 : 0);
            pst.setInt(19, roma.isSelected() ? 1 : 0);
            pst.setInt(20, (int) oikKatastasi.getSelectionModel().getSelectedIndex());//we are pushing to database the selected index
            pst.setInt(21, arithmosTeknon > 0 ? 1 : 0); //checking number of tekna. if >0 has tekna gets 1
            pst.setInt(22, arithmosTeknon);
            pst.setString(23, teknaDB); //here we use the converted to comma separated values variable in order to save the tableView data using only one field in database.
            pst.setInt(24, politeknos.isSelected() ? 1 : 0);
            pst.setInt(25, monogoneiki.isSelected() ? 1 : 0);
            pst.setInt(26, mellousaMama.isSelected() ? 1 : 0);
            pst.setInt(27, amea.isSelected() ? 1 : 0);
            pst.setInt(28, (int) asfForeas.getSelectionModel().getSelectedIndex());//we are pushing to database the selected index
            pst.setInt(29, xronios.isSelected() ? 1 : 0);
            pst.setString(30, pathisi.getText());
            pst.setInt(31, monaxiko.isSelected() ? 1 : 0);
            pst.setInt(32, anoTon60.isSelected() ? 1 : 0);
            pst.setInt(33, emfiliVia.isSelected() ? 1 : 0);
            pst.setInt(34, spoudastis.isSelected() ? 1 : 0);
            pst.setInt(35, anenergos.isSelected() ? 1 : 0);
            pst.setString(36, loipa.getText());

            pst.setString(37, oldBarcode); // we update the values to the database table where barcode = oldBarcode

            System.out.println("the query is:" + pst.toString());
            int linesAffected = pst.executeUpdate();

            //checking if the data were inserted to the database successfully
            if (linesAffected > 0) {
                sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                        "!",
                        "   ?  ?  , ?     .",
                        "confirm");
                cm.showAndWait();

                if (le.LockEditing(false, selID, "ofeloumenoi")) {
                    Stage stage = (Stage) barcode.getScene().getWindow();
                    sl.StageLoad("/sopho/Ofeloumenoi/OfeloumenoiMain.fxml", stage, true, false); //resizable true, utility false
                } else {
                    sopho.Messages.CustomMessageController cm2 = new sopho.Messages.CustomMessageController(
                            null, "?",
                            "   ?  ?  ?.      ?   ? .   ?  ? ?    ??.",
                            "error");
                    cm2.showAndWait();
                }
            } else {//problem inserting data...
                sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                        "?!",
                        "   ?  ??   . ?  ...",
                        "error");
                cm.showAndWait();
            }
        } catch (SQLException e) {
            System.out.println(
                    "?     ?   ?  !"
                            + e);
        }
    }
}

From source file:alfio.manager.EventManagerIntegrationTest.java

@Test
public void testDecreaseEventSeatsWithABoundedCategory() {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null,
            "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()),
            new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "",
            true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager,
            eventRepository);/*  ww w  .jav  a2s. c om*/
    Event event = pair.getKey();
    EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null,
            null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0",
            ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()),
            DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(),
            event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(),
            null, event.isFreeOfCharge(), null, 7, null, null);
    eventManager.updateEventPrices(event, update, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(10, tickets.size());
    assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() != null));
}

From source file:com.esri.geoportal.harvester.agp.AgpOutputBroker.java

private String fromatDate(Date date) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    return FORMATTER.format(zonedDateTime);
}

From source file:com.esri.geoportal.commons.csw.client.impl.Client.java

/**
 * Formats ISO date./*ww w  . java2s  .  c  o  m*/
 * @param date date to format
 * @return ISO date
 */
private static String formatIsoDate(Date date) {
    ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
    return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(zonedDateTime);
}