Example usage for org.jfree.data.time Day parseDay

List of usage examples for org.jfree.data.time Day parseDay

Introduction

In this page you can find the example usage for org.jfree.data.time Day parseDay.

Prototype

public static Day parseDay(String s) 

Source Link

Document

Parses the string argument as a day.

Usage

From source file:org.jfree.data.time.DayTest.java

/**
 * Problem for date parsing.//from  w  w w.j  a  va 2  s  .  c  o m
 * <p>
 * This test works only correct if the short pattern of the date
 * format is "dd/MM/yyyy". If not, this test will result in a
 * false negative.
 *
 * @throws ParseException on parsing errors.
 */
@Test
public void testParseDay() throws ParseException {
    GregorianCalendar gc = new GregorianCalendar(2001, 12, 31);
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    Date reference = format.parse("31/12/2001");
    if (reference.equals(gc.getTime())) {
        // test 1...
        Day d = Day.parseDay("31/12/2001");
        assertEquals(37256, d.getSerialDate().toSerial());
    }

    // test 2...
    Day d = Day.parseDay("2001-12-31");
    assertEquals(37256, d.getSerialDate().toSerial());
}

From source file:org.jfree.data.time.junit.DayTest.java

/**
 * Problem for date parsing./*from   w w w.  j  av a2 s . c  om*/
 * <p>
 * This test works only correct if the short pattern of the date
 * format is "dd/MM/yyyy". If not, this test will result in a
 * false negative.
 *
 * @throws ParseException on parsing errors.
 */
public void testParseDay() throws ParseException {
    GregorianCalendar gc = new GregorianCalendar(2001, 12, 31);
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
    Date reference = format.parse("31/12/2001");
    if (reference.equals(gc.getTime())) {
        // test 1...
        Day d = Day.parseDay("31/12/2001");
        assertEquals(37256, d.getSerialDate().toSerial());
    }

    // test 2...
    Day d = Day.parseDay("2001-12-31");
    assertEquals(37256, d.getSerialDate().toSerial());
}

From source file:org.jfree.data.time.Second.java

/**
 * Creates a new instance by parsing a string.  The string is assumed to
 * be in the format "YYYY-MM-DD HH:MM:SS", perhaps with leading or trailing
 * whitespace./*  w  ww .j  a va 2 s  .  co m*/
 *
 * @param s  the string to parse.
 *
 * @return The second, or <code>null</code> if the string is not parseable.
 */
public static Second parseSecond(String s) {
    Second result = null;
    s = s.trim();
    String daystr = s.substring(0, Math.min(10, s.length()));
    Day day = Day.parseDay(daystr);
    if (day != null) {
        String hmsstr = s.substring(Math.min(daystr.length() + 1, s.length()), s.length());
        hmsstr = hmsstr.trim();

        int l = hmsstr.length();
        String hourstr = hmsstr.substring(0, Math.min(2, l));
        String minstr = hmsstr.substring(Math.min(3, l), Math.min(5, l));
        String secstr = hmsstr.substring(Math.min(6, l), Math.min(8, l));
        int hour = Integer.parseInt(hourstr);

        if ((hour >= 0) && (hour <= 23)) {

            int minute = Integer.parseInt(minstr);
            if ((minute >= 0) && (minute <= 59)) {

                Minute m = new Minute(minute, new Hour(hour, day));
                int second = Integer.parseInt(secstr);
                if ((second >= 0) && (second <= 59)) {
                    result = new Second(second, m);
                }
            }
        }
    }
    return result;
}

From source file:org.jfree.data.time.Hour.java

/**
 * Creates an Hour instance by parsing a string.  The string is assumed to
 * be in the format "YYYY-MM-DD HH", perhaps with leading or trailing
 * whitespace.//ww  w  .  j  ava  2 s. c  o m
 *
 * @param s  the hour string to parse.
 *
 * @return <code>null</code> if the string is not parseable, the hour
 *         otherwise.
 */
public static Hour parseHour(String s) {
    Hour result = null;
    s = s.trim();

    String daystr = s.substring(0, Math.min(10, s.length()));
    Day day = Day.parseDay(daystr);
    if (day != null) {
        String hourstr = s.substring(Math.min(daystr.length() + 1, s.length()), s.length());
        hourstr = hourstr.trim();
        int hour = Integer.parseInt(hourstr);
        // if the hour is 0 - 23 then create an hour
        if ((hour >= FIRST_HOUR_IN_DAY) && (hour <= LAST_HOUR_IN_DAY)) {
            result = new Hour(hour, day);
        }
    }

    return result;
}

From source file:org.jfree.data.time.Minute.java

/**
 * Creates a Minute instance by parsing a string.  The string is assumed to
 * be in the format "YYYY-MM-DD HH:MM", perhaps with leading or trailing
 * whitespace.// w w  w .jav  a  2  s  .  c  o m
 *
 * @param s  the minute string to parse.
 *
 * @return <code>null</code>, if the string is not parseable, the minute
 *      otherwise.
 */
public static Minute parseMinute(String s) {
    Minute result = null;
    s = s.trim();

    String daystr = s.substring(0, Math.min(10, s.length()));
    Day day = Day.parseDay(daystr);
    if (day != null) {
        String hmstr = s.substring(Math.min(daystr.length() + 1, s.length()), s.length());
        hmstr = hmstr.trim();

        String hourstr = hmstr.substring(0, Math.min(2, hmstr.length()));
        int hour = Integer.parseInt(hourstr);

        if ((hour >= 0) && (hour <= 23)) {
            String minstr = hmstr.substring(Math.min(hourstr.length() + 1, hmstr.length()), hmstr.length());
            int minute = Integer.parseInt(minstr);
            if ((minute >= 0) && (minute <= 59)) {
                result = new Minute(minute, new Hour(hour, day));
            }
        }
    }
    return result;
}

From source file:grafix.telas.TelaComparativos.java

private Vector<IndiceComparativo> gerarIndices() {
    Vector<IndiceComparativo> resultado = new Vector<IndiceComparativo>();
    Day dataComparacao = Day.parseDay(comboData.getSelectedItem().toString());
    resultado.add(new IndiceComparativo(Controle.getCarteira().getAcao(combo1.getSelectedItem().toString()),
            dataComparacao));//from   w  w w  .  j  a  va2  s.c o  m
    if (cb2.isSelected()) {
        resultado.add(new IndiceComparativo(Controle.getCarteira().getAcao(combo2.getSelectedItem().toString()),
                dataComparacao));
    }
    if (cb3.isSelected()) {
        resultado.add(new IndiceComparativo(Controle.getCarteira().getAcao(combo3.getSelectedItem().toString()),
                dataComparacao));
    }
    if (cb4.isSelected()) {
        resultado.add(new IndiceComparativo(Controle.getCarteira().getAcao(combo4.getSelectedItem().toString()),
                dataComparacao));
    }
    if (cb5.isSelected()) {
        resultado.add(new IndiceComparativo(Controle.getCarteira().getAcao(combo5.getSelectedItem().toString()),
                dataComparacao));
    }
    return resultado;
}