List of usage examples for org.joda.time.format DateTimeFormatterBuilder DateTimeFormatterBuilder
public DateTimeFormatterBuilder()
From source file:nc.noumea.mairie.organigramme.core.transformer.MSDateTransformer.java
License:Open Source License
@Override public void transform(Object arg0) { if (arg0 == null) { getContext().write(null);/*from w w w. j av a2 s. co m*/ return; } DateTime dt = new DateTime(arg0); DateTimeFormatter formater = new DateTimeFormatterBuilder().appendLiteral("/Date(") .appendLiteral(String.format("%s", dt.getMillis())).appendPattern("Z").appendLiteral(")/") .toFormatter(); getContext().writeQuoted(formater.print(dt)); }
From source file:nc.noumea.mairie.organigramme.core.utility.JsonDateSerializer.java
License:Open Source License
@Override public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException { if (date == null) { gen.writeNull();/* w w w .jav a 2 s .c o m*/ return; } DateTime dt = new DateTime(date); DateTimeFormatter formater = new DateTimeFormatterBuilder().appendLiteral("/Date(") .appendLiteral(String.format("%s", dt.getMillis())).appendPattern("Z").appendLiteral(")/") .toFormatter(); gen.writeString(formater.print(dt)); }
From source file:net.karlmartens.ui.widget.Calendar.java
License:Apache License
public Calendar(Composite parent, int style, Locale locale) { super(parent, style); final DateFormatSymbols symbols = DateFormatSymbols.getInstance(locale); _cal = java.util.Calendar.getInstance(locale); _titlePrinter = new DateTimeFormatterBuilder()// .appendMonthOfYearText()// .appendLiteral(' ')// .appendYear(4, 4)// .toFormatter();/*from ww w. j ava2s . c o m*/ _resourceManger = new LocalResourceManager(JFaceResources.getResources(getDisplay())); _date = new YearMonthDay(_cal); _month = _date.toYearMonth(); _minimum = _month.addYears(-100); _maximum = _month.addYears(100); final String[] weekdays = createCalendarWeekdays(_cal, symbols); _weekdayCount = weekdays.length; final Display display = getDisplay(); _alternateBackgroundColor = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); _selectionColor = display.getSystemColor(SWT.COLOR_LIST_SELECTION); final GridLayout layout = new GridLayout(_weekdayCount, false); layout.horizontalSpacing = 0; layout.marginHeight = 1; layout.marginWidth = 1; layout.verticalSpacing = 0; super.setLayout(layout); super.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); final Font titleFont = _resourceManger.createFont(FontDescriptor.createFrom("Arial", 12, SWT.BOLD)); _title = createBlock(); _title.setLayoutData(createLayoutData().span(_weekdayCount, 1).create()); _title.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); _title.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); _title.setFont(titleFont); final Font calendarFont = _resourceManger.createFont(FontDescriptor.createFrom("Arial", 10, SWT.NONE)); _blocks = new Block[_weekdayCount * ROW_COUNT]; for (int i = 0; i < _blocks.length; i++) { if (i == _weekdayCount) createSeparator(); final Block block = _blocks[i] = createBlock(); block.setLayoutData(createLayoutData().create()); block.setFont(calendarFont); if (i < _weekdayCount) { block.setText(weekdays[i]); continue; } } _requiresRefresh = true; new ListenerImpl(); final PassthoughEventListener pListener = new PassthoughEventListener(this); pListener.addSource(_title); for (int i = 0; i < _blocks.length; i++) pListener.addSource(_blocks[i]); }
From source file:net.karlmartens.ui.widget.CalendarCombo.java
License:Apache License
public static DateTimeFormatter createDateFormat() { final int pivotYear = DateSupport.currentYear() + 40; final DateTimeParser[] parsers = new DateTimeParser[] { // ///*from ww w. ja v a 2s. co m*/ new DateTimeFormatterBuilder()// .appendTwoDigitYear(pivotYear, false)// .appendLiteral('-')// .appendMonthOfYear(1)// .appendLiteral('-')// .appendDayOfMonth(1)// .toParser(), new DateTimeFormatterBuilder()// .appendYear(4, 4)// .appendLiteral('-')// .appendMonthOfYear(1)// .appendLiteral('-')// .appendDayOfMonth(1)// .toParser(), // new DateTimeFormatterBuilder()// .appendMonthOfYearShortText()// .appendLiteral(' ')// .appendDayOfMonth(1)// .appendLiteral(", ")// .appendTwoDigitYear(pivotYear, false)// .toParser(), // new DateTimeFormatterBuilder()// .appendMonthOfYearShortText()// .appendLiteral(' ')// .appendDayOfMonth(1)// .appendLiteral(", ")// .appendYear(4, 4)// .toParser(), // }; final DateTimePrinter printer = new DateTimeFormatterBuilder()// .appendYear(4, 4)// .appendLiteral('-')// .appendMonthOfYear(2)// .appendLiteral('-')// .appendDayOfMonth(2)// .toPrinter(); return new DateTimeFormatterBuilder()// .append(printer, parsers)// .toFormatter()// .withPivotYear(pivotYear); }
From source file:net.ripe.rpki.commons.FixedDateRule.java
License:BSD License
private static long convertDateTimeStringToMillis(String yyyymmdd) { DateTimeFormatter dateTimeParser = new DateTimeFormatterBuilder().appendYear(4, 4).appendMonthOfYear(2) .appendDayOfMonth(2).toFormatter().withZone(DateTimeZone.UTC); return dateTimeParser.parseDateTime(yyyymmdd).getMillis(); }
From source file:net.schweerelos.parrot.model.NodeWrapper.java
License:Open Source License
private String createToolTip(ParrotModel model) { if (!isOntResource()) { return ""; }/*from ww w . ja v a 2s . c o m*/ OntResource resource = getOntResource(); if (!resource.isIndividual() || resource.isProperty()) { return ""; } StringBuilder text = new StringBuilder(); // use extracted model to speed up reasoning OntModel ontModel = model.getOntModel(); ModelExtractor extractor = new ModelExtractor(ontModel); extractor.setSelector(StatementType.PROPERTY_VALUE); Model eModel = extractor.extractModel(); Resource eResource = eModel.getResource(resource.getURI()); StmtIterator props = eResource.listProperties(); while (props.hasNext()) { Statement statement = props.nextStatement(); Property pred = statement.getPredicate(); if (!pred.isURIResource()) { continue; } OntProperty ontPred = ontModel.getOntProperty(pred.getURI()); if (ontPred == null) { continue; } if (ParrotModelHelper.showTypeAsSecondary(ontModel, ontPred)) { // anything in the tooltip yet? if so, add line break text.append(text.length() > 0 ? "<br>" : ""); // put in extracted predicate label text.append(extractLabel(ontPred)); text.append(" "); RDFNode object = statement.getObject(); if (object.isLiteral()) { Literal literal = (Literal) object.as(Literal.class); String lexicalForm = literal.getLexicalForm(); if (literal.getDatatype().equals(XSDDatatype.XSDdateTime)) { DateTimeFormatter parser = ISODateTimeFormat.dateTimeParser(); DateTime dateTime = parser.parseDateTime(lexicalForm); DateTimeFormatterBuilder formatter = new DateTimeFormatterBuilder() .appendMonthOfYearShortText().appendLiteral(' ').appendDayOfMonth(1) .appendLiteral(", ").appendYear(4, 4).appendLiteral(", ").appendHourOfHalfday(1) .appendLiteral(':').appendMinuteOfHour(2).appendHalfdayOfDayText() .appendLiteral(" (").appendTimeZoneName().appendLiteral(", UTC") .appendTimeZoneOffset("", true, 1, 1).appendLiteral(')'); String prettyDateTime = formatter.toFormatter().print(dateTime); text.append(prettyDateTime); } else { text.append(lexicalForm); } } else if (object.isURIResource()) { OntResource ontObject = ontModel.getOntResource((Resource) object.as(Resource.class)); if (ontObject == null) { continue; } text.append(extractLabel(ontObject)); } } } // surround with html tags text.insert(0, "<html>"); text.append("</html>"); String result = text.toString(); if (result.equals("<html></html>")) { result = ""; } return result; }
From source file:nz.net.ultraq.jaxb.adapters.XMLLocalDateAdapter.java
License:Apache License
/** * Converts any ISO8601 date/time string into a Joda DateTime object. * // www . j a v a 2s. com * @param value * @return Joda DateTime. */ @Override public LocalDate unmarshal(String value) { return value == null ? null : new DateTimeFormatterBuilder() .append(ISODateTimeFormat.dateParser()).appendOptional(new DateTimeFormatterBuilder() .appendTimeZoneOffset("Z", true, 2, 4).toFormatter().getParser()) .toFormatter().parseLocalDate(value); }
From source file:org.alfresco.repo.content.metadata.TikaPoweredMetadataExtracter.java
License:Open Source License
public TikaPoweredMetadataExtracter(String extractorContext, HashSet<String> supportedMimeTypes, HashSet<String> supportedEmbedMimeTypes) { super(supportedMimeTypes, supportedEmbedMimeTypes); this.extractorContext = extractorContext; // TODO Once TIKA-451 is fixed this list will get nicer DateTimeParser[] parsersUTC = { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").getParser(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").getParser() }; DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss").getParser(), DateTimeFormat.forPattern("yyyy-MM-dd").getParser(), DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").getParser(), DateTimeFormat.forPattern("yyyy/MM/dd").getParser(), DateTimeFormat.forPattern("EEE MMM dd hh:mm:ss zzz yyyy").getParser() }; this.tikaUTCDateFormater = new DateTimeFormatterBuilder().append(null, parsersUTC).toFormatter() .withZone(DateTimeZone.UTC); this.tikaDateFormater = new DateTimeFormatterBuilder().append(null, parsers).toFormatter(); }
From source file:org.apache.arrow.vector.util.DateUtility.java
License:Apache License
public static DateTimeFormatter getDateTimeFormatter() { if (dateTimeTZFormat == null) { DateTimeFormatter dateFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTimeParser optionalTime = DateTimeFormat.forPattern(" HH:mm:ss").getParser(); DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser(); DateTimeParser optionalZone = DateTimeFormat.forPattern(" ZZZ").getParser(); dateTimeTZFormat = new DateTimeFormatterBuilder().append(dateFormatter).appendOptional(optionalTime) .appendOptional(optionalSec).appendOptional(optionalZone).toFormatter(); }// w w w . ja v a2 s . c o m return dateTimeTZFormat; }
From source file:org.apache.arrow.vector.util.DateUtility.java
License:Apache License
public static DateTimeFormatter getTimeFormatter() { if (timeFormat == null) { DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("HH:mm:ss"); DateTimeParser optionalSec = DateTimeFormat.forPattern(".SSS").getParser(); timeFormat = new DateTimeFormatterBuilder().append(timeFormatter).appendOptional(optionalSec) .toFormatter();//from w w w . j a v a 2 s .com } return timeFormat; }