示例#1
0
  @Test
  public void testDateConversion() {
    Field f =
        Data.makeColumnField(
            "a",
            "label",
            new Object[] {"Jan 4, 1980", "Jan 4, 1988", "a", "2", null, "Jan 9, 1978"});

    Field g = Data.toDate(f, null);
    assertNotEquals(f, g);
    assertEquals("a", g.name);
    assertEquals("label", g.label);
    assertEquals(6, g.rowCount());
    assertEquals(3, g.valid());

    // Should not change
    assertEquals(g, Data.toDate(g, null));
  }
示例#2
0
  @Test
  public void testDateConversionForBadDates() {
    Object[] data = new Object[1000];
    for (int i = 0; i < data.length; i++) data[i] = i % 10 == 0 ? "name" : "-";
    Field f = Data.makeColumnField("a", "label", data);
    Field g = Data.toDate(f);
    assertNotEquals(f, g);

    assertEquals("a", g.name);
    assertEquals("label", g.label);
    assertEquals(1000, g.rowCount());
    assertEquals(0, g.valid());
  }
示例#3
0
  @Test
  public void testDate() {
    Field a;

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:00:01"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(1.0 / 3600 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.second, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:04:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(4.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:06:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(6.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 00:45:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(45.0 / 60 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.minute, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 04:59:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(DateUnit.hour, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 1, 1970 05:00:00"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(5.0 / 24, a.max(), 1e-9);
    assertEquals(DateUnit.hour, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 1, 1970", "January 4, 1970"}));
    assertEquals(0.0, a.min(), 1e-9);
    assertEquals(3.0, a.max(), 1e-9);
    assertEquals(DateUnit.day, a.property("dateUnit"));

    // Note that only three days are needed to get days as a unit -- this an exception to the usual
    // "5 ticks" rule
    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 2, 1970"}));
    assertEquals(1.0, a.min(), 1e-9);
    assertEquals(9.0, a.max(), 1e-9);
    assertEquals(DateUnit.day, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField("a", "label", new Object[] {"January 10, 1970", "March 2, 1970"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(60.0, a.max(), 1e-9);
    assertEquals(DateUnit.week, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "December 31, 1970"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(364.0, a.max(), 1e-9);
    assertEquals(DateUnit.quarter, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1972"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(2 * 365 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.quarter, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1974"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(4 * 365 + 1 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.year, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 1976"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(6 * 365 + 1 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.year, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.makeColumnField(
                "a", "label", new Object[] {"January 10, 1970", "January 10, 2030"}));
    assertEquals(9.0, a.min(), 1e-9);
    assertEquals(60 * 365 + 15 + 9, a.max(), 1e-9);
    assertEquals(DateUnit.decade, a.property("dateUnit"));

    a =
        Data.toDate(
            Data.toDate(
                Data.makeColumnField("a", "label", new Object[] {"09:45:22", "09:45:24"}), null));
    assertEquals((9 + 45 / 60.0 + 22 / 3600.0) / 24.0, a.min(), 1e-9);
    assertEquals((9 + 45 / 60.0 + 24 / 3600.0) / 24.0, a.max(), 1e-9);
    assertEquals(DateUnit.second, a.property("dateUnit"));
  }