Example usage for java.time LocalDate atTime

List of usage examples for java.time LocalDate atTime

Introduction

In this page you can find the example usage for java.time LocalDate atTime.

Prototype

public LocalDateTime atTime(int hour, int minute) 

Source Link

Document

Combines this date with a time to create a LocalDateTime .

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);

    LocalDateTime l = a.atTime(2, 3);
    System.out.println(l);//from  w  w  w.j  av a  2s .co  m
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.of(2014, 6, 21);
    System.out.println(localDate);

    LocalDateTime localTime1 = localDate.atStartOfDay();
    System.out.println(localTime1);

    LocalDateTime localTime2 = localDate.atTime(16, 21);
    System.out.println(localTime2);
}

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.  ja va2  s.  c om*/

    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:org.tightblog.ui.restapi.WeblogEntryController.java

private Instant calculatePubTime(WeblogEntry entry) {
    Instant pubtime = null;//ww w  .  j  a v a 2s  . co m

    String dateString = entry.getDateString();
    if (!StringUtils.isEmpty(dateString)) {
        try {
            LocalDate newDate = LocalDate.parse(dateString, pubDateFormat);

            // Now handle the time from the hour, minute and second combos
            pubtime = newDate.atTime(entry.getHours(), entry.getMinutes()).atZone(entry.getWeblog().getZoneId())
                    .toInstant();
        } catch (Exception e) {
            log.error("Error calculating pubtime", e);
        }
    }
    return pubtime;
}