Example usage for java.time LocalTime of

List of usage examples for java.time LocalTime of

Introduction

In this page you can find the example usage for java.time LocalTime of.

Prototype

public static LocalTime of(int hour, int minute) 

Source Link

Document

Obtains an instance of LocalTime from an hour and minute.

Usage

From source file:com.thinkenterprise.domain.BoundedContextInitializer.java

private void initRoutes() {

    // Mnchen-Houston LH7902
    ///*  w w  w.j  ava 2s  .  c o m*/
    Route route = new Route("LH7902", "MUC", "IAH");
    route.addScheduledDaily();
    route.setDepartureTime(LocalTime.of(9, 30));
    route.setArrivalTime(LocalTime.of(14, 00));

    // Flug am 23.09.2015
    Flight flight = new Flight(120.45, LocalDate.of(2015, 9, 23));
    flight.addEmployee("Fred");
    flight.addEmployee("Sarah");
    route.addFlight(flight);

    // Flug am 24.09.2015
    flight = new Flight(111.45, LocalDate.of(2015, 9, 24));
    route.addFlight(flight);

    routeRepository.save(route);

    // Mnchen-Ibiza LH1602
    //
    route = new Route("LH1602", "MUC", "IBZ");
    route.addScheduledWeekday(DayOfWeek.SATURDAY);
    route.setDepartureTime(LocalTime.of(8, 50));
    route.setArrivalTime(LocalTime.of(11, 15));

    flight = new Flight(120.45, LocalDate.of(2015, 9, 19));
    route.addFlight(flight);

    routeRepository.save(route);

    // Mnchen-Ibiza LH1838
    //
    route = new Route("LH1838", "MUC", "IBZ");
    route.addScheduledWeekday(DayOfWeek.MONDAY);
    route.addScheduledWeekday(DayOfWeek.THURSDAY);
    route.addScheduledWeekday(DayOfWeek.SATURDAY);
    route.setDepartureTime(LocalTime.of(12, 25));
    route.setArrivalTime(LocalTime.of(14, 50));

    flight = new Flight(120.45, LocalDate.of(2015, 9, 19));
    route.setAircraft("D-AIPA");
    route.addFlight(flight);

    routeRepository.save(route);

    // Mnchen-New York LH401
    //
    route = new Route("LH401", "FRA", "NYC");
    route.addScheduledDaily();
    route.setDepartureTime(LocalTime.of(15, 55));
    route.setArrivalTime(LocalTime.of(5, 30));

    flight = new Flight(120.45, LocalDate.of(2015, 9, 30));
    route.setAircraft("D-AIPA");
    route.addFlight(flight);

    routeRepository.save(route);
}

From source file:de.msg.repository.driver.DefaultRouteRepositoryDriver.java

@PostConstruct
public void initRoutesList() {
    for (short i = 0; i < routeCount; i++) {
        String flightNumber = flightNumberList.get(i);
        String departure = departureList.get(i);
        String destination = destinationList.get(i);

        Route route = new Route(flightNumber, departure, destination);
        route.setId(new Long(i + 1));
        route.addScheduledDaily();//from www  .  j  ava2s . c o m
        route.setDepartureTime(LocalTime.of(9 + i, 30));
        route.setArrivalTime(LocalTime.of(14 + i, 0));
        routeList.add(route);
    }
}

From source file:de.lgblaumeiser.ptm.rest.AnalysisControllerTest.java

