Timestatic

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;
	}
}

 

你可能感兴趣的:(F#)