Java Code Examples for org.jfree.chart.axis.SegmentedTimeline#toMillisecond()
The following examples show how to use
org.jfree.chart.axis.SegmentedTimeline#toMillisecond() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test 4 checks 9.30am Friday 26 March 2004 (+ 1 millisecond) converts to * a timeline value and back again correctly. This is prior to Daylight * Saving. */ public void test4() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test4", value == (900000 * 34 + 900000 * 2 + 1) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 2
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test 4 checks 9.30am Friday 26 March 2004 (+ 1 millisecond) converts to * a timeline value and back again correctly. This is prior to Daylight * Saving. */ public void test4() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test4", value == (900000 * 34 + 900000 * 2 + 1) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 3
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 1 checks 9am Friday 26 March 2004 converts to a timeline value and * back again correctly. This is prior to Daylight Saving. */ public void test1() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Locale savedLocale = Locale.getDefault(); Locale.setDefault(Locale.UK); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue("test1", value == (900000 * 34) && date.getTime() == reverted.getTime()); TimeZone.setDefault(savedZone); Locale.setDefault(savedLocale); }
Example 4
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 7 checks 9am Monday 29 March 2004 converts to a timeline value and * back again correctly. This is during Daylight Saving. */ public void test7() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 5
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 6 checks that 9am on Sunday 28 March 2004 converts to the timeline * value and back again correctly. Note that Saturday and Sunday are * excluded from the timeline, so we expect the value to map to 9am on * Monday 29 March 2004. This is during daylight saving. */ public void test6() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 28); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 6
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 5 checks 5.30pm Thursday 25 March 2004 converts to a timeline * value and back again correctly. As it is in the excluded segment, we * expect it to map to 9am, Friday 26 March 2004. This is prior to * Daylight Saving. */ public void test5() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.HOUR_OF_DAY, 17); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 26); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test5", value == (900000 * 34) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 7
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 3 checks 9.30am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test3() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 8
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 2 checks 9.15am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test2() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 9
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 1 checks 9am Friday 26 March 2004 converts to a timeline value and * back again correctly. This is prior to Daylight Saving. */ public void test1() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Locale savedLocale = Locale.getDefault(); Locale.setDefault(Locale.UK); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue("test1", value == (900000 * 34) && date.getTime() == reverted.getTime()); TimeZone.setDefault(savedZone); Locale.setDefault(savedLocale); }
Example 10
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests translations between timelines. * * @param timeline the timeline to use for verifications. * @param startTest ??. */ public void verifyTranslations(SegmentedTimeline timeline, long startTest) { for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END; testCycle += TEST_CYCLE_INC) { long millisecond = startTest + testCycle * timeline.getSegmentSize(); SegmentedTimeline.Segment segment = timeline.getSegment( millisecond); for (int i = 0; i < 1000; i++) { long translatedValue = timeline.toTimelineValue( segment.getMillisecond()); long newValue = timeline.toMillisecond(translatedValue); if (segment.inExcludeSegments() || segment.inExceptionSegments()) { // the reverse transformed value will be in the start of the // next non-excluded and non-exception segment SegmentedTimeline.Segment tempSegment = segment.copy(); tempSegment.moveIndexToStart(); do { tempSegment.inc(); } while (!tempSegment.inIncludeSegments()); assertEquals(tempSegment.getMillisecond(), newValue); } else { assertEquals(segment.getMillisecond(), newValue); } segment.inc(); } } }
Example 11
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 7 checks 9am Monday 29 March 2004 converts to a timeline value and * back again correctly. This is during Daylight Saving. */ public void test7() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test7", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 12
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 6 checks that 9am on Sunday 28 March 2004 converts to the timeline * value and back again correctly. Note that Saturday and Sunday are * excluded from the timeline, so we expect the value to map to 9am on * Monday 29 March 2004. This is during daylight saving. */ public void test6() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 28); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test6", value == (900000 * 34 * 2) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 13
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 5 checks 5.30pm Thursday 25 March 2004 converts to a timeline * value and back again correctly. As it is in the excluded segment, we * expect it to map to 9am, Friday 26 March 2004. This is prior to * Daylight Saving. */ public void test5() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 25); cal.set(Calendar.HOUR_OF_DAY, 17); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(Locale.UK); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 26); expectedReverted.set(Calendar.HOUR_OF_DAY, 9); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test5", value == (900000 * 34) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 14
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 3 checks 9.30am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test3() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 30); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000 * 2) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 15
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Test 2 checks 9.15am Friday 26 March 2004 converts to a timeline value * and back again correctly. This is prior to Daylight Saving. */ public void test2() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 26); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); assertTrue( "test2", value == (900000 * 34 + 900000) && date.getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 16
Source File: SegmentedTimelineTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Tests translations between timelines. * * @param timeline the timeline to use for verifications. * @param startTest ??. */ public void verifyTranslations(SegmentedTimeline timeline, long startTest) { for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END; testCycle += TEST_CYCLE_INC) { long millisecond = startTest + testCycle * timeline.getSegmentSize(); SegmentedTimeline.Segment segment = timeline.getSegment( millisecond); for (int i = 0; i < 1000; i++) { long translatedValue = timeline.toTimelineValue( segment.getMillisecond()); long newValue = timeline.toMillisecond(translatedValue); if (segment.inExcludeSegments() || segment.inExceptionSegments()) { // the reverse transformed value will be in the start of the // next non-excluded and non-exception segment SegmentedTimeline.Segment tempSegment = segment.copy(); tempSegment.moveIndexToStart(); do { tempSegment.inc(); } while (!tempSegment.inIncludeSegments()); assertEquals(tempSegment.getMillisecond(), newValue); } else { assertEquals(segment.getMillisecond(), newValue); } segment.inc(); } } }
Example 17
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Test 8. */ public void test8() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 10); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); // Add exception in included segments cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); timeline.addException(cal.getTime()); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 10); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test8", value == (900000 * 34 * 2 + 900000 * (4 - 1)) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }
Example 18
Source File: SegmentedTimelineTests2.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Test 8. */ public void test8() { TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(Locale.UK); cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 10); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date date = cal.getTime(); SegmentedTimeline timeline = getTimeline(); // Add exception in included segments cal.set(Calendar.YEAR, 2004); cal.set(Calendar.MONTH, Calendar.MARCH); cal.set(Calendar.DAY_OF_MONTH, 29); cal.set(Calendar.HOUR_OF_DAY, 9); cal.set(Calendar.MINUTE, 15); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); timeline.addException(cal.getTime()); long value = timeline.toTimelineValue(date); long ms = timeline.toMillisecond(value); Calendar cal2 = Calendar.getInstance(Locale.UK); cal2.setTime(new Date(ms)); Date reverted = cal2.getTime(); Calendar expectedReverted = Calendar.getInstance(); expectedReverted.set(Calendar.YEAR, 2004); expectedReverted.set(Calendar.MONTH, Calendar.MARCH); expectedReverted.set(Calendar.DAY_OF_MONTH, 29); expectedReverted.set(Calendar.HOUR_OF_DAY, 10); expectedReverted.set(Calendar.MINUTE, 0); expectedReverted.set(Calendar.SECOND, 0); expectedReverted.set(Calendar.MILLISECOND, 0); assertTrue( "test8", value == (900000 * 34 * 2 + 900000 * (4 - 1)) && expectedReverted.getTime().getTime() == reverted.getTime() ); TimeZone.setDefault(savedZone); }