forked from LupusNobilis/java-org.hwo
80 lines
1.3 KiB
Java
80 lines
1.3 KiB
Java
package org.hwo.datetime;
|
|
|
|
public class TimeOfDay {
|
|
|
|
public static int getHours(int secondsOfDay)
|
|
{
|
|
return secondsOfDay / 3600;
|
|
}
|
|
public static int getMinutes(int secondsOfDay)
|
|
{
|
|
return (secondsOfDay % 3600) / 60;
|
|
}
|
|
public static int getSeconds(int secondsOfDay)
|
|
{
|
|
return (secondsOfDay % 60);
|
|
}
|
|
|
|
private int secondsOfDay;
|
|
|
|
public TimeOfDay()
|
|
{
|
|
secondsOfDay = 0;
|
|
}
|
|
public TimeOfDay(int sod)
|
|
{
|
|
secondsOfDay = sod;
|
|
}
|
|
public TimeOfDay(int hour,int minute,int second)
|
|
{
|
|
initialize(hour, minute, second);
|
|
}
|
|
|
|
private void initialize(int hour,int minute,int second)
|
|
{
|
|
secondsOfDay = (hour * 3600) + (minute * 60) + second;
|
|
}
|
|
|
|
public int getSeondsOfDay()
|
|
{
|
|
return secondsOfDay;
|
|
}
|
|
public void setSecondsOfDay(int secondsOfDay)
|
|
{
|
|
this.secondsOfDay = secondsOfDay;
|
|
}
|
|
|
|
public int getHours()
|
|
{
|
|
return getHours(secondsOfDay);
|
|
}
|
|
|
|
public int getMinutes()
|
|
{
|
|
return getMinutes(secondsOfDay);
|
|
}
|
|
|
|
public int getSeonds()
|
|
{
|
|
return getSeconds(secondsOfDay);
|
|
}
|
|
|
|
public void setHours(int hours)
|
|
{
|
|
initialize(hours, getMinutes(), getSeonds());
|
|
}
|
|
|
|
public void setMinutes(int minutes)
|
|
{
|
|
initialize(getHours(), minutes, getSeonds());
|
|
}
|
|
|
|
public void setSeconds(int seconds)
|
|
{
|
|
initialize(getHours(), getMinutes(), seconds);
|
|
}
|
|
|
|
|
|
|
|
}
|