Example usage for java.util Calendar clear

List of usage examples for java.util Calendar clear

Introduction

In this page you can find the example usage for java.util Calendar clear.

Prototype

public final void clear() 

Source Link

Document

Sets all the calendar field values and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

private void testLocales(final String format, final boolean eraBC) throws Exception {

    final Calendar cal = Calendar.getInstance(GMT);
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 10);
    if (eraBC) {//from  w w w.  j  a v  a  2 s  .  c  o m
        cal.set(Calendar.ERA, GregorianCalendar.BC);
    }

    for (final Locale locale : Locale.getAvailableLocales()) {
        // ja_JP_JP cannot handle dates before 1868 properly
        if (eraBC && locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
            continue;
        }
        final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
        final DateParser fdf = getInstance(format, locale);

        try {
            checkParse(locale, cal, sdf, fdf);
        } catch (final ParseException ex) {
            Assert.fail("Locale " + locale + " failed with " + format + " era " + (eraBC ? "BC" : "AD") + "\n"
                    + trimMessage(ex.toString()));
        }
    }
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testDayOf() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 10);

    final DateParser fdf = getInstance("W w F D y", NEW_YORK, Locale.US);
    assertEquals(cal.getTime(), fdf.parse("3 7 2 41 03"));
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testParseNumerics() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 10, 15, 33, 20);
    cal.set(Calendar.MILLISECOND, 989);

    final DateParser fdf = getInstance("yyyyMMddHHmmssSSS", NEW_YORK, Locale.US);
    assertEquals(cal.getTime(), fdf.parse("20030210153320989"));
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testQuotes() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 10, 15, 33, 20);
    cal.set(Calendar.MILLISECOND, 989);

    final DateParser fdf = getInstance("''yyyyMMdd'A''B'HHmmssSSS''", NEW_YORK, Locale.US);
    assertEquals(cal.getTime(), fdf.parse("'20030210A'B153320989'"));
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

private Calendar getEraStart(int year, final TimeZone zone, final Locale locale) {
    final Calendar cal = Calendar.getInstance(zone, locale);
    cal.clear();

    // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/calendar.doc.html
    if (locale.equals(FastDateParser.JAPANESE_IMPERIAL)) {
        if (year < 1868) {
            cal.set(Calendar.ERA, 0);
            cal.set(Calendar.YEAR, 1868 - year);
        }//w w  w . jav  a 2s .  c o m
    } else {
        if (year < 0) {
            cal.set(Calendar.ERA, GregorianCalendar.BC);
            year = -year;
        }
        cal.set(Calendar.YEAR, year / 100 * 100);
    }
    return cal;
}

From source file:com.inkubator.hrm.service.impl.TempAttendanceRealizationServiceImpl.java

private static List<Date> getRangeOfDates(Date firstDate, Date secondDate) {
    List<Date> result = new ArrayList<Date>();
    Calendar cal = Calendar.getInstance();
    Date left;// w  w w  .ja  v  a2s  . c  om
    Date right;

    // Compare the dates to see which is less
    if (firstDate.compareTo(secondDate) < 0) {
        left = firstDate;
        right = secondDate;
    } else {
        right = firstDate;
        left = secondDate;
    }

    cal.clear();
    cal.setTime(left); // Seed the calendar with the starting date

    for (int i = 0; left.compareTo(right) < 0; i++) {
        result.add(left); // Add the date iterator value to the result set
        cal.add(Calendar.DATE, 1); // Add one day
        left = cal.getTime(); // Update the date iterator to the new date
    }

    return result;
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testLang996() throws ParseException {
    final Calendar expected = Calendar.getInstance(NEW_YORK, Locale.US);
    expected.clear();
    expected.set(2014, Calendar.MAY, 14);

    final DateParser fdp = getInstance("ddMMMyyyy", NEW_YORK, Locale.US);
    assertEquals(expected.getTime(), fdp.parse("14may2014"));
    assertEquals(expected.getTime(), fdp.parse("14MAY2014"));
    assertEquals(expected.getTime(), fdp.parse("14May2014"));
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testTzParses() throws Exception {
    // Check that all Locales can parse the time formats we use
    for (final Locale locale : Locale.getAvailableLocales()) {
        final FastDateParser fdp = new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);

        for (final TimeZone tz : new TimeZone[] { NEW_YORK, REYKJAVIK, GMT }) {
            final Calendar cal = Calendar.getInstance(tz, locale);
            cal.clear();
            cal.set(Calendar.YEAR, 2000);
            cal.set(Calendar.MONTH, 1);
            cal.set(Calendar.DAY_OF_MONTH, 10);
            final Date expected = cal.getTime();

            final Date actual = fdp.parse("2000/02/10 " + tz.getDisplayName(locale));
            Assert.assertEquals("tz:" + tz.getID() + " locale:" + locale.getDisplayName(), expected, actual);
        }/*from w  w  w. java2 s  .  com*/
    }
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testLang538() throws ParseException {
    final DateParser parser = getInstance("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", GMT);

    final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT-8"));
    cal.clear();
    cal.set(2009, Calendar.OCTOBER, 16, 8, 42, 16);

    assertEquals(cal.getTime(), parser.parse("2009-10-16T16:42:16.000Z"));
}

From source file:org.apache.logging.log4j.core.util.datetime.FastDateParserTest.java

@Test
public void testParseLongShort() throws ParseException {
    final Calendar cal = Calendar.getInstance(NEW_YORK, Locale.US);
    cal.clear();
    cal.set(2003, Calendar.FEBRUARY, 10, 15, 33, 20);
    cal.set(Calendar.MILLISECOND, 989);
    cal.setTimeZone(NEW_YORK);/*from   ww w . jav a  2s  .  c  o  m*/

    DateParser fdf = getInstance("yyyy GGGG MMMM dddd aaaa EEEE HHHH mmmm ssss SSSS ZZZZ", NEW_YORK, Locale.US);

    assertEquals(cal.getTime(), fdf.parse("2003 AD February 0010 PM Monday 0015 0033 0020 0989 GMT-05:00"));
    cal.set(Calendar.ERA, GregorianCalendar.BC);

    final Date parse = fdf.parse("2003 BC February 0010 PM Saturday 0015 0033 0020 0989 GMT-05:00");
    assertEquals(cal.getTime(), parse);

    fdf = getInstance("y G M d a E H m s S Z", NEW_YORK, Locale.US);
    assertEquals(cal.getTime(), fdf.parse("03 BC 2 10 PM Sat 15 33 20 989 -0500"));

    cal.set(Calendar.ERA, GregorianCalendar.AD);
    assertEquals(cal.getTime(), fdf.parse("03 AD 2 10 PM Saturday 15 33 20 989 -0500"));
}