@Test
public void test() throws Exception {
    ActivityRestController.ActivityBody data = new ActivityRestController.ActivityBody();
    data.activityName = "MyTestActivity";
    data.bookingNumber = "0815";
    mockMvc.perform(//from w w  w .  j a v a2s .c o  m
            post("/activities").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(data)))
            .andDo(print()).andExpect(status().isCreated());

    LocalDate date = LocalDate.now();
    String dateString = date.format(ISO_LOCAL_DATE);
    BookingRestController.BookingBody booking = new BookingRestController.BookingBody();
    booking.activityId = "1";
    booking.user = "TestUser";
    booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME);
    booking.endtime = LocalTime.of(16, 45).format(ISO_LOCAL_TIME);
    booking.comment = "";
    mockMvc.perform(post("/bookings/" + dateString).contentType(APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated());

    mockMvc.perform(get("/analysis/hours/" + dateString.substring(0, 7))).andDo(print())
            .andExpect(status().isOk()).andExpect(content().string(containsString(dateString)))
            .andExpect(content().string(containsString("08:15")))
            .andExpect(content().string(containsString("16:45")))
            .andExpect(content().string(containsString("08:30")))
            .andExpect(content().string(containsString("00:00")));

    mockMvc.perform(get("/analysis/projects/" + dateString.substring(0, 7))).andDo(print())
            .andExpect(status().isOk()).andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("08,50")))
            .andExpect(content().string(containsString("100")))
            .andExpect(content().string(containsString("8")));

}

From source file:com.epam.ta.reportportal.database.search.FilterRules.java

public static Predicate<String> timeStamp() {
    return value -> {
        if (value == null) {
            return false;
        }//w w  w.  ja v  a2s .c o m
        try {
            long offset = Long.parseLong(value);
            LocalDateTime.of(LocalDate.now(), LocalTime.of(0, 0)).plusMinutes(offset);
        } catch (NumberFormatException | DateTimeException e) {
            return false;
        }
        return true;
    };
}

From source file:de.lgblaumeiser.ptm.rest.BookingControllerTest.java

@Test
public void testRoundtripCreateAndRetrieveBooking() throws Exception {
    ActivityRestController.ActivityBody data = new ActivityRestController.ActivityBody();
    data.activityName = "MyTestActivity";
    data.bookingNumber = "0815";
    mockMvc.perform(/* w w w .  j  a va 2  s .  co m*/
            post("/activities").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(data)))
            .andDo(print()).andExpect(status().isCreated());

    LocalDate date = LocalDate.now();
    String dateString = date.format(ISO_LOCAL_DATE);
    BookingRestController.BookingBody booking = new BookingRestController.BookingBody();
    booking.activityId = "1";
    booking.user = "TestUser";
    booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME);
    booking.comment = "";
    mockMvc.perform(post("/bookings/" + dateString).contentType(APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated());

    mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString(dateString)));

    mockMvc.perform(get("/bookings/" + dateString)).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString("MyTestActivity")))
            .andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("TestUser")))
            .andExpect(content().string(containsString("starttime")));

    mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString("MyTestActivity")))
            .andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("TestUser")))
            .andExpect(content().string(containsString("starttime")));

    booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME);
    mockMvc.perform(post("/bookings/" + dateString + "/1").contentType(APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isOk());

    mockMvc.perform(get("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString("MyTestActivity")))
            .andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("TestUser")))
            .andExpect(content().string(containsString("starttime")))
            .andExpect(content().string(containsString("endtime")));

    LocalDate date2 = date.minusDays(1);
    String dateString2 = date2.format(ISO_LOCAL_DATE);

    booking = new BookingRestController.BookingBody();
    booking.activityId = "1";
    booking.user = "TestUser";
    booking.starttime = LocalTime.of(8, 15).format(ISO_LOCAL_TIME);
    booking.endtime = LocalTime.of(16, 30).format(ISO_LOCAL_TIME);
    booking.comment = "Test Comment";
    mockMvc.perform(post("/bookings/" + dateString2).contentType(APPLICATION_JSON)
            .content(objectMapper.writeValueAsString(booking))).andDo(print()).andExpect(status().isCreated());

    mockMvc.perform(get("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString("MyTestActivity")))
            .andExpect(content().string(containsString("0815")))
            .andExpect(content().string(containsString("TestUser")))
            .andExpect(content().string(containsString("Test Comment")))
            .andExpect(content().string(containsString("starttime")))
            .andExpect(content().string(containsString("endtime")));

    mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString(dateString)))
            .andExpect(content().string(containsString(dateString2)));

    mockMvc.perform(delete("/bookings/" + dateString + "/1")).andDo(print()).andExpect(status().isOk());
    mockMvc.perform(delete("/bookings/" + dateString2 + "/2")).andDo(print()).andExpect(status().isOk());

    mockMvc.perform(get("/bookings")).andDo(print()).andExpect(status().isOk())
            .andExpect(content().string(containsString("[]")));
}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * Get a User via given username or email
 *
 * @param input can be an email or username
 * @return The requested User (or a exception is thrown)
 *//*  w  w  w . j ava 2  s . c o  m*/
