Example usage for org.joda.time.format DateTimeFormat shortTime

List of usage examples for org.joda.time.format DateTimeFormat shortTime

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat shortTime.

Prototype

public static DateTimeFormatter shortTime() 

Source Link

Document

Creates a format that outputs a short time format.

Usage

From source file:com.goodhuddle.huddle.web.site.handlebars.helper.DateTimeHelper.java

License:Open Source License

public DateTimeHelper() {
    defaultDateFormat = DateTimeFormat.shortDate();
    defaultTimeFormat = DateTimeFormat.shortTime();
    defaultDateTimeFormat = DateTimeFormat.shortDateTime();
}

From source file:com.guavabot.alarmpreference.AlarmPreference.java

License:Apache License

@Override
public CharSequence getSummary() {
    if (mAlarm == null) {
        return null;
    }/*  ww w .  ja  va  2s .co  m*/

    if (!mAlarm.isAlarmOn()) {
        return getContext().getResources().getText(R.string.alarm_disabled);
    }

    String[] dayNames = getContext().getResources().getStringArray(R.array.alarm_days_summary);
    StringBuilder builder = new StringBuilder();
    int weeklyAlarms = mAlarm.getWeeklyAlarms();
    for (int i = 0; i < 7; i++) {
        if ((weeklyAlarms & (1 << i)) != 0)
            builder.append(dayNames[i]);
    }

    DateTimeFormatter timeFmt = DateTimeFormat.shortTime();
    builder.append(getContext().getString(R.string.alarm_at, timeFmt.print(mAlarm.getTime())));
    return builder.toString();
}

From source file:com.helger.datetime.format.PDTFormatter.java

License:Apache License

/**
 * Get the short time formatter for the passed locale.
 *
 * @param aDisplayLocale/*ww  w . ja v  a 2s.co  m*/
 *        The display locale to be used. May be <code>null</code>.
 * @return The created date time formatter. Never <code>null</code>.
 */
@Nonnull
public static DateTimeFormatter getShortFormatterTime(@Nullable final Locale aDisplayLocale) {
    return getWithLocaleAndChrono(DateTimeFormat.shortTime(), aDisplayLocale);
}

From source file:com.hmsinc.epicenter.velocity.DateTimeFormatTool.java

License:Open Source License

/**
 * Checks a string to see if it matches one of the standard DateTimeFormat
 * style patterns: full, long, medium, short, or default.
 *///  ww w.  j  av a2 s.c o m
