Timestatic
4016 ワード
public class Timestatic
{
private Date d1;
private Date d2;
private long late_time_all;
private long early_time_all;
private long extra_weekday_all;
private long extra_weekend_all;
private Calendar am = Const.am;
private Calendar pm = Const.pm;
private static SimpleDateFormat f = Const.timeFormat;
public Timestatic()
{
}
public Timestatic(Date d1, Date d2)
{
setParas(d1, d2);
}
public Date getD1()
{
return d1;
}
public void setD1(Date d1)
{
this.d1 = d1;
}
public Date getD2()
{
return d2;
}
public void setD2(Date d2)
{
this.d2 = d2;
}
public void setParas(Date d1, Date d2)
{
this.d1 = d1;
this.d2 = d2;
}
public String getEarly_time_all()
{
return " :"+toTime(early_time_all);
}
public void setEarly_time_all(long early_time_all)
{
this.early_time_all = early_time_all;
}
public String getLate_time_all()
{
return " :" + toTime(late_time_all);
}
public String getLateAndEarlyTimeAll()
{
return " :"+toTime(late_time_all+early_time_all);
}
public void setLate_time_all(long late_time_all)
{
this.late_time_all = late_time_all;
}
public String getExtra_weekend_all()
{
return " :"+toTime(extra_weekend_all);
}
public void setExtra_weekend_all(long extra_weekend_all)
{
this.extra_weekend_all = extra_weekend_all;
}
public String getExtra_weekday_all()
{
return " :"+toTime(extra_weekday_all);
}
public void setExtra_weekday_all(long extra_weekday_all)
{
this.extra_weekday_all = extra_weekday_all;
}
public long getSeconds(long seconds)
{
return seconds % 3600 % 60;
}
public long getMinits(long seconds)
{
return seconds % 3600 / 60;
}
public long getHours(long seconds)
{
return seconds / 3600;
}
public String getLate()
{
long late = (tr(d1).getTime() - tr(am.getTime()).getTime()) / 1000;
late_time_all += late;
return " :" + toTime(late);
}
public String getEarly_Leave()
{
long early = (tr(pm.getTime()).getTime() - tr(d2).getTime()) / 1000;
early_time_all += early;
return " :" + toTime(early);
}
public static Date tr(Date d)
{
Date da = null;
try
{
da = f.parse(f.format(d));
}
catch (ParseException e)
{
}
return da;
}
private String toTime(long seconds)
{
return getHours(seconds) + " " + getMinits(seconds) + " "
+ getSeconds(seconds) + " ";
}
@SuppressWarnings("deprecation")
public String toString()
{
if (d1.getDay() == 0 || d1.getDay() == 6 || d2.getDay() == 0 || d2.getDay() == 6)
{
long weekend = (tr(d2).getTime()-tr(d1).getTime()) / 1000;
extra_weekend_all += weekend;
return " :"+toTime(weekend);
}
d1 = tr(d1);
d2 = tr(d2);
Date a = tr(am.getTime());
Date p = tr(pm.getTime());
String res1 = (d1.after(a) ? getLate()+" " : "") + (d2.before(p) ? getEarly_Leave() : "");
String res2 = "";
if(d2.after(p))
{
long weekday = (d2.getTime() - p.getTime())/1000;
extra_weekday_all += weekday;
res2 = " :"+toTime(weekday);
}
return "".equals(res1) ? res2 : res1;
}
}