Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

public String toString(String pattern) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:com.tmathmeyer.sentinel.ui.DatePicker.java

License:Open Source License

/**
 * Sets date of DatePicker to specified value
 * /*from  ww  w  .  j  ava2s . c  om*/
 * @param previous the DateTime object from which to obtain values
 */
public void setDate(DateTime previous) {
    this.date.setValue(previous.toString(dateFmt));
}

From source file:com.tmathmeyer.sentinel.ui.DatePicker.java

License:Open Source License

/**
 * Sets time of DatePicker to specified value
 * //from w  ww.ja v  a2s  .c  o m
 * @param previous the DateTime object from which to obtain values
 */
public void setTime(DateTime previous) {
    this.time.setValue(previous.toString(timeFmt));
    if (previous.getHourOfDay() >= 12) {
        this.AMPM.setSelectedIndex(1);
    } else {
        this.AMPM.setSelectedIndex(0);
    }
}

From source file:com.tmathmeyer.sentinel.ui.navigation.GoToPanel.java

License:Open Source License

public void displayGoto(DateTime mDateTime) {
    gotoDateField.setText(mDateTime.toString(gotoExampleField));
}

From source file:com.tmathmeyer.sentinel.ui.navigation.MiniCalendarPanel.java

License:Open Source License

public void display(DateTime date) {
    // Title Bar Pane
    monthName = new JLabel(date.toString(Months.monthLblFormat), JLabel.CENTER);
    monthName.setFont(new Font("DejaVu Sans", Font.BOLD, 12));
    monthName.setMaximumSize(new Dimension(4400, 30));
    this.removeAll();
    this.setLayout(new BorderLayout());

    JPanel titlePane = new JPanel();
    JButton nextButton = new JButton(">");
    JButton prevButton = new JButton("<");

    titlePane.setLayout(new BoxLayout(titlePane, BoxLayout.X_AXIS));

    titlePane.add(prevButton);/*w w  w  . j  a  va 2s .  c o  m*/
    titlePane.add(nextButton);

    prevButton.setFocusable(false);
    prevButton.setBackground(UIManager.getDefaults().getColor("Panel.background"));
    nextButton.setFocusable(false);
    nextButton.setBackground(UIManager.getDefaults().getColor("Panel.background"));

    prevButton.setBorder(new EmptyBorder(5, 5, 5, 5));
    nextButton.setBorder(new EmptyBorder(5, 5, 5, 5));

    titlePane.add(monthName);

    calendarPreloader = new CalendarNavigationModule(date, mainPanel, monthOnly);
    this.miniCalendar = this.calendarPreloader.renderComponent();

    this.add(miniCalendar, BorderLayout.CENTER);
    this.add(titlePane, BorderLayout.NORTH);

    // add event listeners
    nextButton.addActionListener(nextListener);
    prevButton.addActionListener(prevListener);

    currentDate = date;

    this.revalidate();
    this.repaint();
}

From source file:com.tomtom.speedtools.services.lbs.route.implementation.TomTomLbsRouteEngineRouteEngineActorImpl.java

License:Apache License

@Override
@Nonnull/*from   www . j a  va 2s.co m*/
public Future<RouteEngineResponse> route(@Nonnull final GeoPoint from, @Nonnull final GeoPoint to,
        @Nullable final DateTime executeBefore) {
    assert from != null;
    assert to != null;

    // TODO ST-3: For as long as this is a route actor, we shall prevent crashing this actor at all cost.
    try {
        LOG.debug("route: {} Request, from={}, to={}, traffic={}", name, from, to,
                lbsProperties.isTrafficEnabled());
        final DateTime now = UTCTime.now();
        if ((executeBefore == null) || now.isBefore(executeBefore)) {
            final String url = getBaseQueryString(from, to);
            final TomTomLbsRouteEngineResponse lbsResponse;
            lbsResponse = executeLbsQuery(url);
            LOG.debug("route: {} Success, from={}, to={}, response={}", name, from, to, lbsResponse);

            final RouteEngineResponse routeEngineResponse = lbsResponse.convertToRouteEngineResponse();
            return Futures.successful(routeEngineResponse);
        } else {
            final String message = "Expected execution before: " + executeBefore.toString(DATE_FORMAT)
                    + " but started at: " + now.toString(DATE_FORMAT);
            LOG.debug("route: {} Too busy, from={}, to={}, {}", name, from, to, message);
            return Futures.failed(new TimeoutException(message));
        }
    } catch (final AuthorizationException e) {
        return Futures.failed(e);
    } catch (final ServiceUnavailableException e) {
        return Futures.failed(e);
    } catch (final IOException e) {
        return Futures.failed(e);
    } catch (final Throwable e) {

        // Catch all to make sure the actor won't die and takes its parent down.
        return Futures.failed(new IllegalStateException(e));
    }
}

