org.joda.time.format.DateTimeFormatterBuilder Java Examples

The following examples show how to use org.joda.time.format.DateTimeFormatterBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TikaPoweredMetadataExtracter.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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();
}
 
Example #2
Source File: FieldInjectorRegistry.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
@Override
protected DateTimeFormatter initialValue() {
	return new DateTimeFormatterBuilder()
		.append(DateTimeFormat.forPattern("yyyy-MM-dd"))                                            
		.appendOptional(
				new DateTimeFormatterBuilder()
					.appendLiteral('T')
					.appendOptional(
							new DateTimeFormatterBuilder()
								.append(DateTimeFormat.forPattern("HH"))
								.appendOptional(
										new DateTimeFormatterBuilder()
											.append(DateTimeFormat.forPattern(":mm"))
												.appendOptional(
														new DateTimeFormatterBuilder()
															.append(DateTimeFormat.forPattern(":ss"))
														.toParser())
										.toParser())
							.toParser())
				.toParser())
		.toFormatter();
}
 
Example #3
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
static String getLocalAMString(DateTime now) {
	//we need an AM date
	DateTime dt = now.withTimeAtStartOfDay();
	Locale locale= new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example #4
Source File: Time_25_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #5
Source File: Time_17_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #6
Source File: Time_17_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #7
Source File: Time_23_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #8
Source File: Time_23_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #9
Source File: Time_19_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #10
Source File: Time_19_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #11
Source File: Time_9_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #12
Source File: Time_9_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #13
Source File: Time_8_DateTimeZone_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #14
Source File: Time_8_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #15
Source File: Time_25_DateTimeZone_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #16
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
static String getLocalPMString(DateTime now) {
	//we need an PM date
	DateTime dt = now.withTimeAtStartOfDay().plusHours(14);
	Locale locale = new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example #17
Source File: DateTimeZone.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #18
Source File: DateTimeZone.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #19
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
static String getLocalAMString(DateTime now) {
	//we need an AM date
	DateTime dt = now.withTimeAtStartOfDay();
	Locale locale= new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example #20
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
static String getLocalPMString(DateTime now) {
	//we need an PM date
	DateTime dt = now.withTimeAtStartOfDay().plusHours(14);
	Locale locale = new ResourceLoader("calendar").getLocale();
	DateTimeFormatter df = new DateTimeFormatterBuilder().appendHalfdayOfDayText().toFormatter().withLocale(locale);
	return df.print(dt);
}
 
Example #21
Source File: ParseTime.java    From h2o-2 with Apache License 2.0 5 votes vote down vote up
public static String listTimezones() {
  DateTimeFormatter offsetFormatter = new DateTimeFormatterBuilder().appendTimeZoneOffset(null, true, 2, 4).toFormatter();
  Set<String> idSet = DateTimeZone.getAvailableIDs();
  Map<String, String> tzMap = new TreeMap();
  Iterator<String>  it = idSet.iterator();
  String id, cid, offset, key, output;
  DateTimeZone tz;
  int i = 0;
  long millis = System.currentTimeMillis();


  // collect canonical and alias IDs into a map
  while (it.hasNext()) {
    id = it.next();
    tz = DateTimeZone.forID(id);
    cid = tz.getID();
    offset = offsetFormatter.withZone(tz).print(tz.getStandardOffset(millis));
    key = offset + " " + cid;
    if (id == cid) { // Canonical ID
      if (!tzMap.containsKey(key)) tzMap.put(key, "");
    }  else {// alias ID
      if (!tzMap.containsKey(key)) tzMap.put(key, id);
      else tzMap.put(key,  tzMap.get(key) + ", " + id);
    }
  }

  // assemble result
  output = "StandardOffset CanonicalID, Aliases\n";
  for (Map.Entry<String, String> e : tzMap.entrySet())
    output += e.getKey() + e.getValue()+"\n";

  return output;
}
 
Example #22
Source File: EntityDateHelperTest.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
@Test
public void testIsPastOrCurrentDateWithDate() {
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate("2010-05-23", DateTime.parse("2011-05-23", DateHelper.getDateTimeFormat()), EntityNames.DISCIPLINE_INCIDENT));
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate("2011-05-23", DateTime.parse("2011-05-23", DateHelper.getDateTimeFormat()), EntityNames.DISCIPLINE_INCIDENT));
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate(null, DateTime.now(), EntityNames.DISCIPLINE_INCIDENT));  // Assuming there's no date changeover between date creation and usage.
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate("2012-11-11", DateTime.parse("2012-11-11T00:00:00"), EntityNames.DISCIPLINE_INCIDENT));  // Assuming there's no date changeover between date creation and usage.
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate("2012-11-11", DateTime.parse("2012-11-11T23:59:59.999"), EntityNames.DISCIPLINE_INCIDENT));  // Assuming there's no date changeover between date creation and usage.
    Assert.assertTrue(EntityDateHelper.isPastOrCurrentDate(null, DateTime.now().minusMillis(1), EntityNames.DISCIPLINE_INCIDENT));  // Assuming there's no date changeover between date creation and usage.
    DateTimeFormatter datefrmt = new DateTimeFormatterBuilder().appendYear(4, 4).appendLiteral('-').appendMonthOfYear(2).appendLiteral('-').appendDayOfMonth(2).toFormatter();
    Assert.assertFalse(EntityDateHelper.isPastOrCurrentDate(datefrmt.print(DateTime.now().plusDays(1)), DateTime.now(), EntityNames.DISCIPLINE_INCIDENT));  // Assuming there's no date changeover between date creation and usage.
    Assert.assertFalse(EntityDateHelper.isPastOrCurrentDate(null, DateTime.now().minusDays(1), EntityNames.DISCIPLINE_INCIDENT));
    Assert.assertFalse(EntityDateHelper.isPastOrCurrentDate(null, DateTime.parse("2012-11-11"), EntityNames.DISCIPLINE_INCIDENT));  // Assuming no one sets the date on this machine before December 11th, 2012.
}
 
