Package org.timepedia.chronoscope.client.util.date

Examples of org.timepedia.chronoscope.client.util.date.ChronoDate


  }
 
  public void testMillisecondPrecision() {
    // test precision using add()
    {
      ChronoDate d = ChronoDate.get(1980, 0, 1);
      double expectedTs = d.getTime();
      for (int i = 0; i < 10000; i++) {
        d.add(TimeUnit.MS, 1);
        expectedTs += 1.0;
        assertEquals(expectedTs, d.getTime());
      }
    }
   
    // test precision using setTime()
    {
      ChronoDate d = ChronoDate.get(1980, 0, 1);
      double expectedTs = d.getTime();
      for (int i = 0; i < 1000; i++) {
        ++expectedTs;
        d.setTime(expectedTs);
        assertEquals(expectedTs, d.getTime());
      }
    }
  }
View Full Code Here


    final int second = 59;
    final double ts = createJavaDate(year, month, day, hour, minute, second).getTime();
   
    // Set the time in milliseconds and verify that it's correctly translated into
    // the constituent date fields.
    ChronoDate d = createTestDate(1580);
    d.setTime(ts);
    assertEquals(year, month, day, hour, minute, second, d);
  }
View Full Code Here

    testSetTimeUnitFields(-5000, 11, 15, 15, 50, 23);
    testSetTimeUnitFields(-999999, 4, 2, 20, 1, 23);
  }
 
  public void testAddYears() {
    ChronoDate d = createTestDate(1195, 2, 15); // non-leapyear
    d.add(TimeUnit.YEAR, 300);
    assertEquals(1495, 2, 15, d);

    d = createTestDate(-750000, 5, 10);
    d.add(TimeUnit.YEAR, 100000);
    assertEquals(-650000, 5, 10, d);

    d = createTestDate(1575, 5, 10);
    d.add(TimeUnit.YEAR, 7);
    assertEquals(1582, 5, 10, d);

    d = createTestDate(1580, 5, 10);
    d.add(TimeUnit.YEAR, 4);
    assertEquals(1584, 5, 10, d);

    d = createTestDate(-100, 5, 10);
    d.add(TimeUnit.YEAR, 2600);
    assertEquals(2500, 5, 10, d);

    d = createTestDate(1901, 5, 10);
    d.add(TimeUnit.YEAR, 44);
    assertEquals(1945, 5, 10, d);

    d = createTestDate(1955, 5, 10);
    d.add(TimeUnit.YEAR, 100);
    assertEquals(2055, 5, 10, d);
  }
View Full Code Here

    d.add(TimeUnit.YEAR, 100);
    assertEquals(2055, 5, 10, d);
  }

  public void testAddMonths() {
    ChronoDate d = createTestDate(1576, 3, 15);
    d.add(TimeUnit.MONTH, 7);
    assertEquals(1576, 10, 15, d);
   
    d = createTestDate(1576, 3, 15);
    d.add(TimeUnit.MONTH, 15);
    assertEquals(1577, 6, 15, d);
   
    d = createTestDate(1580, 3, 15);
    d.add(TimeUnit.MONTH, 26);
    assertEquals(1582,5, 15, d);

    d = createTestDate(1580, 3, 15);
    d.add(TimeUnit.MONTH, 12*5+5);
    assertEquals(1585,8, 15, d);

    d = createTestDate(-100000, 11, 31);
    d.add(TimeUnit.MONTH, 5);
    assertEquals(-99999, 4, 31, d);
  }
View Full Code Here

    d.add(TimeUnit.MONTH, 5);
    assertEquals(-99999, 4, 31, d);
  }

  public void testAddDays() {
    ChronoDate d = createTestDate(1575, 1, 28); // non-leapyear
    d.add(TimeUnit.DAY, 2);
    assertEquals(1575, 2, 2, d);

    d = createTestDate(1576, 1, 28); // leapyear
    d.add(TimeUnit.DAY, 2);
    assertEquals(1576, 2, 1, d);

    d = createTestDate(-3, 11, 25); // non-leapyear
    d.add(TimeUnit.DAY, 10);
    assertEquals(-2, 0, 4, d);

    d = createTestDate(1581, 11, 25);
    d.add(TimeUnit.DAY, 10);
    assertEquals(1582, 0, 4, d);

    d = createTestDate(1582, 9, 1);
    d.add(TimeUnit.DAY, 15);
    assertEquals(1582, 9, 16, d);

    d = createTestDate(1582, 11, 25);
    d.add(TimeUnit.DAY, 10);
    assertEquals(1583, 0, 4, d);
   
    // Test that day overflow logic works:
    d = createTestDate(1975, 0, 31); // non-leapyear
    d.add(TimeUnit.DAY, 35);
    assertEquals(1975, 2, 7, d);
    d = createTestDate(1976, 0, 31); // leapyear
    d.add(TimeUnit.DAY, 35);
    assertEquals(1976, 2, 6, d);
    d = createTestDate(1976, 0, 1); // skip an entire year (leapyear)
    d.add(TimeUnit.DAY, 366);
    assertEquals(1977, 0, 1, d);
  }