From source file:com.tomtom.speedtools.tracer.LoggingTraceHandler.java

License:Apache License

@Override
public void handle(@Nonnull final DateTime time, @Nonnull final String clazz, @Nonnull final String tracer,
        @Nonnull final String method, @Nonnull final Object[] args) {
    assert time != null;
    assert clazz != null;
    assert tracer != null;
    assert method != null;
    assert args != null;

    // If logging is globally enabled and this particular SLF4J log handler is enabled, create readable message.
    if (LOG.isTraceEnabled()) {
        final StringBuilder message = new StringBuilder();
        message.append(time.toString(FORMATTER)).append(": ").append(clazz).append('.').append(method)
                .append('(');
        for (int i = 0; i < args.length; i++) {
            if (i > 0) {
                message.append(", ");
            }// w ww  .  j a  v  a2s  .  c  o  m

            /**
             * Convert the argument to a string. Theoretically, this can throw an exception. It shouldn't,
             * but if it does, we don't want this thread to die as a result of it. Log it as an error
             * and continue.
             */
            message.append((args[i] == null) ? "null" : Trace.toStringJsonSafe(args[i]));
        }
        message.append(')');
        LOG.trace("{}", message.toString());
    }
}

From source file:com.tripadvisor.seekbar.ClockView.java

License:Apache License

private void setSeekBarStatus(DateTime newCurrentTime) {
    if (mValidTimeInterval.contains(newCurrentTime)) {
        if (newCurrentTime.getDayOfWeek() == mValidTimeInterval.getStart().getDayOfWeek()) {
            mCircularClockSeekBar.setSeekBarStatus(VALID_RANGE);
            mTimeWeekDayText.setVisibility(GONE);
        } else {//w w  w  .ja  va 2  s  . co  m
            mCircularClockSeekBar.setSeekBarStatus(DIFFERENT_DAY_OF_WEEK);
            mTimeWeekDayText.setVisibility(VISIBLE);
            mTimeWeekDayText.setText(newCurrentTime.toString("EEE"));
        }
    } else {
        mCircularClockSeekBar.setSeekBarStatus(INVALID_RANGE);
        mTimeWeekDayText.setVisibility(GONE);
    }
}

From source file:com.ufnet.ws.utils.JodaDateUtil.java

License:Open Source License

/**
 * formatDate/*www. j  av a  2s . co m*/
 * @param datetime
 * @return
 */
public static String formatDate(DateTime datetime) {
    return datetime.toString(DATE_FORMATTER);
}

From source file:com.userweave.domain.util.xml.InvoiceCreator.java

License:Open Source License

/**
 * Create XML Representation of Invoice of given Study
 * @param study//from   w w w.j a va  2 s  . co  m
 * @return
 */