public static User getUser(String input) throws UserNotFoundException {
    String sql;
    if (input.contains("@")) {
        if (USERS_PER_EMAIL.containsKey(input)) {
            User u = USERS_PER_EMAIL.get(input);
            addUser(u);
            return u;
        }
        sql = "SELECT * FROM " + Tables.USER + " WHERE " + Columns.EMAIL + " = ?";
    } else {
        if (USERS_PER_USERNAME.containsKey(input)) {
            User u = USERS_PER_USERNAME.get(input);
            addUser(u);
            return u;
        }
        sql = "SELECT * FROM " + Tables.USER + " WHERE " + Columns.USERNAME + " = ?";
    }
    User u = new User();
    try {
        PreparedStatement stat = Database.getConnection().prepareStatement(sql);
        stat.setString(1, input);
        ResultSet result = stat.executeQuery();
        if (result.next()) {
            u.setId(result.getInt(Columns.ID));
            u.setUsername(result.getString(Columns.USERNAME));
            u.setPassword(result.getString(Columns.PASSWORD));
            u.setSalt(result.getString(Columns.SALT));
            u.setEmail(result.getString(Columns.EMAIL));
            u.setFirstName(result.getString(Columns.FIRST_NAME));
            u.setLastName(result.getString(Columns.LAST_NAME));
            u.setRegistrationDate(result.getTimestamp(Columns.REGISTRATION_DATE).toLocalDateTime());
            u.setAccessLevel(result.getInt(Columns.STATUS));
            u.setActivationKey(result.getString(Columns.ACTIVATION_KEY));
            if (result.getInt(Columns.SEND_CLIPPING_MAIL) == 1) {
                u.setSendClippingMail(true);
            } else {
                u.setSendClippingMail(false);
            }
            u.setClippingTime(loadAllClippingSendTimes(u));
            if (u.getClippingTime().size() < 1) {
                addClippingSendTime(u, LocalTime.of(8, 0));
            }
        } else {
            throw new UserNotFoundException();
        }
    } catch (SQLException ex) {
        throw new UserNotFoundException();
    }
    UserUtils.addUser(u);
    u.setLastClipping(ClippingUtils.getLastClipping(u));
    return u;
}

From source file:msi.gama.util.GamaDate.java

public GamaDate(final IScope scope, final Temporal d) {
    final ZoneId zone;
    if (d instanceof ChronoZonedDateTime) {
        zone = ZonedDateTime.from(d).getZone();
    } else if (d.isSupported(ChronoField.OFFSET_SECONDS)) {
        zone = ZoneId.ofOffset("", ZoneOffset.ofTotalSeconds(d.get(ChronoField.OFFSET_SECONDS)));
    } else {//from w  ww  . j av  a2s .  c o  m
        zone = GamaDateType.DEFAULT_ZONE;
    }
    if (!d.isSupported(MINUTE_OF_HOUR)) {
        internal = ZonedDateTime.of(LocalDate.from(d), LocalTime.of(0, 0), zone);
    } else if (!d.isSupported(DAY_OF_MONTH)) {
        internal = ZonedDateTime.of(LocalDate.from(
                scope == null ? Dates.DATES_STARTING_DATE.getValue() : scope.getSimulation().getStartingDate()),
                LocalTime.from(d), zone);
    } else {
        internal = d;
    }
}

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

