I found that TimePeriod is very useful,such as Day,Month,Hour,Minute.
With TimePeriod, I found a convenience way to display date in domain axis.
However, I couldn't find a TimePeriod which represent quarter of an hour and the Quarter TimePeriod delegated quarter of a year.
I wrote a class named MinQuarter, but it had not finished. I hope someone will finish it .
thanks
The code is:
package com.jrefinery.data;
import com.jrefinery.date.*;
import java.util.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: MBARI Proprietary Information. All rights reserved.</p>
* @author not attributable
* @version 0.1
*/
public class MinQuarter extends TimePeriod {
//constants
/**
* the constants for quarter 1 in an hour
*/
private static int FIRST_QUARTER_IN_HOUR = 0;
/**
* the constants for quarter 4 in an hour
*/
private static int LAST_QUARTER_IN_HOUR = 3;
/**
* the hour
*/
protected Hour hour;
/**
* the minute
*/
//protected Minute minute;
/**
* the quarter
*/
protected int quar;
/**
* Constructs a new MinQuarter, based on the system date/time.
*/
public MinQuarter() {
this(new Date());
}
/**
* Constructs a new MinQuarter ,
* @param quar quarter
* @param hour Hour
*/
public MinQuarter (int quar , Hour hour) {
this.quar = quar;
this.hour = hour;
}
/**
*
* @param time The date/time.
*/
public MinQuarter( Date time) {
this(time,TimePeriod.DEFAULT_TIME_ZONE);
}
/**
* Constructs a MinQuarter, based on a date/time and time zone.
* @param time The date/time.
* @param zone The zone.
*/
public MinQuarter( Date time , TimeZone zone) {
Calendar calendar = Calendar.getInstance(zone);
calendar.setTime(time);
hour = new Hour(calendar.getTime());
int min = calendar.get(Calendar.MINUTE);
// this.minute = new Minute(calendar.getTime());
// int min = minute.getMinute();
quar = (min-15)/15;
}
/**
* returns the quarter of an hour
* @return hour
*/
public int getMinQuarter() {
return this.quar;
}
/**
* returns the hour
* @return hour
*/
public Hour getHour () {
return this.hour;
}
/**
* returns the day of the quarter
* @return day
*/
public Day getDay() {
return this.hour.getDay();
}
/**
*
* @return previous Quarter
*/
public TimePeriod previous() {
MinQuarter result;
if(this.quar != this.FIRST_QUARTER_IN_HOUR) {
result = new MinQuarter(quar-1,hour);
}
else {
Hour prevHour = (Hour)hour.previous();
if(prevHour != null) {
result = new MinQuarter(this.LAST_QUARTER_IN_HOUR,prevHour);
}
else
result = null;
}
return result;
}
/**
*
* @return next quarter
*/
public TimePeriod next() {
/**@todo Implement this com.jrefinery.data.TimePeriod abstract method*/
MinQuarter result;
if (this.quar != LAST_QUARTER_IN_HOUR) {
result = new MinQuarter(quar+1,hour);
}
else {
Hour nextHour = (Hour)hour.next();
if (nextHour != null)
{
result = new MinQuarter(this.FIRST_QUARTER_IN_HOUR,nextHour);
}
else
result = null;
}
return result;
}
/**
* Tests the equality of this object against an arbitrary Object.
* @param object an object to be test.
* @return true or false
*/
public boolean equals(Object object) {
if(object instanceof MinQuarter) {
MinQuarter mq = (MinQuarter)object;
return ((this.quar == mq.getMinQuarter()) && this.hour.equals(mq.getHour()));
}
else
return false;
}
public long getEnd(Calendar calendar) {
/**@todo Implement this com.jrefinery.data.TimePeriod abstract method*/
throw new java.lang.UnsupportedOperationException("Method getEnd() not yet implemented.");
}
public int compareTo(Object o) {
/**@todo Implement this java.lang.Comparable abstract method*/
throw new java.lang.UnsupportedOperationException("Method compareTo() not yet implemented.");
}
/**
*
* @param calendar
* @return
*/
public long getStart(Calendar calendar) {
return 0;
}
}
can't find quarter of an hour?
-
- Posts: 2
- Joined: Tue Jul 08, 2003 8:44 am
- Location: hangzhou china
- Contact: