Example usage for java.time.format DateTimeFormatter ISO_LOCAL_DATE

List of usage examples for java.time.format DateTimeFormatter ISO_LOCAL_DATE

Introduction

In this page you can find the example usage for java.time.format DateTimeFormatter ISO_LOCAL_DATE.

Prototype

DateTimeFormatter ISO_LOCAL_DATE

To view the source code for java.time.format DateTimeFormatter ISO_LOCAL_DATE.

Click Source Link

Document

The ISO date formatter that formats or parses a date without an offset, such as '2011-12-03'.

Usage

From source file:org.openhab.binding.plugwise.internal.PlugwiseUtils.java

@SuppressWarnings("null")
public static boolean updateProperties(Map<String, String> properties, InformationResponseMessage message) {
    boolean update = false;

    // Update firmware version property
    String oldFirmware = properties.get(Thing.PROPERTY_FIRMWARE_VERSION);
    String newFirmware = DateTimeFormatter.ISO_LOCAL_DATE.format(message.getFirmwareVersion());
    if (oldFirmware == null || !oldFirmware.equals(newFirmware)) {
        properties.put(Thing.PROPERTY_FIRMWARE_VERSION, newFirmware);
        update = true;/*w  w w.  j  a  v a 2  s  . c o  m*/
    }

    // Update hardware version property
    String oldHardware = properties.get(Thing.PROPERTY_HARDWARE_VERSION);
    String newHardware = message.getHardwareVersion();
    if (oldHardware == null || !oldHardware.equals(newHardware)) {
        properties.put(Thing.PROPERTY_HARDWARE_VERSION, newHardware);
        update = true;
    }

    // Update hertz property for devices with a relay
    if (message.getDeviceType().isRelayDevice()) {
        String oldHertz = properties.get(PlugwiseBindingConstants.PROPERTY_HERTZ);
        String newHertz = Integer.toString(message.getHertz());
        if (oldHertz == null || !oldHertz.equals(newHertz)) {
            properties.put(PlugwiseBindingConstants.PROPERTY_HERTZ, newHertz);
            update = true;
        }
    }

    // Update MAC address property
    String oldMACAddress = properties.get(PlugwiseBindingConstants.PROPERTY_MAC_ADDRESS);
    String newMACAddress = message.getMACAddress().toString();
    if (oldMACAddress == null || !oldMACAddress.equals(newMACAddress)) {
        properties.put(PlugwiseBindingConstants.PROPERTY_MAC_ADDRESS, newMACAddress);
        update = true;
    }

    return update;
}

From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java

@SuppressWarnings("unused")
private static void validateISOPattens(List<String> isoPatternList) {

    Set<String> formattedDateTimeSet = new HashSet<String>();
    for (String pattern : isoPatternList) {
        formattedDateTimeSet.add(getFormattedDateTime(pattern, Locale.US));
    }/*from   ww  w . j  a v  a 2  s . c o  m*/

    DateTimeFormatter[] formatters = new DateTimeFormatter[] { DateTimeFormatter.BASIC_ISO_DATE, // 1
            DateTimeFormatter.ISO_DATE, // 2
            DateTimeFormatter.ISO_DATE_TIME, // 3
            // DateTimeFormatter.ISO_TIME, //
            DateTimeFormatter.ISO_INSTANT, // 4
            DateTimeFormatter.ISO_LOCAL_DATE, // 5
            DateTimeFormatter.ISO_LOCAL_DATE_TIME, // 6
            // DateTimeFormatter.ISO_LOCAL_TIME, //
            DateTimeFormatter.ISO_OFFSET_DATE, // 7
            DateTimeFormatter.ISO_OFFSET_DATE_TIME, // 8
            // DateTimeFormatter.ISO_OFFSET_TIME, //
            DateTimeFormatter.ISO_ORDINAL_DATE, // 9
            DateTimeFormatter.ISO_WEEK_DATE, // 10
            DateTimeFormatter.ISO_ZONED_DATE_TIME, // 11
            DateTimeFormatter.RFC_1123_DATE_TIME, // 12
    };

    System.out.println("-------------Validate ISO PattenText-------------");
    for (int i = 0; i < formatters.length; i++) {

        System.out.print((i + 1) + "\t");
        try {
            String formattedDateTime = ZONED_DATE_TIME.format(formatters[i]);
            System.out.print(formattedDateTimeSet.contains(formattedDateTime) ? "YES\t" : "NO\t");
            System.out.println(formattedDateTime);
        } catch (Throwable t) {
            System.out.println(t.getMessage());
        }
    }

}

