* {@link #YEAR_ABBR_MONTH} for something like "Sept 2012". If you don't want to use one of the predefined skeletons,
* you can supply your own. The skeletons are like the patterns in SimpleDateFormat, except they:
* <ol>
- * <li>only keep the field pattern letter and all other parts in a pattern, such as space, punctuation, and
+ * <li>only keep the field pattern letter and ignore all other parts in a pattern, such as space, punctuation, and
* string literals.
* <li>are independent of the order of fields.
* <li>ignore certain differences in the field's pattern letter length:
/*
-* Copyright (C) 2008-2011, International Business Machines
+* Copyright (C) 2008-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*/
private DateIntervalFormat() {
}
- /*
+ /**
* Construct a DateIntervalFormat from DateFormat,
* a DateIntervalInfo, and skeleton.
* DateFormat provides the timezone, calendar,
* @param locale the locale of this date interval formatter.
* @param dtitvinf the DateIntervalInfo object to be adopted.
* @param skeleton the skeleton of the date formatter
+ * @internal
+ * @deprecated This API is ICU internal only.
*/
- private DateIntervalFormat(ULocale locale, DateIntervalInfo dtItvInfo,
- String skeleton)
+ public DateIntervalFormat(String skeleton, DateIntervalInfo dtItvInfo,
+ DateTimePatternGenerator generator,
+ SimpleDateFormat simpleDateFormat)
{
+ SimpleDateFormat dateFormat = simpleDateFormat;
+ fDateFormat = dateFormat;
// freeze date interval info
dtItvInfo.freeze();
fSkeleton = skeleton;
fInfo = dtItvInfo;
- DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);
- final String bestPattern = generator.getBestPattern(skeleton);
- fDateFormat = new SimpleDateFormat(bestPattern, locale);
fFromCalendar = (Calendar) fDateFormat.getCalendar().clone();
fToCalendar = (Calendar) fDateFormat.getCalendar().clone();
initializePattern();
}
+
/**
* Construct a DateIntervalFormat from skeleton and the default <code>FORMAT</code> locale.
getInstance(String skeleton, ULocale locale)
{
DateIntervalInfo dtitvinf = new DateIntervalInfo(locale);
- return new DateIntervalFormat(locale, dtitvinf, skeleton);
+ DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);
+ return new DateIntervalFormat(skeleton, dtitvinf, generator, new SimpleDateFormat(generator.getBestPattern(skeleton), locale));
}
// clone. If it is frozen, clone returns itself, otherwise, clone
// returns a copy.
dtitvinf = (DateIntervalInfo)dtitvinf.clone();
- return new DateIntervalFormat(locale, dtitvinf, skeleton);
+ DateTimePatternGenerator generator = DateTimePatternGenerator.getInstance(locale);
+ return new DateIntervalFormat(skeleton, dtitvinf, generator, new SimpleDateFormat(generator.getBestPattern(skeleton), locale));
}
* @stable ICU 3.6
*/
public class DateTimePatternGenerator implements Freezable<DateTimePatternGenerator>, Cloneable {
+ private static final boolean DEBUG = false;
+
// debugging flags
//static boolean SHOW_DISTANCE = false;
// TODO add hack to fix months for CJK, as per bug ticket 1099
return result;
}
+ /**
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ public char getDefaultHourFormatChar() {
+ return defaultHourFormatChar;
+ }
+
+ /**
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ public void setDefaultHourFormatChar(char defaultHourFormatChar) {
+ this.defaultHourFormatChar = defaultHourFormatChar;
+ }
+
private static void hackTimes(DateTimePatternGenerator result, PatternInfo returnInfo, String hackPattern) {
result.fp.set(hackPattern);
StringBuilder mmss = new StringBuilder();
return addPatternWithSkeleton(pattern, null, override, returnInfo);
}
- /*
+ /**
* addPatternWithSkeleton:
* If skeletonToUse is specified, then an availableFormats entry is being added. In this case:
* 1. We pass that skeleton to DateTimeMatcher().set instead of having it derive a skeleton from the pattern.
* derived (i.e. entries derived from the standard date/time patters for the specified locale).
* 3. When adding the pattern (skeleton2pattern.put, basePattern_pattern.put), we set a field to indicate that the added
* entry had a specified skeleton.
+ * @internal
+ * @deprecated This API is ICU internal only.
*/
- private DateTimePatternGenerator addPatternWithSkeleton(String pattern, String skeletonToUse, boolean override, PatternInfo returnInfo) {
+ public DateTimePatternGenerator addPatternWithSkeleton(String pattern, String skeletonToUse, boolean override, PatternInfo returnInfo) {
checkFrozen();
DateTimeMatcher matcher;
if (skeletonToUse == null) {
returnInfo.status = PatternInfo.OK;
returnInfo.conflictingPattern = "";
PatternWithSkeletonFlag patWithSkelFlag = new PatternWithSkeletonFlag(pattern,skeletonToUse != null);
+ if (DEBUG) {
+ System.out.println(matcher + " => " + patWithSkelFlag);
+ }
skeleton2pattern.put(matcher, patWithSkelFlag);
basePattern_pattern.put(basePattern, patWithSkelFlag);
return this;
* @param pattern Input pattern, such as "dd/MMM"
* @return skeleton, such as "MMMdd"
* @internal
+ * @deprecated This API is ICU internal only.
*/
public String getSkeletonAllowingDuplicates(String pattern) {
synchronized (this) { // synchronized since a getter must be thread-safe
pattern = pat;
skeletonWasSpecified = skelSpecified;
}
+ public String toString() {
+ return pattern + "," + skeletonWasSpecified;
+ }
}
private TreeMap<DateTimeMatcher, PatternWithSkeletonFlag> skeleton2pattern = new TreeMap<DateTimeMatcher, PatternWithSkeletonFlag>(); // items are in priority order
private TreeMap<String, PatternWithSkeletonFlag> basePattern_pattern = new TreeMap<String, PatternWithSkeletonFlag>(); // items are in priority order