View Full Code Here

    d.add(TimeUnit.DAY, 366);
    assertEquals(1977, 0, 1, d);
  }
 
  public void testAddWeeks() {
    ChronoDate d = createTestDate(2008, 1, 27); // leapyear
    d.add(TimeUnit.WEEK, 2);
    assertEquals(2008, 2, 12, d);

    d = createTestDate(2008, 1, 27); // leapyear
    d.add(TimeUnit.WEEK, 4);
    assertEquals(2008, 2, 26, d);

    // This test hits the Julian, JulianGregorianCrossover, and Gregorian EraCalc
    // subclasses.  Verifies that the day-of-week value is the same for each week
    // that we increment.
    d = createTestDate(1581, 0, 15);
    DayOfWeek dow = d.getDayOfWeek();
    for (int i = 0; i < (52 * 3); i++) {
      d.add(TimeUnit.WEEK, 1);
      assertEquals(dow, d.getDayOfWeek());
    }
  }
View Full Code Here

    }
  }

  public void testAdd_DECADE() {
    int year = 1892;
    ChronoDate d = ChronoDate.get(year, 1, 1);
   
    while (year < 4999) {
      d.add(TimeUnit.DECADE, 1);
      assertEquals(year + 10, d.getYear());
      year += 10;
    }
   
  }
View Full Code Here

   
  }
 
  public void testAdd_CENTURY() {
    int year = -5124;
    ChronoDate d = ChronoDate.get(year, 1, 1);
   
    while (year < 4999) {
      d.add(TimeUnit.CENTURY, 1);
      assertEquals(year + 100, d.getYear());
      year += 100;
    }
   
  }
View Full Code Here

    }
   
  }

  public void testTruncate() {
    ChronoDate d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.YEAR);
    assertEquals(1492, 0, 1, d);
   
    d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.MONTH);
    assertEquals(1492, 4, 1, d);

    d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.DAY);
    assertEquals(1492, 4, 21, d);

    d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.HOUR);
    assertEquals(1492, 4, 21, 23, 0, 0, d);

    d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.MIN);
    assertEquals(1492, 4, 21, 23, 56, 0, d);

    d = createTestDate(1492, 4, 21, 23, 56, 31, 555);
    d.truncate(TimeUnit.SEC);
    assertEquals(1492, 4, 21, 23, 56, 31, d);
  }
View Full Code Here

  /**
   * Week truncation requires special logic.  Test this functionality separately.
   */
  public void testTruncateWeek() {
    // Monday, Oct 13
    ChronoDate d = createTestDate(2008, 9, 13, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(2008, 9, 12, d);

    // Saturday, Oct 18
    d = createTestDate(2008, 9, 18, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(2008, 9, 12, d);

    // Friday, Oct 3
    d = createTestDate(2008, 9, 3, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(2008, 8, 28, d); // expect Sun, Sept 28 '08

    // Wed, Jan 2, 2008
    d = createTestDate(2008, 0, 2, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(2007, 11, 30, d); // expect Sun, Dec 30, '07

    // Sun, Jan 2, 1200
    d = createTestDate(1200, 0, 2, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(1200, 0, 2, d); // expect Sun, Jan 2, 1200

    // Sat, Jan 1, 1200
    d = createTestDate(1200, 0, 1, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(1199, 11, 26, d); // expect Sun, Dec 26, 1199

    // Tue, Mar 20, 1582
    d = createTestDate(1582, 2, 20, 23, 59, 59, 123);
    d.truncate(TimeUnit.WEEK);
    assertEquals(1582, 2, 18, d);
  }
View Full Code Here

TOP

Related Classes of org.timepedia.chronoscope.client.util.date.ChronoDate

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.