Example usage for java.util GregorianCalendar setTimeZone

List of usage examples for java.util GregorianCalendar setTimeZone

Introduction

In this page you can find the example usage for java.util GregorianCalendar setTimeZone.

Prototype

@Override
    public void setTimeZone(TimeZone zone) 

Source Link

Usage

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

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *//*  w  ww .  j a v a  2s  . co m*/
@Test
public void testGetFirstMillisecondWithCalendar() {
    Year y = new Year(2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, y.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        y.getFirstMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 *//*from   w  ww.  j a v a2s  .  c o  m*/
@Test
public void testGetLastMillisecondWithCalendar() {
    Year y = new Year(2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(1009843199999L, y.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        y.getLastMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *//*w w  w .  ja  v  a  2s .  c  o  m*/
public void testGetFirstMillisecondWithCalendar() {
    Day d = new Day(1, 12, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(1007164800000L, d.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        d.getFirstMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *//*w  ww  .  j a v a2 s  . co m*/
@Test
public void testGetFirstMillisecondWithCalendar() {
    Month m = new Month(1, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, m.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 *///from ww  w .  j a  v a  2  s . c o m
@Test
public void testGetLastMillisecondWithCalendar() {
    Month m = new Month(3, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(986083199999L, m.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:org.springframework.integration.x.rollover.file.RolloverFileOutputStream.java

/**
 * @param filename//from  w ww. j a  va  2  s  .co m
 *            The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when
 *            creating and rolling over the file.
 * @param append
 *            If true, existing files will be appended to.
 * @param zone
 *            the timezone for the output
 * @param dateFormat
 *            The format for the date file substitution. The default is "yyyy_MM_dd".
 * @param rolloverStartTimeMs
 *            Defines the time in [ms] of the first file roll over process to start.
 * @param rolloverPeriodMs
 *            Defines the frequency (in ms) of the file roll over processes.
 * @throws IOException
 *             if unable to create output
 */
public RolloverFileOutputStream(String filename, boolean append, TimeZone zone, String dateFormat,
        long rolloverStartTimeMs, long rolloverPeriodMs, long maxRolledFileSize, String archivePrefix,
        boolean compressArchive, int bufferSize, FileCompressor fileCompressor) throws IOException {

    super(null);

    this.bufferSize = bufferSize;
    this.compressArchive = compressArchive;
    this.archivePrefix = archivePrefix;
    this.maxRolledFileSize = maxRolledFileSize;

    if (dateFormat == null) {
        dateFormat = ROLLOVER_FILE_DATE_FORMAT;
    }

    fileDateFormat = new SimpleDateFormat(dateFormat);

    if (StringUtils.isEmpty(filename)) {
        throw new IllegalArgumentException("Invalid filename");
    }

    filePath = filename.trim();
    fileDir = new File(new File(filename).getAbsolutePath()).getParentFile();

    if (fileDir != null && (!fileDir.isDirectory() || !fileDir.canWrite())) {
        throw new IOException("Cannot write into directory: " + fileDir);
    }

    appendToFile = append;
    setFile(true);

    synchronized (RolloverFileOutputStream.class) {

        if (rolloverTimer == null) {
            rolloverTimer = new Timer(RolloverFileOutputStream.class.getName(), true);
        }

        rollTask = new RollTask();

        Date startTime = null;
        if (rolloverStartTimeMs <= 0) {
            Calendar now = Calendar.getInstance();
            now.setTimeZone(zone);

            GregorianCalendar midnight = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH),
                    now.get(Calendar.DAY_OF_MONTH), 23, 0);
            midnight.setTimeZone(zone);
            midnight.add(Calendar.HOUR, 1);

            startTime = midnight.getTime();
        } else {
            startTime = new Date(rolloverStartTimeMs);
        }

        long period = (rolloverPeriodMs <= 0) ? 86400000 : rolloverPeriodMs;

        rolloverTimer.scheduleAtFixedRate(rollTask, startTime, period);
    }

    this.fileCompressor = fileCompressor;
}

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

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *///w  w w  .j  ava  2 s  . c  o m
@Test
public void testGetFirstMillisecondWithCalendar() {
    Quarter q = new Quarter(1, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, q.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        q.getFirstMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 *///from   ww w  .j  ava 2s  .c  o m
@Test
public void testGetLastMillisecondWithCalendar() {
    Quarter q = new Quarter(3, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(1001894399999L, q.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        q.getLastMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 *///w  ww  .  ja  v a2s .  c  o  m
public void testGetFirstMillisecondWithCalendar() {
    Month m = new Month(1, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(978307200000L, m.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 *//*from  www  .  j  a  v  a 2s  . c  o  m*/
public void testGetLastMillisecondWithCalendar() {
    Month m = new Month(3, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(986083199999L, m.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    } catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}