Example usage for org.joda.time.format DateTimeFormatter parseLocalTime

List of usage examples for org.joda.time.format DateTimeFormatter parseLocalTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormatter parseLocalTime.

Prototype

public LocalTime parseLocalTime(String text) 

Source Link

Document

Parses only the local time from the given text, returning a new LocalTime.

Usage

From source file:com.fatboyindustrial.gsonjodatime.LocalTimeConverter.java

License:Open Source License

/**
 * Gson invokes this call-back method during deserialization when it encounters a field of the
 * specified type. <p>/*from   w w  w. j a v  a 2s  .  co m*/
 *
 * In the implementation of this call-back method, you should consider invoking
 * {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects
 * for any non-trivial field of the returned object. However, you should never invoke it on the
 * the same type passing {@code json} since that will cause an infinite loop (Gson will call your
 * call-back method again).
 *
 * @param json The Json data being deserialized
 * @param typeOfT The type of the Object to deserialize to
 * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
 * @throws JsonParseException if json is not in the expected format of {@code typeOfT}
 */
@Override
public LocalTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN);
    return fmt.parseLocalTime(json.getAsString());
}

From source file:com.google.gerrit.server.config.ScheduleConfig.java

License:Apache License

private static long initialDelay(Config rc, String section, String subsection, String keyStartTime,
        DateTime now, long interval) {
    long delay = MISSING_CONFIG;
    String start = rc.getString(section, subsection, keyStartTime);
    try {//  ww w  .  j  a va2 s.c o  m
        if (start != null) {
            DateTimeFormatter formatter;
            MutableDateTime startTime = now.toMutableDateTime();
            try {
                formatter = ISODateTimeFormat.hourMinute();
                LocalTime firstStartTime = formatter.parseLocalTime(start);
                startTime.hourOfDay().set(firstStartTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour());
            } catch (IllegalArgumentException e1) {
                formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US);
                LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start);
                startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek());
                startTime.hourOfDay().set(firstStartDateTime.getHourOfDay());
                startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour());
            }
            startTime.secondOfMinute().set(0);
            startTime.millisOfSecond().set(0);
            long s = startTime.getMillis();
            long n = now.getMillis();
            delay = (s - n) % interval;
            if (delay <= 0) {
                delay += interval;
            }
        } else {
            log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section,
                    keyStartTime));
        }
    } catch (IllegalArgumentException e2) {
        log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime),
                e2);
        delay = INVALID_CONFIG;
    }
    return delay;
}

From source file:com.moosemorals.weather.xml.WeatherParser.java

License:Open Source License

private Current readCurrent(XMLStreamReader parser, WeatherReport.Builder reportBuilder)
        throws XMLStreamException, IOException {

    parser.require(XMLStreamReader.START_ELEMENT, NAMESPACE, "current_condition");

    DateTimeFormatter fmt = DateTimeFormat.forPattern("hh:mm aa").withZoneUTC();
    Current.Builder builder = new Current.Builder();

    while (parser.next() != XMLStreamReader.END_ELEMENT) {
        if (parser.getEventType() != XMLStreamReader.START_ELEMENT) {
            continue;
        }/*w  ww.j  av  a2 s  . co  m*/

        switch (parser.getLocalName()) {
        case "observation_time":
            builder.setObservationTime(fmt.parseLocalTime(readTag(parser, "observation_time")));
            break;
        case "temp_C":
            builder.setTempC(readIntTag(parser, "temp_C"));
            break;
        case "temp_F":
            builder.setTempF(readIntTag(parser, "temp_F"));
            break;
        case "weatherCode":
            builder.setWeatherCode(readIntTag(parser, "weatherCode"));
            break;
        case "weatherIconUrl":
            builder.setWeatherIconUrl(readTag(parser, "weatherIconUrl").trim());
            break;
        case "weatherDesc":
            builder.setWeatherDesc(readTag(parser, "weatherDesc").trim());
            break;
        case "windspeedMiles":
            builder.setWindspeedMiles(readIntTag(parser, "windspeedMiles"));
            break;
        case "windspeedKmph":
            builder.setWindspeedKmph(readIntTag(parser, "windspeedKmph"));
            break;
        case "winddirDegree":
            builder.setWinddirDegree(readIntTag(parser, "winddirDegree"));
            break;
        case "winddir16Point":
            builder.setWinddir16Point(readTag(parser, "winddir16Point"));
            break;
        case "precipMM":
            builder.setPrecipMM(readFloatTag(parser, "precipMM"));
            break;
        case "humidity":
            builder.setHumidity(readIntTag(parser, "humidity"));
            break;
        case "visibility":
            builder.setVisibility(readIntTag(parser, "visibility"));
            break;
        case "pressure":
            builder.setPressure(readIntTag(parser, "pressure"));
            break;
        case "cloudcover":
            builder.setCloudcover(readIntTag(parser, "cloudcover"));
            break;
        case "FeelsLikeC":
            builder.setFeelsLikeC(readIntTag(parser, "FeelsLikeC"));
            break;
        case "FeelsLikeF":
            builder.setFeelsLikeF(readIntTag(parser, "FeelsLikeF"));
            break;
        default:
            // Cope with the crazy way that languages are handled.
            if (parser.getLocalName().startsWith(LANG_TAG)) {
                builder.setWeatherDesc(readTag(parser, parser.getLocalName()).trim());

                reportBuilder.setLanguage(parser.getLocalName().substring(LANG_TAG.length()));

                break;
            }
            log.warn("Current: Skiping unexpected tag {}", parser.getLocalName());
            skipTag(parser);
            break;
        }
    }
    return builder.build();

}