@Override
public void executeStartResourceJob(boolean isAppliedForClusters) {
    OffsetDateTime currentDateTime = OffsetDateTime.now();
    List<SchedulerJobData> jobsToStart = getSchedulerJobsForAction(UserInstanceStatus.RUNNING, currentDateTime,
            isAppliedForClusters);//from ww  w  . j  ava2  s. c om
    if (!jobsToStart.isEmpty()) {
        log.debug(isAppliedForClusters ? "Scheduler computational resource start job is executing..."
                : "Scheduler exploratory start job is executing...");
        log.info(CURRENT_DATETIME_INFO,
                LocalTime.of(currentDateTime.toLocalTime().getHour(),
                        currentDateTime.toLocalTime().getMinute()),
                currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek());
        log.info(isAppliedForClusters ? "Quantity of clusters for starting: {}"
                : "Quantity of exploratories for starting: {}", jobsToStart.size());
        jobsToStart
                .forEach(job -> changeResourceStatusTo(UserInstanceStatus.RUNNING, job, isAppliedForClusters));
    }

}

From source file:dhbw.clippinggorilla.objects.user.UserUtils.java

/**
 * Get a User via given id//from  w  w  w .  j av a  2 s .c o  m
 *
 * @param id The id of the requested User
 * @return The requested User (or a exception is thrown)
 */
public static User getUser(int id) throws UserNotFoundException {
    if (USERS_PER_ID.containsKey(id)) {
        User u = USERS_PER_ID.get(id);
        addUser(u);
        return u;
    }
    String sql = "SELECT * FROM " + Tables.USER + " WHERE " + Columns.ID + " = ?";
    User u = new User();
    try {
        PreparedStatement stat = Database.getConnection().prepareStatement(sql);
        stat.setInt(1, id);
        ResultSet result = stat.executeQuery();
        if (result.next()) {
            u.setId(result.getInt(Columns.ID));
            u.setUsername(result.getString(Columns.USERNAME));
            u.setPassword(result.getString(Columns.PASSWORD));
            u.setSalt(result.getString(Columns.SALT));
            u.setEmail(result.getString(Columns.EMAIL));
            u.setFirstName(result.getString(Columns.FIRST_NAME));
            u.setLastName(result.getString(Columns.LAST_NAME));
            u.setRegistrationDate(result.getTimestamp(Columns.REGISTRATION_DATE).toLocalDateTime());
            u.setAccessLevel(result.getInt(Columns.STATUS));
            u.setActivationKey(result.getString(Columns.ACTIVATION_KEY));
            if (result.getInt(Columns.SEND_CLIPPING_MAIL) == 1) {
                u.setSendClippingMail(true);
            } else {
                u.setSendClippingMail(false);
            }
            u.setClippingTime(loadAllClippingSendTimes(u));
            if (u.getClippingTime().size() < 1) {
                addClippingSendTime(u, LocalTime.of(8, 0));
            }
        } else {
            throw new UserNotFoundException();
        }
    } catch (SQLException ex) {
        throw new UserNotFoundException();
    }
    UserUtils.addUser(u);
    u.setLastClipping(ClippingUtils.getLastClipping(u));
    return u;
}

From source file:co.com.soinsoftware.hotelero.view.JFRoomPayment.java

private Date getFinalDate(final Date initialDate, final int hour) {
    final LocalDate today = LocalDate.now();
    LocalDateTime finalDateTime = null;
    if (DateUtils.isSameDay(initialDate, new Date())) {
        finalDateTime = today.plusDays(1).atTime(LocalTime.of(hour, 0));
    } else {//from w  ww. j  a va2s  .co m
        finalDateTime = today.atTime(LocalTime.of(hour, 0));
    }
    final ZonedDateTime zdt = finalDateTime.atZone(ZoneId.systemDefault());
    return Date.from(zdt.toInstant());
}