Example usage for java.time OffsetDateTime of

List of usage examples for java.time OffsetDateTime of

Introduction

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

Prototype

public static OffsetDateTime of(LocalDate date, LocalTime time, ZoneOffset offset) 

Source Link

Document

Obtains an instance of OffsetDateTime from a date, time and offset.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneOffset.UTC);

    System.out.println(o);//from ww  w .  jav  a  2  s .co m
}

From source file:csv.sorting.PrepareWeatherData.java

public static void main(String[] args) throws Exception {

    // Path to read the CSV data from:
    final Path csvStationDataFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503station.txt");
    final Path csvLocalWeatherDataUnsortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly.txt");
    final Path csvLocalWeatherDataSortedFilePath = FileSystems.getDefault()
            .getPath("C:\\Users\\philipp\\Downloads\\csv\\201503hourly_sorted.txt");

    // A map between the WBAN and Station for faster Lookups:
    final Map<String, Station> stationMap = getStationMap(csvStationDataFilePath);

    // Holds the List of Sorted DateTimes (including ZoneOffset):
    List<Integer> indices = new ArrayList<>();

    // Comparator for sorting the File:
    Comparator<OffsetDateTime> byMeasurementTime = (e1, e2) -> e1.compareTo(e2);

    // Get the sorted indices from the stream of LocalWeatherData Elements:
    try (Stream<CsvMappingResult<csv.model.LocalWeatherData>> stream = getLocalWeatherData(
            csvLocalWeatherDataUnsortedFilePath)) {

        // Holds the current line index, when processing the input Stream:
        AtomicInteger currentIndex = new AtomicInteger(1);

        // We want to get a list of indices, which sorts the CSV file by measurement time:
        indices = stream//from w w  w  .ja v  a 2 s.  c  o m
                // Skip the CSV Header:
                .skip(1)
                // Start by enumerating ALL mapping results:
                .map(x -> new ImmutablePair<>(currentIndex.getAndAdd(1), x))
                // Then only take those lines, that are actually valid:
                .filter(x -> x.getRight().isValid())
                // Now take the parsed entity from the CsvMappingResult:
                .map(x -> new ImmutablePair<>(x.getLeft(), x.getRight().getResult()))
                // Take only those measurements, that are also available in the list of stations:
                .filter(x -> stationMap.containsKey(x.getRight().getWban()))
                // Get the OffsetDateTime from the LocalWeatherData, which includes the ZoneOffset of the Station:
                .map(x -> {
                    // Get the matching station:
                    csv.model.Station station = stationMap.get(x.getRight().getWban());
                    // Calculate the OffsetDateTime from the given measurement:
                    OffsetDateTime measurementTime = OffsetDateTime.of(x.getRight().getDate(),
                            x.getRight().getTime(), ZoneOffset.ofHours(0));
                    // Build the Immutable pair with the Index again:
                    return new ImmutablePair<>(x.getLeft(), measurementTime);
                })
                // Now sort the Measurements by their Timestamp:
                .sorted((x, y) -> byMeasurementTime.compare(x.getRight(), y.getRight()))
                // Take only the Index:
                .map(x -> x.getLeft())
                // And turn it into a List:
                .collect(Collectors.toList());
    }

    // Now sorts the File by Line Number:
    writeSortedFileByIndices(csvLocalWeatherDataUnsortedFilePath, indices, csvLocalWeatherDataSortedFilePath);
}

From source file:com.intuit.wasabi.api.pagination.filters.FilterUtil.java

/**
 * Parses a UI date of the format {@code M/d/yZ} (See {@link DateTimeFormatter}) as it is allowed to be
 * entered in advanced search fields in the UI. Throws a {@link PaginationException} on failure, notifying the user.
 *
 * @param dateString     the string as received from the UI
 * @param timeZoneOffset the user's timezone offset
 * @return a parsed date/*from  w w  w .ja v a 2 s.c om*/
 */