From source file:com.moosemorals.weather.xml.WeatherParser.java

License:Open Source License

private Astronomy readAstronmy(XMLStreamReader parser, DateTime when) throws XMLStreamException, IOException {
    parser.require(XMLStreamReader.START_ELEMENT, NAMESPACE, "astronomy");

    Astronomy.Builder builder = new Astronomy.Builder();

    DateTimeFormatter fmt = DateTimeFormat.forPattern("hh:mm aa");

    while (parser.next() != XMLStreamReader.END_ELEMENT) {
        if (parser.getEventType() != XMLStreamReader.START_ELEMENT) {
            continue;
        }/*from   w  w w .jav  a 2  s.c  o m*/

        String raw;
        LocalTime time;
        switch (parser.getLocalName()) {
        case "sunrise":
            raw = readTag(parser, "sunrise");
            if (!raw.equals("No sunrise")) {
                time = fmt.parseLocalTime(raw);
                builder.setSunrise(
                        when.withHourOfDay(time.getHourOfDay()).withMinuteOfHour(time.getMinuteOfHour()));
            } else {
                builder.setSunrise(null);
            }
            break;
        case "sunset":
            raw = readTag(parser, "sunset");
            if (!raw.equals("No sunset")) {
                time = fmt.parseLocalTime(raw);
                builder.setSunset(
                        when.withHourOfDay(time.getHourOfDay()).withMinuteOfHour(time.getMinuteOfHour()));
            } else {
                builder.setSunset(null);
            }
            break;
        case "moonrise":
            raw = readTag(parser, "moonrise");
            if (!raw.equals("No moonrise")) {
                time = fmt.parseLocalTime(raw);
                builder.setMoonrise(
                        when.withHourOfDay(time.getHourOfDay()).withMinuteOfHour(time.getMinuteOfHour()));
            } else {
                builder.setMoonrise(null);
            }
            break;
        case "moonset":
            raw = readTag(parser, "moonset");
            if (!raw.equals("No moonset")) {
                time = fmt.parseLocalTime(raw);
                builder.setMoonset(
                        when.withHourOfDay(time.getHourOfDay()).withMinuteOfHour(time.getMinuteOfHour()));
            } else {
                builder.setMoonset(null);
            }
            break;
        default:
            log.warn("Astro: Skiping unexpected tag {}", parser.getLocalName());
            skipTag(parser);
            break;
        }
    }

    return builder.build();
}

From source file:com.sonicle.webtop.calendar.UserOptionsService.java

License:Open Source License