private static DateTimeFormatter getTimeStyle(String style, Locale locale, DateTimeZone zone) {
    final DateTimeFormatter ret;
    if (style.equalsIgnoreCase("full")) {
        ret = DateTimeFormat.fullTime();
    } else if (style.equalsIgnoreCase("long")) {
        ret = DateTimeFormat.longTime();
    } else if (style.equalsIgnoreCase("medium")) {
        ret = DateTimeFormat.mediumTime();
    } else if (style.equalsIgnoreCase("short")) {
        ret = DateTimeFormat.shortTime();
    } else if (style.equalsIgnoreCase("none")) {
        ret = null;
    } else {
        ret = DateTimeFormat.forPattern(style);
    }
    return ret == null ? null : ret;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<LocalTime> getOriginDepartureTimeList() {
    ArrayList<LocalTime> originDepartureTimeList = new ArrayList<>();
    for (WebElement originDepartureTime : originDepartureTimes) {
        if (originDepartureTime.findElements(By.cssSelector(".time")).isEmpty()) {
            continue;
        }/*from www . j  ava2 s .  co  m*/
        String text = originDepartureTime.findElement(By.cssSelector(".time")).getText().trim();
        originDepartureTimeList.add(LocalTime.parse(text, DateTimeFormat.shortTime()));
    }
    return originDepartureTimeList;
}

From source file:com.hotwire.selenium.desktop.us.results.AirResultsPage.java

License:Open Source License

public ArrayList<LocalTime> getDepartureDestinationTimesList() {
    ArrayList<LocalTime> destinationDepartureTimeList = new ArrayList<LocalTime>();
    for (WebElement departureDestinationTime : departureDestinationTimes) {
        if (departureDestinationTime.findElements(By.cssSelector(".time")).isEmpty()) {
            continue;
        }// www  . j av a  2 s. c o m
        String text = departureDestinationTime.findElement(By.cssSelector(".time")).getText().trim();
        LocalTime localTime = LocalTime.parse(text, DateTimeFormat.shortTime());
        if (departureDestinationTime.findElements(By.cssSelector(".plusDay")).size() > 0) {
            int plusDays = new Integer(departureDestinationTime.findElement(By.cssSelector(".plusDay"))
                    .getText().trim().replaceAll("[^0-9]", "")).intValue();
            localTime = localTime.plusMillis(plusDays);
        }
        destinationDepartureTimeList.add(localTime);
    }
    return destinationDepartureTimeList;
}

From source file:com.robwilliamson.healthyesther.fragment.edit.EditEventFragment.java

License:Open Source License

private void updateUi() {
    mSettingRowName = true;/*from   w  w w .  jav  a 2s  . c o m*/
    if (hasRow()) {
        @SuppressWarnings("ConstantConditions")
        @Nonnull
        EventTable.Row row = getRow();
        if (getNameView() != null) {
            String rowName = row.getName();
            Editable editable = getNameView().getEditableText();

            editable.clear();
            if (rowName != null) {
                editable.append(rowName);
            }
        }

        if (getTimeButton() != null) {
            getTimeButton()
                    .setText(Utils.Time.toString(row.getWhen().as(DateTime.class), DateTimeFormat.shortTime()));
        }

        if (getDateButton() != null) {
            getDateButton().setText(
                    Utils.Time.toString(row.getWhen().as(DateTime.class), DateTimeFormat.mediumDate()));
        }
    }
    mSettingRowName = false;
}

From source file:com.sheepdog.mashmesh.servlets.AcceptPickupServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Objectify rideRequestOfy = OfyService.transactionOfy();

    try {//  w ww  .j  ava 2  s  .c om
        String rideRequestId = req.getParameter("rideRequestId");
        Preconditions.checkNotNull(rideRequestId);

        RideRequest rideRequest = rideRequestOfy.get(RideRequest.class, Long.parseLong(rideRequestId));
        UserProfile userProfile = (UserProfile) req.getAttribute("userProfile");

        VolunteerProfile volunteerProfile = rideRequest.getPendingVolunteerProfile();

        // Make sure that we're not trying to answer a pickup request meant for someone else.
        if (!volunteerProfile.getUserId().equals(userProfile.getUserId())) {
            resp.setStatus(403);
            // TODO: Explanatory page
            return;
        }

        // TODO: Centralize this logic with the rest of the notification logic
        RideRecord rideRecord = rideRequest.getPendingRideRecord();
        rideRecord.setExportable(true);
        OfyService.ofy().put(rideRecord);

        PickupNotification.sendPatientNotification(rideRequest, userProfile);

        rideRequestOfy.delete(rideRequest);
        rideRequestOfy.getTxn().commit();

        // TODO: Make sure that pickup requests timeout and trigger a rejection.

        DateTimeFormatter dateFormatter = DateTimeFormat.fullDate();
        DateTimeFormatter timeFormatter = DateTimeFormat.shortTime();

        VelocityContext context = new VelocityContext();
        context.put("userProfile", userProfile);
        context.put("isAdmin", UserServiceFactory.getUserService().isUserAdmin());
        context.put("patientProfile", rideRequest.getPatientProfile());
        context.put("appointmentAddress", rideRequest.getAppointmentAddress());
        context.put("appointmentTime", timeFormatter.print(rideRequest.getAppointmentTime()));
        context.put("appointmentDate", dateFormatter.print(rideRequest.getAppointmentTime()));
        context.put("pickupTime", timeFormatter.print(rideRecord.getPickupTime()));

        resp.setContentType("text/html");
        Template template = VelocityUtils.getInstance().getTemplate(ACCEPT_PICKUP_TEMPLATE_PATH);
        template.merge(context, resp.getWriter());
    } catch (MessagingException e) {
        logger.log(Level.SEVERE, "Failed to send patient notification", e);
        resp.setStatus(500);
    } finally {
        if (rideRequestOfy.getTxn().isActive()) {
            rideRequestOfy.getTxn().rollback();
        }
    }
}

From source file:com.vityuk.ginger.provider.format.JodaTimeUtils.java

License:Apache License

private static DateTimeFormatter createJodaDateFormatter(FormatType formatType, DateFormatStyle formatStyle) {
    switch (formatType) {
    case TIME:/* ww  w  .  j ava 2  s  . co  m*/
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortTime();
        case MEDIUM:
            return DateTimeFormat.mediumTime();
        case LONG:
            return DateTimeFormat.longTime();
        case FULL:
            return DateTimeFormat.fullTime();
        case DEFAULT:
            return ISODateTimeFormat.time();
        }
    case DATE:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDate();
        case MEDIUM:
            return DateTimeFormat.mediumDate();
        case LONG:
            return DateTimeFormat.longDate();
        case FULL:
            return DateTimeFormat.fullDate();
        case DEFAULT:
            return ISODateTimeFormat.date();
        }
    case DATETIME:
        switch (formatStyle) {
        case SHORT:
            return DateTimeFormat.shortDateTime();
        case MEDIUM:
            return DateTimeFormat.mediumDateTime();
        case LONG:
            return DateTimeFormat.longDateTime();
        case FULL:
            return DateTimeFormat.fullDateTime();
        case DEFAULT:
            return ISODateTimeFormat.dateTime();
        }
    }

    throw new IllegalArgumentException();
}