public static OffsetDateTime parseUIDate(String dateString, String timeZoneOffset) {
    try {
        TemporalAccessor tempAccessor = DateTimeFormatter.ofPattern("M/d/yyyyZ")
                .parse(dateString + timeZoneOffset);
        return OffsetDateTime.of(java.time.LocalDate.from(tempAccessor), LocalTime.MIDNIGHT, ZoneOffset.UTC);
    } catch (DateTimeParseException parseException) {
        throw new PaginationException(
                ErrorCode.FILTER_KEY_UNPROCESSABLE, "Wrong format: Can not parse date (" + dateString
                        + ") , must be of " + "format MM/dd/yyyy , e.g. 05/23/2014 or 4/7/2013",
                parseException);
    }
}

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

/**
 * Checks if scheduler's time data satisfies existing time parameters.
 *
 * @param dto           scheduler job data.
 * @param dateTime      existing time data.
 * @param desiredStatus target exploratory status which has influence for time/date checking ('running' status
 *                      requires for checking start time, 'stopped' - for end time, 'terminated' - for
 *                      'terminatedDateTime').
 * @return true/false.//w  w w.  ja  va  2  s  .co  m
 */
private boolean isSchedulerJobDtoSatisfyCondition(SchedulerJobDTO dto, OffsetDateTime dateTime,
        UserInstanceStatus desiredStatus) {
    ZoneOffset zOffset = dto.getTimeZoneOffset();
    OffsetDateTime roundedDateTime = OffsetDateTime.of(dateTime.toLocalDate(),
            LocalTime.of(dateTime.toLocalTime().getHour(), dateTime.toLocalTime().getMinute()),
            dateTime.getOffset());

    LocalDateTime convertedDateTime = ZonedDateTime
            .ofInstant(roundedDateTime.toInstant(), ZoneId.ofOffset(TIMEZONE_PREFIX, zOffset))
            .toLocalDateTime();

    return desiredStatus == TERMINATED
            ? Objects.nonNull(dto.getTerminateDateTime())
                    && convertedDateTime.toLocalDate().equals(dto.getTerminateDateTime().toLocalDate())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus))
            : !convertedDateTime.toLocalDate().isBefore(dto.getBeginDate())
                    && isFinishDateMatchesCondition(dto, convertedDateTime)
                    && getDaysRepeat(dto, desiredStatus)
                            .contains(convertedDateTime.toLocalDate().getDayOfWeek())
                    && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus));
}

From source file:org.kie.workbench.common.forms.integration.tests.valueprocessing.FormValuesProcessorTest.java

@Test
public void testLocalDateFieldTaskFormValuesProcessing() {
    setupFormValuesProcessor(Collections.singletonList(localDateFieldValueProcessor));

    final String LOCAL_DATE_BINDING = "_localDate_", LOCAL_DATE_TIME_BINDING = "_localDateTime_",
            LOCAL_TIME_BINDING = "_localTime_", OFFSET_DATE_TIME_BINDING = "_offsetDateTime_";

    final LocalDate localDate1 = LocalDate.of(1989, 6, 6);
    final LocalDateTime localDateTime1 = LocalDateTime.of(2000, 5, 2, 3, 4);
    final LocalTime localTime1 = LocalTime.of(23, 15);
    //form engine does not support setting custom offset
    final ZoneOffset zoneOffset1 = OffsetDateTime.now().getOffset();
    final OffsetDateTime offsetDateTime1 = OffsetDateTime.of(localDate1, localTime1, zoneOffset1);

    final Map<String, Object> originalRawValues = new HashMap<String, Object>() {
        {/* ww  w  .j a va  2  s.c o m*/
            put(LOCAL_DATE_BINDING, localDate1);
            put(LOCAL_DATE_TIME_BINDING, localDateTime1);
            put(LOCAL_TIME_BINDING, localTime1);
            put(OFFSET_DATE_TIME_BINDING, offsetDateTime1);
        }
    };

    localDateFieldValueProcessor.init();
    final Map<String, Object> readFlatValues = formValuesProcessor.readFormValues(localDateTaskForm,
            originalRawValues, context);

    final Map<String, Object> writtenRawValues = testWritingFormValues(localDateTaskForm, originalRawValues,
            readFlatValues, originalRawValues);
    testReadingFormValues(localDateTaskForm, writtenRawValues, readFlatValues);
}