public String toXML(Study study) {

    DecimalFormat df_us = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
    df_us.applyPattern("#0.00");

    DecimalFormat df_de = (DecimalFormat) DecimalFormat.getInstance(Locale.GERMAN);
    df_de.applyPattern("#0.00");

    Document document = DocumentHelper.createDocument();
    Element invoice = document.addElement("invoice");

    Element receipient = invoice.addElement("receipient");

    Element details = invoice.addElement("details");

    if (study.getOwner().getCompany() != null) {
        receipient.addElement("company").addText(study.getOwner().getCompany());
    } else {
        receipient.addElement("company").addText("");
    }

    receipient.addElement("surname").addText(study.getOwner().getSurname());

    receipient.addElement("forename").addText(study.getOwner().getForename());

    Element address = receipient.addElement("address");
    if (study.getOwner().getAddress() != null) {
        address.addElement("street").addText(study.getOwner().getAddress().getStreet());
        address.addElement("housenumber").addText(study.getOwner().getAddress().getHouseNumber());
        address.addElement("postcode").addText(study.getOwner().getAddress().getPostcode());
        address.addElement("city").addText(study.getOwner().getAddress().getCity());
        address.addElement("country").addText(study.getOwner().getAddress().getCountry().getName());
    }

    details.addElement("number").addText(study.getConsideration().getInvoice().getNumber());

    DateTime invoiceDate = study.getConsideration().getDate();
    DateTimeFormatter dateDTF = DateTimeFormat.longDate();
    DateTimeFormatter usFmt = dateDTF.withLocale(Locale.US);
    String dateString = invoiceDate.toString(usFmt);

    if (evaluateReceipient(study) == Receipient.GERMAN_ALL) {
        DateTimeFormatter deFmt = dateDTF.withLocale(Locale.GERMAN);
        dateString = invoiceDate.toString(deFmt);
    }

    details.addElement("date").addText(dateString);

    details.addElement("currency").addText(study.getConsideration().getCurrency().getCurrencyCode());

    Double gross = study.getConsideration().getGrossAmount();
    if (study.getConsideration().getGrossAmount() != null) {

        String grossString = df_us.format(study.getConsideration().getGrossAmount());

        if (evaluateReceipient(study) == Receipient.GERMAN_ALL) {
            grossString = df_de.format(study.getConsideration().getGrossAmount());
        }

        details.addElement("gross").addText(grossString);
    } else {
        details.addElement("gross").addText(new Integer(0).toString());
    }

    if (study.getConsideration().getInvoice().getPurchaseTaxPercent() != null
            && study.getConsideration().getInvoice().getPurchaseTaxPercent() > 0d) {

        String netString = df_us.format(study.getConsideration().getInvoice().getNetAmount());
        if (evaluateReceipient(study) == Receipient.GERMAN_ALL) {
            netString = df_de.format(study.getConsideration().getInvoice().getNetAmount());
        }
        details.addElement("net").addText(netString);

        Double tax = new Double(study.getConsideration().getGrossAmount()
                - study.getConsideration().getInvoice().getNetAmount());
        tax = Math.round(tax * 100.) / 100.;
        String taxString = df_us.format(tax);
        if (evaluateReceipient(study) == Receipient.GERMAN_ALL) {
            netString = df_de.format(tax);
        }
        details.addElement("tax").addText(taxString);

        String taxRateString = df_us.format(study.getConsideration().getInvoice().getPurchaseTaxPercent());
        if (evaluateReceipient(study) == Receipient.GERMAN_ALL) {
            netString = df_de.format(study.getConsideration().getInvoice().getPurchaseTaxPercent());
        }
        details.addElement("taxrate").addText(taxRateString);
    } else {
        details.addElement("net").addText(new Integer(0).toString());
        details.addElement("tax").addText(new Integer(0).toString());

        details.addElement("taxrate")
                .addText(study.getConsideration().getInvoice().getPurchaseTaxPercent().toString());
    }

    return document.asXML();
}

From source file:com.userweave.pages.base.ContactAndFeedbackPage.java

License:Open Source License

@Override
protected WebMarkupContainer getAcceptButton(String componentId, final ModalWindow window) {
    final AjaxSubmitLink link = new AjaxSubmitLink(componentId, getForm()) {
        private static final long serialVersionUID = 1L;

        @Override/*from w w  w. j  a v  a  2 s . c  om*/
        protected void onSubmit(AjaxRequestTarget target, Form form) {
            User user = UserWeaveSession.get().getUser();

            String subject = new StringResourceModel(feedbacktype.toString(), ContactAndFeedbackPage.this, null)
                    .getString();

            try {
                DateTimeFormatter fmt = DateTimeFormat.forPattern("dd.MM.yyyy");

                DateTimeFormatter localeFmt = fmt.withLocale(user.getLocale());

                DateTimeFormatter timeFmt = DateTimeFormat.forPattern("HH:mm");

                DateTime dateTime = new DateTime();

                String mailMessage = new StringResourceModel("mailMessage", ContactAndFeedbackPage.this, null,
                        new Object[] { user.getForename(), user.getSurname(), dateTime.toString(localeFmt),
                                dateTime.toString(timeFmt), subject, feedbackMessage }).getString();

                String subjectForMail = new StringResourceModel("mailSubject", ContactAndFeedbackPage.this,
                        null).getString();

                mailservice.sendMail(user.getEmail(), subjectForMail, mailMessage, "info@userweave.net", true);

                window.close(target);
            } catch (MessagingException e) {
                error(new StringResourceModel("mailMessageError", ContactAndFeedbackPage.this, null)
                        .getString());

                target.add(feedback);
            }
        }

        @Override
        protected void onError(AjaxRequestTarget target, Form<?> form) {
        }
    };

    return link;
}