org.jfree.data.time.Minute Java Examples

The following examples show how to use org.jfree.data.time.Minute. 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: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Minute m = new Minute(40, 2, 15, 4, 2000);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(955766400000L, m.getFirstMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #2
Source File: CategoricalChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #3
Source File: Chart.java    From crypto-bot with Apache License 2.0 6 votes vote down vote up
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
	// Running the strategy
	TimeSeriesManager seriesManager = new TimeSeriesManager(series);
	List<Trade> trades = seriesManager.run(strategy).getTrades();
	// Adding markers to plot
	for (Trade trade : trades) {
		// Buy signal
		double buySignalTickTime = new Minute(
				Date.from(series.getBar(trade.getEntry().getIndex()).getEndTime().toInstant()))
						.getFirstMillisecond();
		Marker buyMarker = new ValueMarker(buySignalTickTime);
		buyMarker.setPaint(Color.GREEN);
		buyMarker.setLabel("B");
		plot.addDomainMarker(buyMarker);
		// Sell signal
		double sellSignalTickTime = new Minute(
				Date.from(series.getBar(trade.getExit().getIndex()).getEndTime().toInstant()))
						.getFirstMillisecond();
		Marker sellMarker = new ValueMarker(sellSignalTickTime);
		sellMarker.setPaint(Color.RED);
		sellMarker.setLabel("S");
		plot.addDomainMarker(sellMarker);
	}
}
 
Example #4
Source File: XYAreaLineChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #5
Source File: BuyAndSellSignalsToChart.java    From ta4j-origins with MIT License 6 votes vote down vote up
/**
 * Runs a strategy over a time series and adds the value markers
 * corresponding to buy/sell signals to the plot.
 * @param series a time series
 * @param strategy a trading strategy
 * @param plot the plot
 */
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
    // Running the strategy
    TimeSeriesManager seriesManager = new TimeSeriesManager(series);
    List<Trade> trades = seriesManager.run(strategy).getTrades();
    // Adding markers to plot
    for (Trade trade : trades) {
        // Buy signal
        double buySignalTickTime = new Minute(Date.from(series.getTick(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker buyMarker = new ValueMarker(buySignalTickTime);
        buyMarker.setPaint(Color.GREEN);
        buyMarker.setLabel("B");
        plot.addDomainMarker(buyMarker);
        // Sell signal
        double sellSignalTickTime = new Minute(Date.from(series.getTick(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker sellMarker = new ValueMarker(sellSignalTickTime);
        sellMarker.setPaint(Color.RED);
        sellMarker.setLabel("S");
        plot.addDomainMarker(sellMarker);
    }
}
 
Example #6
Source File: XYChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private int getDateUnitAsInt( final Class domainTimePeriod ) {
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.SECOND;
  }
  if ( Minute.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MINUTE;
  }
  if ( Hour.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.HOUR;
  }
  if ( Day.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.DAY;
  }
  if ( Month.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MONTH;
  }
  if ( Year.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.YEAR;
  }
  if ( Second.class.equals( domainTimePeriod ) ) {
    return DateTickUnit.MILLISECOND;
  }
  return DateTickUnit.DAY;
}
 
Example #7
Source File: ChartConstants.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #8
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Minute m = new Minute(45, 21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(987889559999L, m.getLastMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #9
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithCalendar() {
    Minute m = new Minute(40, 2, 15, 4, 2000);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));        
    assertEquals(955766400000L, m.getFirstMillisecond(calendar));
    
    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #10
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithTimeZone() {
    Minute m = new Minute(59, 15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-623289660000L, m.getFirstMillisecond(c));
    
    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);            
}
 
Example #11
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithCalendar() {
    Minute m = new Minute(45, 21, 21, 4, 2001);
    GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY);
    calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt"));
    assertEquals(987889559999L, m.getLastMillisecond(calendar));

    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #12
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithTimeZone() {
    Minute m = new Minute(1, 2, 7, 7, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-614962680001L, m.getLastMillisecond(c));

    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #13
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond(TimeZone) method.
 */
public void testGetFirstMillisecondWithTimeZone() {
    Minute m = new Minute(59, 15, 1, 4, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-623289660000L, m.getFirstMillisecond(c));

    // try null calendar
    boolean pass = false;
    try {
        m.getFirstMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #14
Source File: TimeSeriesCollectorFunction.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
private static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #15
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getLastMillisecond(TimeZone) method.
 */
public void testGetLastMillisecondWithTimeZone() {
    Minute m = new Minute(1, 2, 7, 7, 1950);
    TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles");
    Calendar c = new GregorianCalendar(zone);
    assertEquals(-614962680001L, m.getLastMillisecond(c));
    
    // try null calendar
    boolean pass = false;
    try {
        m.getLastMillisecond((Calendar) null);
    }
    catch (NullPointerException e) {
        pass = true;
    }
    assertTrue(pass);            
}
 
Example #16
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getEnd() method.
 */
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getEnd());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #17
Source File: BuyAndSellSignalsToChart.java    From ta4j-origins with MIT License 5 votes vote down vote up
/**
 * Builds a JFreeChart time series from a Ta4j time series and an indicator.
 * @param tickSeries the ta4j time series
 * @param indicator the indicator
 * @param name the name of the chart time series
 * @return the JFreeChart time series
 */
private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator<Decimal> indicator, String name) {
    org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name);
    for (int i = 0; i < tickSeries.getTickCount(); i++) {
        Tick tick = tickSeries.getTick(i);
        chartTimeSeries.add(new Minute(Date.from(tick.getEndTime().toInstant())), indicator.getValue(i).toDouble());
    }
    return chartTimeSeries;
}
 
Example #18
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getFirstMillisecond() method.
 */
public void testGetFirstMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(43, 15, 1, 4, 2006);
    assertEquals(1143902580000L, m.getFirstMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #19
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getStart() method.
 */
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getStart());
    Locale.setDefault(saved);       
    TimeZone.setDefault(savedZone);
}
 
Example #20
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getEnd() method.
 */
public void testGetEnd() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59);
    cal.set(Calendar.MILLISECOND, 999);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getEnd());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #21
Source File: SecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Second second1 = new Second(34, minute1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    Second second2 = new Second(34, minute2);
    assertTrue(second1.equals(second2));
}
 
Example #22
Source File: KafkaFT.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
private static JFreeChart createChart(XYDataset xydataset) {
	JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Flink Exactly-Once on Kafka with YARN Chaos Monkey", "Date", "Value", xydataset, true, true, false);
	XYPlot xyplot = (XYPlot) jfreechart.getPlot();

	XYLineAndShapeRenderer r0 = (XYLineAndShapeRenderer) xyplot.getRenderer(0);

	// draw data points as points
	r0.setSeriesShapesVisible(2, true);
	r0.setSeriesLinesVisible(2, true);
	// order elements as assed
	xyplot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);

	DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();

	Number first = xydataset.getX(0, 0);
	Minute minute = new Minute(new Date((Long)first));
	System.out.println("first = "+first);
	RelativeDateFormat relativedateformat = new RelativeDateFormat(minute.getFirstMillisecond());
	relativedateformat.setSecondFormatter(new DecimalFormat("00"));
	dateaxis.setDateFormatOverride(relativedateformat);


	//dateaxis.setDateFormatOverride(new SimpleDateFormat("mm:ss"));
	ValueAxis valueaxis = xyplot.getRangeAxis();
	valueaxis.setAutoRangeMinimumSize(1.0D);
	valueaxis.setLabel("Elements/Core");

	xyplot.getRenderer().setSeriesPaint(2, ChartColor.DARK_MAGENTA);
	return jfreechart;
}
 