From source file:rapture.dp.invocable.calendar.steps.CalendarLookupStep.java

@Override
public String invoke(CallingContext ctx) {
    DecisionApi decision = Kernel.getDecision();
    try {//from   www .  ja  v  a 2s  .  com
        decision.setContextLiteral(ctx, getWorkerURI(), "STEPNAME", getStepName());

        String dateStr = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DATE"));
        String calendar = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "CALENDAR"));
        String translator = StringUtils
                .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "TRANSLATOR"));
        if (translator == null)
            translator = StringUtils
                    .stripToNull(decision.getContextValue(ctx, getWorkerURI(), "DEFAULT_TRANSLATOR"));
        LocalDate date = (dateStr == null) ? LocalDate.now() : LocalDate.parse(dateStr);

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        // Expected format is a map of dates (with or without years) to names or lists of names
        // Example:
        // {
        // "31Dec" : ["New Tear's Eve", "Hogmanay"] ,
        // "05Sep2016" : "Labor Day",
        // "04Sep2017" : "Labor Day"
        // "2015-01-01" : "New Year's Day"
        // }

        Map<String, Object> calendarTable = new HashMap<>();
        if (calendar != null) {
            String calendarJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, calendar));
            if (calendarJson != null) {
                calendarTable = JacksonUtil.getMapFromJson(calendarJson);
            }
        }

        // Translate the date to a name - eg Good Friday, Yom Kippur, Thanksgiving
        Map<String, Object> translationTable = new HashMap<>();
        if (translator != null) {
            String translationJson = StringUtils.stripToNull(Kernel.getDoc().getDoc(ctx, translator));
            if (translationJson != null) {
                translationTable = JacksonUtil.getMapFromJson(translationJson);
            }
        }

        List<String> lookup = new ArrayList<>();

        String languageTag = StringUtils.stripToNull(decision.getContextValue(ctx, getWorkerURI(), "LOCALE"));
        Locale locale = (languageTag == null) ? Locale.getDefault() : Locale.forLanguageTag(languageTag);

        for (DateTimeFormatter formatter : ImmutableList.of(DateTimeFormatter.ISO_LOCAL_DATE,
                DateTimeFormatter.ofPattern("ddMMMuuuu", locale), DateTimeFormatter.ofPattern("ddMMM", locale),
                DateTimeFormatter.ofPattern("MMMdduuuu", locale), DateTimeFormatter.ofPattern("MMMdd", locale),
                DateTimeFormatter.ofPattern("uuuuMMMdd", locale))) {

            String formattedDate = date.format(formatter);
            Object transList = translationTable.get(formattedDate);
            if (transList != null) {
                if (transList instanceof Iterable) {
                    for (Object o : (Iterable) transList) {
                        lookup.add(o.toString());
                    }
                } else
                    lookup.add(transList.toString());
            }
            lookup.add(formattedDate);
        }
        lookup.add(DayOfWeek.from(date).getDisplayName(TextStyle.FULL, locale));

        decision.setContextLiteral(ctx, getWorkerURI(), "DATE_TRANSLATIONS",
                JacksonUtil.jsonFromObject(lookup));

        // Calendar table defines the priority. getMapFromJson returns a LinkedHashMap so order is preserved.
        for (Entry<String, Object> calEntry : calendarTable.entrySet()) {
            if (lookup.contains(calEntry.getKey())) {
                decision.setContextLiteral(ctx, getWorkerURI(), "CALENDAR_LOOKUP_ENTRY",
                        JacksonUtil.jsonFromObject(calEntry));
                decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                        calEntry.getKey() + " matched as " + calEntry.getValue().toString(), false);
                return calEntry.getValue().toString();
            }
        }
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(), getStepName() + ": No matches for "
                + DateTimeFormatter.ISO_LOCAL_DATE.format(date) + " found in calendar", false);
        return getNextTransition();
    } catch (Exception e) {
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName(),
                "Unable to access the calendar : " + e.getLocalizedMessage());
        decision.setContextLiteral(ctx, getWorkerURI(), getStepName() + "Error", ExceptionToString.summary(e));
        decision.writeWorkflowAuditEntry(ctx, getWorkerURI(),
                "Problem in " + getStepName() + ": " + ExceptionToString.getRootCause(e).getLocalizedMessage(),
                true);
        return getErrorTransition();
    }
}