List of usage examples for org.joda.time.format DateTimeFormatter withLocale
public DateTimeFormatter withLocale(Locale locale)
From source file:com.tuplejump.stargate.FormatDateTimeFormatter.java
License:Apache License
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) {/*w w w .java 2 s .c o m*/ this.format = format; this.locale = locale; this.printer = locale == null ? printer.withDefaultYear(1970) : printer.withLocale(locale).withDefaultYear(1970); this.parser = locale == null ? parser.withDefaultYear(1970) : parser.withLocale(locale).withDefaultYear(1970); }
From source file:com.userweave.domain.util.xml.InvoiceCreator.java
License:Open Source License
/** * Create XML Representation of Invoice of given Study * @param study/* w ww . jav a2 s . c o 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//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; }
From source file:com.userweave.pages.user.configuration.UserApiCredentialsPanel.java
License:Open Source License
public UserApiCredentialsPanel(String id, UserModel userModel) { super(id);/*from w w w. j a v a2 s . c o m*/ model = userModel; AddModalWindows(); final FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackPanel"); feedbackPanel.setOutputMarkupId(true); add(feedbackPanel); createApiCredentialsContainer = new WebMarkupContainer("createApiCredentialsContainer") { @Override public boolean isVisible() { return !hasUserApiCredentials(); } }; createApiCredentialsContainer.setOutputMarkupPlaceholderTag(true); add(createApiCredentialsContainer); apiCredentialsContainer = new WebMarkupContainer("apiCredentialsContainer") { @Override public boolean isVisible() { return hasUserApiCredentials(); } }; apiCredentialsContainer.setOutputMarkupPlaceholderTag(true); add(apiCredentialsContainer); Form form = new Form("form"); createApiCredentialsContainer.add(form); form.add(new DefaultButton("createButton", new ResourceModel("createApiCredentials"), form) { @Override protected void onError(AjaxRequestTarget target, Form form) { target.addComponent(feedbackPanel); } @Override protected void onSubmit(AjaxRequestTarget target, Form form) { target.addComponent(feedbackPanel); // create new apiCredential ApiCredentials apiCred = new ApiCredentials(); apiCred.setHash(HashProvider.uniqueUUID()); apiCred.setActiveLastChange(new DateTime()); apiCredentialsDao.save(apiCred); User user = model.getObject(); user.setApiCredentials(apiCred); userDao.save(user); apiCredentialsContainer.setVisible(true); createApiCredentialsContainer.setVisible(false); target.addComponent(apiCredentialsContainer); target.addComponent(createApiCredentialsContainer); }; }); apiCredentialsContainer.add(new Label("apiAuthHash", new PropertyModel(model, "apiCredentials.hash"))); apiCredentialsContainer.add(new AjaxLink("genHash") { @Override public void onClick(AjaxRequestTarget target) { target.addComponent(feedbackPanel); generateHashModalWindow.show(target); } @Override public boolean isVisible() { return UserWeaveSession.get().isAdmin(); } }); WebMarkupContainer activeAdminContainer = new WebMarkupContainer("activeAdminContainer") { @Override public boolean isVisible() { return UserWeaveSession.get().isAdmin(); } }; apiCredentialsContainer.add(activeAdminContainer); final AjaxCheckBox activeChkBx = new AjaxCheckBox("active", new PropertyModel(model, "apiCredentials.active")) { @Override protected void onUpdate(AjaxRequestTarget target) { target.addComponent(feedbackPanel); userDao.save(model.getObject()); } }; activeChkBx.setOutputMarkupId(true); activeAdminContainer.add(activeChkBx); WebMarkupContainer activeContainer = new WebMarkupContainer("activeContainer") { @Override public boolean isVisible() { return !UserWeaveSession.get().isAdmin(); } }; apiCredentialsContainer.add(activeContainer); String dateString = new StringResourceModel("noActiveDate", this, null).getString(); if (model.getObject().getApiCredentials() != null && model.getObject().getApiCredentials().getActiveLastChange() != null) { DateTimeFormatter dateDTF = DateTimeFormat.longDate(); DateTimeFormatter usFmt = dateDTF.withLocale(UserWeaveSession.get().getLocale()); dateString = model.getObject().getApiCredentials().getActiveLastChange().toString(usFmt); } Label activeLabel = new Label("activeText", new StringResourceModel("deactiveFormat", this, null, new Object[] { dateString })); if (model.getObject().getApiCredentials() != null && model.getObject().getApiCredentials().isActive()) { activeLabel.setDefaultModel( new StringResourceModel("activeFormat", this, null, new Object[] { dateString })); } activeContainer.add(activeLabel); WebMarkupContainer deleteContainer = new WebMarkupContainer("deleteContainer") { @Override public boolean isVisible() { return UserWeaveSession.get().isAdmin(); } }; apiCredentialsContainer.add(deleteContainer); deleteContainer.add(new AjaxLink("delete") { @Override public void onClick(AjaxRequestTarget target) { target.addComponent(feedbackPanel); deleteModalWindow.show(target); } }); }
From source file:com.vityuk.ginger.provider.format.JodaTimeUtils.java
License:Apache License
public static DateTimeFormatter createJodaDateFormatter(FormatType formatType, String style, Locale locale) { DateFormatStyle formatStyle = DateFormatStyle.forStyle(style); final DateTimeFormatter formatter; if (formatStyle == null) { formatter = DateTimeFormat.forPattern(style); } else {/*w w w .ja v a 2 s. c o m*/ formatter = createJodaDateFormatter(formatType, formatStyle); } return formatter.withLocale(locale); }
From source file:de.jpaw.bonaparte.core.CSVComposer.java
License:Apache License
protected final DateTimeFormatter doDateTimeFormatter(DateTimeFormatter input) { return cfg.timeZone == null ? input.withLocale(cfg.locale).withZoneUTC() : input.withLocale(cfg.locale).withZone(cfg.timeZone); }
From source file:it.d4nguard.rgrpg.util.dynacast.adapters.DateTimeAdapter.java
License:Open Source License
/** * {@inheritDoc}//from w w w . j av a2s . c o m */ @Override public ReadableInstant adapt(String value) { // value is a string formatted as: "07/04/1987[dd/MM/yyyy]" String date = ""; DateTimeFormatter fmt; Triplet<String, String, String> tri = StringUtils.getBetween(value, '[', ']'); date = tri.getLeft(); if (tri.hasCenter()) fmt = DateTimeFormat.forPattern(tri.getCenter()); else fmt = ISODateTimeFormat.localDateOptionalTimeParser(); fmt = fmt.withLocale(Locale.getDefault()); if (getType().equals(DateTime.class)) return DateTime.parse(date, fmt); else if (getType().equals(DateMidnight.class)) return DateMidnight.parse(date, fmt); else if (getType().equals(Instant.class)) return Instant.parse(date, fmt); else if (getType().equals(MutableDateTime.class)) return MutableDateTime.parse(date, fmt); else throw new UnsupportedOperationException("type"); }
From source file:openmarker.tea.runtime.DefaultContext.java
License:Apache License
public void dateFormat(String format, String timeZoneID) { DateTimeZone zone;/* w w w .j a v a2s . co m*/ if (timeZoneID != null) { zone = DateTimeZone.forID(timeZoneID); } else { zone = DateTimeZone.getDefault(); } mDateTimeZone = zone; /* --Original before joda upgrade DateTimeFormat dtFormat; if (mLocale == null) { dtFormat = DateTimeFormat.getInstance(zone); --orig } else { dtFormat = DateTimeFormat.getInstance(zone, mLocale); } if (format == null) { format = dtFormat.getPatternForStyle("LL"); --orig }*/ if (format == null) { format = DateTimeFormat.patternForStyle("LL", mLocale); } DateTimeFormatter formatter = DateTimeFormat.forPattern(format).withZone(zone); if (mLocale != null) { formatter = formatter.withLocale(mLocale); } mDateTimeFormatter = formatter; mDateTimePattern = format; }
From source file:org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter.java
License:Open Source License
/** * Convert a date <tt>String</tt> to a <tt>Date</tt> object *///from w ww . j ava 2 s . co m protected Date makeDate(String dateStr) { if (dateStr == null || dateStr.length() == 0) { return null; } Date date = null; try { date = DefaultTypeConverter.INSTANCE.convert(Date.class, dateStr); } catch (TypeConversionException e) { // Try one of the other formats if (this.supportedDateFormatters != null) { // Remove text such as " (PDT)" which cannot be parsed. String dateStr2 = (dateStr == null || dateStr.indexOf('(') == -1) ? dateStr : dateStr.replaceAll(" \\(.*\\)", ""); for (DateTimeFormatter supportedDateFormatter : supportedDateFormatters) { // supported DateFormats were defined /** * Regional date format */ try { DateTime dateTime = supportedDateFormatter.parseDateTime(dateStr2); if (dateTime.getCenturyOfEra() > 0) { return dateTime.toDate(); } } catch (IllegalArgumentException e1) { // Didn't work } /** * Date format can be locale specific - make sure English format always works */ /* * TODO MER 25 May 2010 - Added this as a quick fix for IMAP date parsing which is always * English regardless of Locale. Some more thought and/or code is required to configure * the relationship between properties, format and locale. */ try { DateTime dateTime = supportedDateFormatter.withLocale(Locale.US).parseDateTime(dateStr2); if (dateTime.getCenturyOfEra() > 0) { return dateTime.toDate(); } } catch (IllegalArgumentException e1) { // Didn't work } } } if (date == null) { // Still no luck throw new TypeConversionException("Unable to convert string to date: " + dateStr); } } return date; }
From source file:org.apache.isis.core.metamodel.facets.value.datetimejdk8local.Jdk8LocalDateTimeUtil.java
License:Apache License
static TimeParser parserOf(org.joda.time.format.DateTimeFormatter jodaFormatter) { return t -> toJava8(jodaFormatter.withLocale(Locale.getDefault()).parseLocalDateTime(t)); }