From source file:me.vertretungsplan.additionalinfo.BaseIcalParser.java

License:Mozilla Public License

@Override
public AdditionalInfo getAdditionalInfo() throws IOException {
    AdditionalInfo info = new AdditionalInfo();
    info.setTitle(getTitle());/*from   ww w .jav a2 s . c  o m*/

    String rawdata = httpGet(getIcalUrl(), "UTF-8");

    if (shouldStripTimezoneInfo()) {
        Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL);
        rawdata = pattern.matcher(rawdata).replaceAll("");
    }

    DateTime now = DateTime.now().withTimeAtStartOfDay();
    List<ICalendar> icals = Biweekly.parse(rawdata).all();

    List<Event> events = new ArrayList<>();
    for (ICalendar ical : icals) {
        for (VEvent event : ical.getEvents()) {
            Event item = new Event();

            TimeZone timezoneStart = getTimeZoneStart(ical, event);

            if (event.getDescription() != null) {
                item.description = event.getDescription().getValue();
            }
            if (event.getSummary() != null) {
                item.summary = event.getSummary().getValue();
            }
            if (event.getDateStart() != null) {
                item.startDate = new DateTime(event.getDateStart().getValue());
                item.startHasTime = event.getDateStart().getValue().hasTime();
            } else {
                continue;
            }
            if (event.getDateEnd() != null) {
                item.endDate = new DateTime(event.getDateEnd().getValue());
                item.endHasTime = event.getDateEnd().getValue().hasTime();
            }
            if (event.getLocation() != null) {
                item.location = event.getLocation().getValue();
            }
            if (event.getUrl() != null) {
                item.url = event.getUrl().getValue();
            }

            if (event.getRecurrenceRule() == null && item.endDate != null
                    && (item.endDate.compareTo(now) < 0)) {
                continue;
            } else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) {
                continue;
            }
            if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null
                    && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) {
                continue;
            }

            if (event.getRecurrenceRule() != null) {
                Duration duration = null;
                if (event.getDateEnd() != null) {
                    duration = new Duration(new DateTime(event.getDateStart().getValue()),
                            new DateTime(event.getDateEnd().getValue()));
                }

                DateIterator iterator = event.getDateIterator(timezoneStart);
                while (iterator.hasNext()) {
                    Date date = iterator.next();
                    Event reccitem = item.clone();
                    reccitem.startDate = new DateTime(date);
                    reccitem.endDate = reccitem.startDate.plus(duration);

                    if (item.startDate.equals(reccitem.startDate))
                        continue;

                    if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
                        continue;
                    } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
                        continue;
                    }

                    events.add(reccitem);
                }
            }

            if (item.endDate != null && (item.endDate.compareTo(now) < 0)) {
                continue;
            } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) {
                continue;
            }

            events.add(item);
        }
    }
    Collections.sort(events, new Comparator<Event>() {
        @Override
        public int compare(Event o1, Event o2) {
            return o1.startDate.compareTo(o2.startDate);
        }
    });

    StringBuilder content = new StringBuilder();

    int count = 0;

    DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY);
    DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY);
    DateTimeFormatter fmtT = DateTimeFormat.shortTime().withLocale(Locale.GERMANY);

    for (Event item : events) {
        if (count >= getMaxItemsCount()) {
            break;
        } else if (count != 0) {
            content.append("<br><br>\n\n");
        }

        DateTime start = item.startDate;

        if (item.endDate != null) {
            DateTime end = item.endDate;

            if (!item.endHasTime) {
                end = end.minusDays(1);
            }

            content.append((item.startHasTime ? fmtDt : fmtD).print(start));
            if (!end.equals(start)) {
                content.append(" - ");
                if (item.startHasTime && item.endHasTime && end.toLocalDate().equals(start.toLocalDate())) {
                    content.append(fmtT.print(end));
                } else {
                    content.append((item.endHasTime ? fmtDt : fmtD).print(end));
                }
            }
        } else {
            content.append(fmtDt.print(start));
        }
        content.append("<br>\n");

        content.append("<b>");
        content.append(item.summary);
        content.append("</b>");

        count++;
    }

    info.setText(content.toString());

    return info;
}