Package java.text

Examples of java.text.ParsePosition


        Assert.assertEquals(0, pos.getErrorIndex());
    }

    @Test
    public void testForgottenSuffix() {
        ParsePosition pos = new ParsePosition(0);
        Assert.assertNull(new Vector1DFormat().parse("{1 ", pos));
        Assert.assertEquals(2, pos.getErrorIndex());
    }
View Full Code Here


  public void testPastXIntervals() {
    Macro m = new Macro(1234567890000L, "select '[past_5_minutes]';");
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long time = 0;
    Date result = null;
    result = format.parse(m.toString(), new ParsePosition(8));
    time = result.getTime()+300000L;
    assertTrue(time<=1234567890000L);
    m = new Macro(1234567890000L, "select '[past_hour]';");
    result = format.parse(m.toString(), new ParsePosition(8));
    time = result.getTime()+3600000L;
    assertTrue(time<=1234567890000L);
    m = new Macro(1234567890000L, "select '[start]';");
    result = format.parse(m.toString(), new ParsePosition(8));
    time = result.getTime();
    assertTrue(time==1234567890000L);
  }
View Full Code Here

    long startTime = 0;
    long endTime = 0;
    long aggregatorStart = Calendar.getInstance().getTimeInMillis();
    long longest = 0;
    if(args.length>=4) {
      ParsePosition pp = new ParsePosition(0);
      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
      String buffer = args[0]+" "+args[1];
      Date tmp = format.parse(buffer, pp);
      startTime = tmp.getTime();
      buffer = args[2]+" "+args[3];
      pp = new ParsePosition(0);
      tmp = format.parse(buffer, pp);
      endTime = tmp.getTime();
    }
    String longQuery = null;
    log.info("Aggregator started.");
View Full Code Here

     */

    public static long
    parseTime(String time) {
  try {
      return dateFormat.parse(time.trim(),new ParsePosition(0)).getTime();
  } catch (Exception e) {
      return 0;
  }
    }
View Full Code Here

  calendar.setTimeZone(TimeZone.getTimeZone(zone));
    }

    ClockToken[] dt = GetTokens(dateString);

    ParsePosition parsePos = new ParsePosition(0);
    ClockRelTimespan diff = new ClockRelTimespan();
    int hasTime = 0;
    int hasZone = 0;
    int hasDate = 0;
    int hasDay = 0;
    int hasRel = 0;

    while (parsePos.getIndex() < dt.length) {
        if (ParseTime(dt, parsePos, calendar)) {
      hasTime++;
  } else if (ParseZone(dt, parsePos, calendar)) {
      hasZone++;
  } else if (ParseDate(dt, parsePos, calendar)) {
View Full Code Here

private static ClockToken[]
GetTokens (
    String in    // String to parse
)
{
    ParsePosition parsePos = new ParsePosition(0);
    ClockToken dt;
    Vector tokenVector = new Vector(in.length());

    while ((dt = GetNextToken(in, parsePos)) != null) {
        tokenVector.addElement(dt);
View Full Code Here

   * @throws ConversionException
   *             Thrown if parsing fails
   */
  protected C parse(final Format format, final Object value, final Locale locale)
  {
    final ParsePosition position = new ParsePosition(0);
    final String stringValue = value.toString();
    final C result = (C)format.parseObject(stringValue, position);
    if (position.getIndex() != stringValue.length())
    {
      throw newConversionException("Cannot parse '" + value + "' using format " + format,
        value, locale).setFormat(format);
    }
    return result;
View Full Code Here

    public static String convertDate(String dateIn, String fromDateFormat, String toDateFormat) {
        String dateOut;
        try {
            SimpleDateFormat formatIn = new SimpleDateFormat(fromDateFormat);
            SimpleDateFormat formatOut= new SimpleDateFormat(toDateFormat);
            Date data = formatIn.parse(dateIn, new ParsePosition(0));
            dateOut = formatOut.format(data);
        } catch (Exception e) {
            dateOut = null;
        }
        return dateOut;
View Full Code Here

        while (timePos != -1)
        {
            String timeText = completeFile.substring(timePos - 8, timePos + 8);

            // Parse time from response
            ParsePosition position = new ParsePosition(0);
            SimpleDateFormat format = new SimpleDateFormat();
            format.applyPattern("HH:mm:ss'##TIME##'");
            format.parse(timeText, position);

            // Recalculate time for local offset
View Full Code Here

            // success
        }
    }

    public void testForgottenImaginaryCharacter() {
        ParsePosition pos = new ParsePosition(0);
        assertNull(new ComplexFormat().parse("1 + 1", pos));
        assertEquals(5, pos.getErrorIndex());
    }
View Full Code Here

TOP

Related Classes of java.text.ParsePosition

Copyright © 2018 www.massapicom. 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.