Examples of PatternInfo


Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

             */
            return fDateFormat.format(fromCalendar, appendTo, pos);
        }
       
        // get interval pattern
        PatternInfo intervalPattern = fIntervalPatterns.get(
              DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);

        if ( intervalPattern == null ) {
            if ( fDateFormat.isFieldUnitIgnored(field) ) {
                /* the largest different calendar field is small than
                 * the smallest calendar field in pattern,
                 * return single date format.
                 */
                return fDateFormat.format(fromCalendar, appendTo, pos);
            }

            return fallbackFormat(fromCalendar, toCalendar, appendTo, pos);
        }

        // If the first part in interval pattern is empty,
        // the 2nd part of it saves the full-pattern used in fall-back.
        // For a 'real' interval pattern, the first part will never be empty.
        if ( intervalPattern.getFirstPart() == null ) {
            // fall back
            return fallbackFormat(fromCalendar, toCalendar, appendTo, pos,
                                    intervalPattern.getSecondPart());
        }
        Calendar firstCal;
        Calendar secondCal;
        if ( intervalPattern.firstDateInPtnIsLaterDate() ) {
            firstCal = toCalendar;
            secondCal = fromCalendar;
        } else {
            firstCal = fromCalendar;
            secondCal = toCalendar;
        }
        // break the interval pattern into 2 parts
        // first part should not be empty,
        String originalPattern = fDateFormat.toPattern();
        fDateFormat.applyPattern(intervalPattern.getFirstPart());
        fDateFormat.format(firstCal, appendTo, pos);
        if ( intervalPattern.getSecondPart() != null ) {
            fDateFormat.applyPattern(intervalPattern.getSecondPart());
            fDateFormat.format(secondCal, appendTo, pos);
        }
        fDateFormat.applyPattern(originalPattern);
        return appendTo;
    }
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

                    String pattern =dtpng.getBestPattern(timeSkeleton);
                    // for fall back interval patterns,
                    // the first part of the pattern is empty,
                    // the second part of the pattern is the full-pattern
                    // should be used in fall-back.
                    PatternInfo ptn = new PatternInfo(null, pattern,
                                                     fInfo.getDefaultOrder());
                    intervalPatterns.put(DateIntervalInfo.
                        CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.DATE], ptn);
                    // share interval pattern
                    intervalPatterns.put(DateIntervalInfo.
                        CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.MONTH], ptn);
                    // share interval pattern
                    intervalPatterns.put(DateIntervalInfo.
                        CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.YEAR], ptn);
                } else {
                    //genFallbackForNotFound(Calendar.DATE, skeleton);
                    //genFallbackForNotFound(Calendar.MONTH, skeleton);
                    //genFallbackForNotFound(Calendar.YEAR, skeleton);
                }
            } else {
                    //genFallbackForNotFound(Calendar.DATE, skeleton);
                    //genFallbackForNotFound(Calendar.MONTH, skeleton);
                    //genFallbackForNotFound(Calendar.YEAR, skeleton);
            }
            return intervalPatterns;
        } // end of skeleton not found
        // interval patterns for skeleton are found in resource
        if ( time.length() == 0 ) {
            // done
        } else if ( date.length() == 0 ) {
            // need to set up patterns for y/M/d differ
            /* result from following looks confusing.
             * for example: 10 10:10 - 11 10:10, it is not
             * clear that the first 10 is the 10th day
            time.insert(0, 'd');
            genFallbackPattern(Calendar.DATE, time);
            time.insert(0, 'M');
            genFallbackPattern(Calendar.MONTH, time);
            time.insert(0, 'y');
            genFallbackPattern(Calendar.YEAR, time);
            */
            // prefix with yMd
            timeSkeleton = DateFormat.YEAR_NUM_MONTH_DAY + timeSkeleton;
            String pattern =dtpng.getBestPattern(timeSkeleton);
            // for fall back interval patterns,
            // the first part of the pattern is empty,
            // the second part of the pattern is the full-pattern
            // should be used in fall-back.
            PatternInfo ptn = new PatternInfo(
                                    null, pattern, fInfo.getDefaultOrder());
            intervalPatterns.put(DateIntervalInfo.
                CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.DATE], ptn);
            intervalPatterns.put(DateIntervalInfo.
                CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.MONTH], ptn);
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

        String pattern = dtpng.getBestPattern(skeleton);
        // for fall back interval patterns,
        // the first part of the pattern is empty,
        // the second part of the pattern is the full-pattern
        // should be used in fall-back.
        PatternInfo ptn = new PatternInfo(
                                    null, pattern, fInfo.getDefaultOrder());
        intervalPatterns.put(
            DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptn);
    }
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

     */
    private SkeletonAndItsBestMatch genIntervalPattern(
                   int field, String skeleton, String bestSkeleton,
                   int differenceInfo, Map<String, PatternInfo> intervalPatterns) {
        SkeletonAndItsBestMatch retValue = null;
        PatternInfo pattern = fInfo.getIntervalPattern(
                                           bestSkeleton, field);
        if ( pattern == null ) {
            // single date
            if ( SimpleDateFormat.isFieldUnitIgnored(bestSkeleton, field) ) {
                PatternInfo ptnInfo =
                    new PatternInfo(fDateFormat.toPattern(),
                                                     null,
                                                     fInfo.getDefaultOrder());
                intervalPatterns.put(DateIntervalInfo.
                    CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptnInfo);
                return null;
            }

            // for 24 hour system, interval patterns in resource file
            // might not include pattern when am_pm differ,
            // which should be the same as hour differ.
            // add it here for simplicity
            if ( field == Calendar.AM_PM ) {
                 pattern = fInfo.getIntervalPattern(bestSkeleton,
                                                         Calendar.HOUR);
                 if ( pattern != null ) {
                      // share
                      intervalPatterns.put(DateIntervalInfo.
                          CALENDAR_FIELD_TO_PATTERN_LETTER[field],
                          pattern);
                 }
                 return null;
            }
            // else, looking for pattern when 'y' differ for 'dMMMM' skeleton,
            // first, get best match pattern "MMMd",
            // since there is no pattern for 'y' differs for skeleton 'MMMd',
            // need to look for it from skeleton 'yMMMd',
            // if found, adjust field width in interval pattern from
            // "MMM" to "MMMM".
            String fieldLetter =
                DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field];
            bestSkeleton = fieldLetter + bestSkeleton;
            skeleton = fieldLetter + skeleton;
            // for example, looking for patterns when 'y' differ for
            // skeleton "MMMM".
            pattern = fInfo.getIntervalPattern(bestSkeleton, field);
            if ( pattern == null && differenceInfo == 0 ) {
                // if there is no skeleton "yMMMM" defined,
                // look for the best match skeleton, for example: "yMMM"
                BestMatchInfo tmpRetValue = fInfo.getBestSkeleton(skeleton);
                String tmpBestSkeleton = tmpRetValue.bestMatchSkeleton;
                differenceInfo =  tmpRetValue.bestMatchDistanceInfo;
                if ( tmpBestSkeleton.length() != 0 && differenceInfo != -1 ) {
                    pattern = fInfo.getIntervalPattern(tmpBestSkeleton, field);
                    bestSkeleton = tmpBestSkeleton;
                }
            }
            if ( pattern != null ) {
                retValue = new SkeletonAndItsBestMatch(skeleton, bestSkeleton);
            }
        }
        if ( pattern != null ) {
            if ( differenceInfo != 0 ) {
                String part1 = adjustFieldWidth(skeleton, bestSkeleton,
                                   pattern.getFirstPart(), differenceInfo);
                String part2 = adjustFieldWidth(skeleton, bestSkeleton,
                                   pattern.getSecondPart(), differenceInfo);
                pattern =  new PatternInfo(part1, part2,
                                           pattern.firstDateInPtnIsLaterDate());
            } else {
                // pattern is immutable, no need to clone;
                // pattern = (PatternInfo)pattern.clone();
            }
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

                                               String datePattern,
                                               int field,
                                               Map<String, PatternInfo> intervalPatterns)
    {

        PatternInfo  timeItvPtnInfo =
            intervalPatterns.get(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);
        if ( timeItvPtnInfo != null ) {
            String timeIntervalPattern = timeItvPtnInfo.getFirstPart() +
                                         timeItvPtnInfo.getSecondPart();
            String pattern = MessageFormat.format(dtfmt, new Object[]
                                         {timeIntervalPattern, datePattern});
            timeItvPtnInfo = DateIntervalInfo.genPatternInfo(pattern,
                                timeItvPtnInfo.firstDateInPtnIsLaterDate());
            intervalPatterns.put(
              DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], timeItvPtnInfo);
        }
        // else: fall back
        // it should not happen if the interval format defined is valid
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

       */
      return fDateFormat.format(fromCalendar, appendTo, pos);
    }

    // get interval pattern
    PatternInfo intervalPattern = fIntervalPatterns.get(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);

    if (intervalPattern == null) {
      if (fDateFormat.isFieldUnitIgnored(field)) {
        /* the largest different calendar field is small than
         * the smallest calendar field in pattern,
         * return single date format.
         */
        return fDateFormat.format(fromCalendar, appendTo, pos);
      }

      return fallbackFormat(fromCalendar, toCalendar, appendTo, pos);
    }

    // If the first part in interval pattern is empty,
    // the 2nd part of it saves the full-pattern used in fall-back.
    // For a 'real' interval pattern, the first part will never be empty.
    if (intervalPattern.getFirstPart() == null) {
      // fall back
      return fallbackFormat(fromCalendar, toCalendar, appendTo, pos, intervalPattern.getSecondPart());
    }
    Calendar firstCal;
    Calendar secondCal;
    if (intervalPattern.firstDateInPtnIsLaterDate()) {
      firstCal = toCalendar;
      secondCal = fromCalendar;
    } else {
      firstCal = fromCalendar;
      secondCal = toCalendar;
    }
    // break the interval pattern into 2 parts
    // first part should not be empty,
    String originalPattern = fDateFormat.toPattern();
    fDateFormat.applyPattern(intervalPattern.getFirstPart());
    fDateFormat.format(firstCal, appendTo, pos);
    if (intervalPattern.getSecondPart() != null) {
      fDateFormat.applyPattern(intervalPattern.getSecondPart());
      fDateFormat.format(secondCal, appendTo, pos);
    }
    fDateFormat.applyPattern(originalPattern);
    return appendTo;
  }
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

          String pattern = dtpng.getBestPattern(timeSkeleton);
          // for fall back interval patterns,
          // the first part of the pattern is empty,
          // the second part of the pattern is the full-pattern
          // should be used in fall-back.
          PatternInfo ptn = new PatternInfo(null, pattern, fInfo.getDefaultOrder());
          intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.DATE], ptn);
          // share interval pattern
          intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.MONTH], ptn);
          // share interval pattern
          intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.YEAR], ptn);
        } else {
          //genFallbackForNotFound(Calendar.DATE, skeleton);
          //genFallbackForNotFound(Calendar.MONTH, skeleton);
          //genFallbackForNotFound(Calendar.YEAR, skeleton);
        }
      } else {
        //genFallbackForNotFound(Calendar.DATE, skeleton);
        //genFallbackForNotFound(Calendar.MONTH, skeleton);
        //genFallbackForNotFound(Calendar.YEAR, skeleton);
      }
      return intervalPatterns;
    } // end of skeleton not found
      // interval patterns for skeleton are found in resource
    if (time.length() == 0) {
      // done
    } else if (date.length() == 0) {
      // need to set up patterns for y/M/d differ
      /* result from following looks confusing.
       * for example: 10 10:10 - 11 10:10, it is not
       * clear that the first 10 is the 10th day
      time.insert(0, 'd');
      genFallbackPattern(Calendar.DATE, time);
      time.insert(0, 'M');
      genFallbackPattern(Calendar.MONTH, time);
      time.insert(0, 'y');
      genFallbackPattern(Calendar.YEAR, time);
      */
      // prefix with yMd
      timeSkeleton = DateFormat.YEAR_NUM_MONTH_DAY + timeSkeleton;
      String pattern = dtpng.getBestPattern(timeSkeleton);
      // for fall back interval patterns,
      // the first part of the pattern is empty,
      // the second part of the pattern is the full-pattern
      // should be used in fall-back.
      PatternInfo ptn = new PatternInfo(null, pattern, fInfo.getDefaultOrder());
      intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.DATE], ptn);
      intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.MONTH], ptn);
      intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[Calendar.YEAR], ptn);
    } else {
      /* if both present,
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

    String pattern = dtpng.getBestPattern(skeleton);
    // for fall back interval patterns,
    // the first part of the pattern is empty,
    // the second part of the pattern is the full-pattern
    // should be used in fall-back.
    PatternInfo ptn = new PatternInfo(null, pattern, fInfo.getDefaultOrder());
    intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptn);
  }
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

   *          null otherwise.
   */
  private SkeletonAndItsBestMatch genIntervalPattern(final int field, String skeleton, String bestSkeleton, int differenceInfo,
      final Map<String, PatternInfo> intervalPatterns) {
    SkeletonAndItsBestMatch retValue = null;
    PatternInfo pattern = fInfo.getIntervalPattern(bestSkeleton, field);
    if (pattern == null) {
      // single date
      if (SimpleDateFormat.isFieldUnitIgnored(bestSkeleton, field)) {
        PatternInfo ptnInfo = new PatternInfo(fDateFormat.toPattern(), null, fInfo.getDefaultOrder());
        intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], ptnInfo);
        return null;
      }

      // for 24 hour system, interval patterns in resource file
      // might not include pattern when am_pm differ,
      // which should be the same as hour differ.
      // add it here for simplicity
      if (field == Calendar.AM_PM) {
        pattern = fInfo.getIntervalPattern(bestSkeleton, Calendar.HOUR);
        if (pattern != null) {
          // share
          intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], pattern);
        }
        return null;
      }
      // else, looking for pattern when 'y' differ for 'dMMMM' skeleton,
      // first, get best match pattern "MMMd",
      // since there is no pattern for 'y' differs for skeleton 'MMMd',
      // need to look for it from skeleton 'yMMMd',
      // if found, adjust field width in interval pattern from
      // "MMM" to "MMMM".
      String fieldLetter = DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field];
      bestSkeleton = fieldLetter + bestSkeleton;
      skeleton = fieldLetter + skeleton;
      // for example, looking for patterns when 'y' differ for
      // skeleton "MMMM".
      pattern = fInfo.getIntervalPattern(bestSkeleton, field);
      if (pattern == null && differenceInfo == 0) {
        // if there is no skeleton "yMMMM" defined,
        // look for the best match skeleton, for example: "yMMM"
        BestMatchInfo tmpRetValue = fInfo.getBestSkeleton(skeleton);
        String tmpBestSkeleton = tmpRetValue.bestMatchSkeleton;
        differenceInfo = tmpRetValue.bestMatchDistanceInfo;
        if (tmpBestSkeleton.length() != 0 && differenceInfo != -1) {
          pattern = fInfo.getIntervalPattern(tmpBestSkeleton, field);
          bestSkeleton = tmpBestSkeleton;
        }
      }
      if (pattern != null) {
        retValue = new SkeletonAndItsBestMatch(skeleton, bestSkeleton);
      }
    }
    if (pattern != null) {
      if (differenceInfo != 0) {
        String part1 = adjustFieldWidth(skeleton, bestSkeleton, pattern.getFirstPart(), differenceInfo);
        String part2 = adjustFieldWidth(skeleton, bestSkeleton, pattern.getSecondPart(), differenceInfo);
        pattern = new PatternInfo(part1, part2, pattern.firstDateInPtnIsLaterDate());
      } else {
        // pattern is immutable, no need to clone;
        // pattern = (PatternInfo)pattern.clone();
      }
      intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], pattern);
View Full Code Here

Examples of com.ibm.icu.text.DateIntervalInfo.PatternInfo

   * @param intervalPatterns       interval patterns
   */
  private void concatSingleDate2TimeInterval(final String dtfmt, final String datePattern, final int field,
      final Map<String, PatternInfo> intervalPatterns) {

    PatternInfo timeItvPtnInfo = intervalPatterns.get(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field]);
    if (timeItvPtnInfo != null) {
      String timeIntervalPattern = timeItvPtnInfo.getFirstPart() + timeItvPtnInfo.getSecondPart();
      String pattern = MessageFormat.format(dtfmt, new Object[] { timeIntervalPattern, datePattern });
      timeItvPtnInfo = DateIntervalInfo.genPatternInfo(pattern, timeItvPtnInfo.firstDateInPtnIsLaterDate());
      intervalPatterns.put(DateIntervalInfo.CALENDAR_FIELD_TO_PATTERN_LETTER[field], timeItvPtnInfo);
    }
    // else: fall back
    // it should not happen if the interval format defined is valid
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.