dateTimeFormatter = DateTimeFormat.forStyle(this.style);
dateTimeFormatter = DateTimeFormat.forStyle(this.style);
private void testJodaStylePatterns(String style, Locale locale, Date date) throws Exception { DateFormatter formatter = new DateFormatter(); formatter.setTimeZone(UTC); formatter.setStylePattern(style); DateTimeFormatter jodaFormatter = DateTimeFormat.forStyle(style).withLocale(locale).withZone(DateTimeZone.UTC); String jodaPrinted = jodaFormatter.print(date.getTime()); assertThat("Unable to print style pattern " + style, formatter.print(date, locale), is(equalTo(jodaPrinted))); assertThat("Unable to parse style pattern " + style, formatter.parse(jodaPrinted, locale), is(equalTo(date))); }
@Test public void createDateTimeFormatterWithFallback() { DateTimeFormatter fallback = DateTimeFormat.forStyle("LL"); DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback); assertThat(formatter, is(sameInstance(fallback))); }
public JacksonJodaDateFormat withFormat(String format) { if (format == null || format.isEmpty()) { return this; } DateTimeFormatter formatter; if (_isStyle(format)) { formatter = DateTimeFormat.forStyle(format); } else { formatter = DateTimeFormat.forPattern(format); } if (_locale != null) { formatter = formatter.withLocale(_locale); } return new JacksonJodaDateFormat(this, formatter); }
@Override protected CharSequence safeApply(final ReadableInstant time, final Options options) { String style = options.param(0, "MM"); return DateTimeFormat.forStyle(style).print(time); }
/** * @see org.joda.time.format.DateTimeFormat#forStyle(String) */ public DateTimeFormatter getDateTimeFormatterForStyle(String style, XWikiContext context) { return DateTimeFormat.forStyle(style).withLocale((Locale) context.get("locale")); }
dateTimeFormatter = DateTimeFormat.forStyle(this.style);
/** * Get a datetime formatter for the specified date, time or datetime style. The style is specified as a two letter * code. The first character is the date style, and the second character is the time style. Specify a character of * 'S' for short style, 'M' for medium, 'L' for long, and 'F' for full. A date or time may be omitted by specifying * a style character '-'. The actual format used depends on the locale. * * @param style the type of date/time used by the returned formatter, both for parsing and printing; valid values * contain two characters from the set {@code "S", "M", "L", "F", "-"} * @return a formatter object set up with the current locale, if the specified style is correct, or {@code null} if * the style is invalid * @see org.joda.time.format.DateTimeFormat * @see org.joda.time.format.DateTimeFormat#forStyle(String) */ public DateTimeFormatter getDateTimeFormatterForStyle(String style) { try { return DateTimeFormat.forStyle(style).withLocale(this.localizationContext.getCurrentLocale()); } catch (IllegalArgumentException ex) { return null; } }
formatter = DateTimeFormat.forPattern(pattern); } else if (style != null) { formatter = DateTimeFormat.forStyle(style); } else {
formatter = DateTimeFormat.forPattern(pattern); } else if (style != null) { formatter = DateTimeFormat.forStyle(style); } else { formatter = DateTimeFormat.fullDateTime();
/** * Determines the root task name (e.g. "Workflow for adding XYZ (started 1.2.2014 10:34)") * TODO allow change processor to influence this name */ private LocalizableMessage determineRootTaskName(ModelContext<?> context) { String operationKey; if (context.getFocusContext() != null && context.getFocusContext().getPrimaryDelta() != null && context.getFocusContext().getPrimaryDelta().getChangeType() != null) { switch (context.getFocusContext().getPrimaryDelta().getChangeType()) { case ADD: operationKey = CREATION_OF_KEY; break; case DELETE: operationKey = DELETION_OF_KEY; break; case MODIFY: operationKey = CHANGE_OF_KEY; break; default: throw new IllegalStateException(); } } else { operationKey = CHANGE_OF_KEY; } ObjectType focus = MiscDataUtil.getFocusObjectNewOrOld(context); DateTimeFormatter formatter = DateTimeFormat.forStyle("MM").withLocale(Locale.getDefault()); String time = formatter.print(System.currentTimeMillis()); return new LocalizableMessageBuilder() .key(APPROVING_AND_EXECUTING_KEY + operationKey) .arg(ObjectTypeUtil.createDisplayInformation(asPrismObject(focus), false)) .arg(time) .build(); }