@Override
public void processUserOptions(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    Connection con = null;//www .  j a  v a2s  . c  om

    try {
        String crud = ServletUtils.getStringParameter(request, "crud", true);
        CalendarUserSettings cus = new CalendarUserSettings(SERVICE_ID, getTargetProfileId());
        DateTimeFormatter hmf = DateTimeUtils.createHmFormatter();

        if (crud.equals(Crud.READ)) {
            JsUserOptions jso = new JsUserOptions(getTargetProfileId().toString());

            // Main
            jso.view = cus.getView();
            jso.workdayStart = hmf.print(cus.getWorkdayStart());
            jso.workdayEnd = hmf.print(cus.getWorkdayEnd());
            jso.eventReminderDelivery = cus.getEventReminderDelivery();

            new JsonResult(jso).printTo(out);

        } else if (crud.equals(Crud.UPDATE)) {
            Payload<MapItem, JsUserOptions> pl = ServletUtils.getPayload(request, JsUserOptions.class);

            // Main
            if (pl.map.has("view"))
                cus.setView(pl.data.view);
            if (pl.map.has("workdayStart"))
                cus.setWorkdayStart(hmf.parseLocalTime(pl.data.workdayStart));
            if (pl.map.has("workdayEnd"))
                cus.setWorkdayEnd(hmf.parseLocalTime(pl.data.workdayEnd));
            if (pl.map.has("eventReminderDelivery"))
                cus.setEventReminderDelivery(pl.data.eventReminderDelivery);

            new JsonResult().printTo(out);
        }

    } catch (Exception ex) {
        logger.error("Error executing UserOptions", ex);
        new JsonResult(false).printTo(out);
    } finally {
        DbUtils.closeQuietly(con);
    }
}

From source file:com.sonicle.webtop.contacts.UserOptionsService.java

License:Open Source License

@Override
public void processUserOptions(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    Connection con = null;/*from ww w. j a v  a2  s  .  co  m*/

    try {
        String crud = ServletUtils.getStringParameter(request, "crud", true);
        ContactsUserSettings cus = new ContactsUserSettings(SERVICE_ID, getTargetProfileId());
        DateTimeFormatter hmf = DateTimeUtils.createHmFormatter();

        if (crud.equals(Crud.READ)) {
            JsUserOptions jso = new JsUserOptions(getTargetProfileId().toString());

            // Main
            jso.view = EnumUtils.toSerializedName(cus.getView());
            jso.showBy = EnumUtils.toSerializedName(cus.getShowBy());
            jso.anniversaryReminderDelivery = cus.getAnniversaryReminderDelivery();
            jso.anniversaryReminderTime = hmf.print(cus.getAnniversaryReminderTime());

            new JsonResult(jso).printTo(out);

        } else if (crud.equals(Crud.UPDATE)) {
            Payload<MapItem, JsUserOptions> pl = ServletUtils.getPayload(request, JsUserOptions.class);

            // Main
            if (pl.map.has("view"))
                cus.setView(pl.data.view);
            if (pl.map.has("showBy"))
                cus.setShowBy(pl.data.showBy);
            if (pl.map.has("anniversaryReminderDelivery"))
                cus.setAnniversaryReminderDelivery(pl.data.anniversaryReminderDelivery);
            if (pl.map.has("anniversaryReminderTime"))
                cus.setAnniversaryReminderTime(hmf.parseLocalTime(pl.data.anniversaryReminderTime));

            new JsonResult().printTo(out);
        }

    } catch (Exception ex) {
        logger.error("Error executing UserOptions", ex);
        new JsonResult(false).printTo(out);
    } finally {
        DbUtils.closeQuietly(con);
    }
}

From source file:com.superrent.modules.CommonFunc.java

public static String sqlTime(JSpinner HH, JSpinner MM) {
    String hh = String.valueOf(HH.getValue());
    String mm = String.valueOf(MM.getValue());
    String ss = "00";
    String time = hh + ":" + mm + ":" + ss;
    DateTimeFormatter f = DateTimeFormat.forPattern("HH:mm:ss");
    LocalTime tim = f.parseLocalTime(time);
    return tim.toString().substring(0, 8);
}

From source file:datetime.management.DateTimeManage.java

public void Increase30min() {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
    LocalTime time = formatter.parseLocalTime("14:00");
    time = time.plusMinutes(30);//from ww w  .ja v a 2 s  . co  m
    System.out.println(formatter.print(time));
}

From source file:datetime.management.DateTimeManage.java

public String Increase30min(String inputTime) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
    LocalTime time = formatter.parseLocalTime(inputTime);
    time = time.plusMinutes(30);/*  w  w w .  ja v  a 2 s. co m*/
    return formatter.print(time);
}

From source file:DateTimeManagement.TimeIncrease.java

public void Increase30min(String inputTime) {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
    LocalTime time = formatter.parseLocalTime(inputTime);
    time = time.plusMinutes(30);//from www .j  av  a2s.c  o m
    System.out.println(formatter.print(time));
}