List of usage examples for java.time LocalTime parse
public static LocalTime parse(CharSequence text, DateTimeFormatter formatter)
From source file:Main.java
public static void main(String[] args) { LocalTime l = LocalTime.parse("12:34", DateTimeFormatter.ISO_LOCAL_TIME); System.out.println(l);/*from w ww. j av a 2 s .c om*/ }
From source file:Main.java
public static void main(String... args) { DateTimeFormatter germanFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT) .withLocale(Locale.GERMAN); LocalTime leetTime = LocalTime.parse("13:37", germanFormatter); System.out.println(leetTime); }
From source file:com.microsoft.sqlserver.testframework.sqlType.SqlTime.java
public Object createdata() { Time temp = new Time( ThreadLocalRandom.current().nextLong(((Time) minvalue).getTime(), ((Time) maxvalue).getTime())); String timeNano = temp.toString() + "." + RandomStringUtils.randomNumeric(this.precision); // can pass String rather than converting to loacTime, but leaving it // unchanged for now to handle prepared statements return LocalTime.parse(timeNano, formatter); }
From source file:controllers.TravelControllerTest.java
@Before public void setUp() throws Exception { mockMVC = MockMvcBuilders.standaloneSetup(new TravelController(databaseMock)).build(); when(userAuthenticationInterceptor.preHandle(any(HttpServletRequest.class), any(HttpServletResponse.class), any(Object.class))).thenReturn(Boolean.TRUE); user = new User("firstname", "lastname", "password1", "first.last@email.com", true); beginDate = LocalTime.parse("10:15:30", DateTimeFormatter.ISO_LOCAL_TIME); endDate = LocalTime.parse("12:15:30", DateTimeFormatter.ISO_LOCAL_TIME); startPoint = new Address(new Street("teststreet", new City("testcity", "1234", "BE")), 1, new Coordinate(50.0, 60.0)); endPoint = new Address(new Street("teststreet", new City("testcity", "1234", "BE")), 5, new Coordinate(55.0, 65.0)); recurring = new RepetitionWeek(); recurlist = new ArrayList<>(); recurlist.add(recurring);//ww w .j av a 2 s . c o m firstTravel = new Travel("travel1", beginDate, endDate, false, startPoint, endPoint, recurlist, new HashMap<>(), new ArrayList<>()); secondTravel = new Travel("travel2", beginDate, endDate, true, endPoint, startPoint, recurlist, new HashMap<>(), new ArrayList<>()); user.addTravel(1, firstTravel); user.addTravel(2, secondTravel); dto = new TravelDTO(); dto.setName("dtotravel"); timeInterval = new String[2]; timeInterval[0] = "08:15:30"; timeInterval[1] = "09:15:30"; dto.setTimeInterval(timeInterval); dto.setArrivalTime(false); dto.setRecurring(recurring.getAllWeek()); dto.setStartpoint(new AddressDTO("dtostart", "1", "dtocity", "DC", "1234", new CoordinateDTO(10.0, 20.0))); dto.setEndpoint(new AddressDTO("dtoend", "5", "dtocity", "DC", "1234", new CoordinateDTO(15.0, 25.0))); when(databaseMock.getUser(anyInt())).thenReturn(user); }
From source file:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java
public static LocalTime getTime(final String time, final DateTimeFormatter formatter) { return time != null ? LocalTime.parse(time, formatter) : null; }
From source file:com.haulmont.cuba.web.widgets.CubaTimeField.java
protected LocalTime parseValue(String text) { if (StringUtils.isNotEmpty(text) && !text.equals(placeholder)) { DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(); return LocalTime.parse(text, dateTimeFormatter); } else {//from w w w. j a v a2s .c o m return null; } }
From source file:org.thevortex.lighting.jinks.robot.Recurrence.java
/** * Parse from a partial ICAL string./*from w w w . j av a 2 s . c om*/ * * @param recurrenceString the string * @return a thing */ public static Recurrence parse(String recurrenceString) { if (recurrenceString == null) return null; Recurrence result = new Recurrence(); // each major part will be on a separate line String[] parts = recurrenceString.split("\\n"); // first one MUST be a "DTSTART;" or we're already fucked String working = checkAndStrip(DTSTART, parts[0]); result.startTime = LocalTime.parse(working, ICAL_DT); // if there are three parts, the second must be an end time if (parts.length == 3) { working = checkAndStrip(DTEND, parts[1]); LocalTime endsAt = LocalTime.parse(working, ICAL_DT); result.duration = Duration.between(result.startTime, endsAt); } // we always have a RRULE: first part is FREQ and if it's weekly, followed by BYDAY working = checkAndStrip(RRULE, parts[parts.length - 1]); parts = working.split(";"); // the type is first working = checkAndStrip(FREQ, parts[0]); result.frequency = Frequency.valueOf(working); // if it's weekly, there's more if (result.frequency == Frequency.WEEKLY) { SortedSet<DayOfWeek> list = new TreeSet<>(); working = checkAndStrip(BYDAY, parts[1]); for (String dayValue : working.split(",")) { for (DayOfWeek dow : DayOfWeek.values()) { if (dow.name().startsWith(dayValue)) { list.add(dow); break; } } } result.days = list; } return result; }
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"); }/*from w w w . j a v a 2s.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"); }