Example #23
Source File: Joda.java    From crate with Apache License 2.0 5 votes vote down vote up
public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
    // 2014/10/10
    DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .toFormatter()
            .withZoneUTC();

    // 2014/10/10 12:12:12
    DateTimeFormatter longFormatter = new DateTimeFormatterBuilder()
            .appendFixedDecimal(DateTimeFieldType.year(), 4)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
            .appendLiteral('/')
            .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
            .appendLiteral(' ')
            .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2)
            .appendLiteral(':')
            .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2)
            .toFormatter()
            .withZoneUTC();

    DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)});

    return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}
 
Example #24
Source File: Nopol2017_0089_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #25
Source File: JodaDateUtility.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
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();
    }

    return dateTimeTZFormat;
  }
 
Example #26
Source File: JodaDateUtility.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
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();
  }
  return timeFormat;
}
 
Example #27
Source File: Helper.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
public static DateTime ConvertFromWebService(String strDate) {
	DateTimeFormatter parser1 = new DateTimeFormatterBuilder().append(ISODateTimeFormat.date()).appendLiteral('T')
			.append(ISODateTimeFormat.hourMinuteSecond()).appendOptional(fractionElement())
			.appendOptional(offsetElement()).toFormatter().withZone(DateTimeZone.UTC);
	parser1.withChronology(ISOChronology.getInstanceUTC());
	return parser1.parseDateTime(strDate);
}
 
Example #28
Source File: Cardumen_00189_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #29
Source File: Cardumen_00189_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}
 
Example #30
Source File: Cardumen_00239_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Gets a printer/parser for managing the offset id formatting.
 * 
 * @return the formatter
 */
private static synchronized DateTimeFormatter offsetFormatter() {
    if (cOffsetFormatter == null) {
        cOffsetFormatter = new DateTimeFormatterBuilder()
            .appendTimeZoneOffset(null, true, 2, 4)
            .toFormatter();
    }
    return cOffsetFormatter;
}