Example #23
Source File: CashFlowToChart.java    From ta4j-origins with MIT License 5 votes vote down vote up
/**
 * Builds a JFreeChart time series from a Ta4j time series and an indicator.
 * @param tickSeries the ta4j time series
 * @param indicator the indicator
 * @param name the name of the chart time series
 * @return the JFreeChart time series
 */
private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator<Decimal> indicator, String name) {
    org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name);
    for (int i = 0; i < tickSeries.getTickCount(); i++) {
        Tick tick = tickSeries.getTick(i);
        chartTimeSeries.add(new Minute(new Date(tick.getEndTime().toEpochSecond() * 1000)), indicator.getValue(i).toDouble());
    }
    return chartTimeSeries;
}
 
Example #24
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    assertTrue(minute1.equals(minute2));
}
 
Example #25
Source File: MillisecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Second second1 = new Second(34, minute1);
    Millisecond milli1 = new Millisecond(999, second1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    Second second2 = new Second(34, minute2);
    Millisecond milli2 = new Millisecond(999, second2);
    assertTrue(milli1.equals(milli2));
}
 
Example #26
Source File: SecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the equals method.
 */
public void testEquals() {
    Day day1 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour1 = new Hour(15, day1);
    Minute minute1 = new Minute(15, hour1);
    Second second1 = new Second(34, minute1);
    Day day2 = new Day(29, MonthConstants.MARCH, 2002);
    Hour hour2 = new Hour(15, day2);
    Minute minute2 = new Minute(15, hour2);
    Second second2 = new Second(34, minute2);
    assertTrue(second1.equals(second2));
}
 
Example #27
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getStart() method.
 */
public void testGetStart() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.ITALY);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome"));
    Calendar cal = Calendar.getInstance(Locale.ITALY);
    cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Minute m = new Minute(47, 3, 16, 1, 2006);
    assertEquals(cal.getTime(), m.getStart());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #28
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the getLastMillisecond() method.
 */
public void testGetLastMillisecond() {
    Locale saved = Locale.getDefault();
    Locale.setDefault(Locale.UK);
    TimeZone savedZone = TimeZone.getDefault();
    TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
    Minute m = new Minute(1, 1, 1, 1, 1970);
    assertEquals(119999L, m.getLastMillisecond());
    Locale.setDefault(saved);
    TimeZone.setDefault(savedZone);
}
 
Example #29
Source File: AccessLogTable.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
void addPoint(TimeSeries bytesSentData, TimeSeries timeTookData, TimeSeries nreqData, Date date, long bytes,
    long count, long timeTook) {

  bytesSentData.add(new Minute(date), bytes / 1000. / 1000.);
  double latency = (double) timeTook / count / 1000.;
  // timeTookData.add(new Minute(date), (latency > 10*1000) ? 0 : latency); // note latency limited to 10 secs.
  timeTookData.add(new Minute(date), latency);
  nreqData.add(new Minute(date), (double) count);
}
 
Example #30
Source File: MinuteTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * In Singapore, the 4.55pm on 21 Mar 2002 is 
 * java.util.Date(1,014,281,700,000L). Use this to check the Minute 
 * constructor.
 */
public void testDateConstructor2() {

    TimeZone zone = TimeZone.getTimeZone("Asia/Singapore");
    Calendar c = new GregorianCalendar(zone);
    Minute m1 = new Minute(new Date(1016700899999L), zone);
    Minute m2 = new Minute(new Date(1016700900000L), zone);

    assertEquals(54, m1.getMinute());
    assertEquals(1016700899999L, m1.getLastMillisecond(c));

    assertEquals(55, m2.getMinute());
    assertEquals(1016700900000L, m2.getFirstMillisecond(c));

}