public class TimeUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DAYS_PER_LEAP_YEAR
The number of days in a leap year.
|
static int |
DAYS_PER_YEAR
The number of days in a standard year.
|
static int |
MINUTES_PER_HOUR
The number of minutes in one hour.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
isLeapYear(int year)
Returns true if year is a leap year and false otherwise.
|
static int |
mostFrequent(List<Integer> years)
Given a sorted list of years, returns the year that occurs
most frequently in the list.
|
static int |
toHoursRoundedUp(int minutes)
Converts a number of minutes to hours rounding up to the nearest number
of hours.
|
static int |
totalDays(int startYear,
int endYear)
Computes the total number of days in the period of time from Jan 1 of the
start year to Dec 31 of the end year accounting for the presence of leap
years.
|
public static final int MINUTES_PER_HOUR
public static final int DAYS_PER_YEAR
public static final int DAYS_PER_LEAP_YEAR
public static int toHoursRoundedUp(int minutes)
toHoursRoundedUp(0) returns 0 toHoursRoundedUp(59) returns 1 toHoursRoundedUp(60) returns 1 toHoursRoundedUp(61) returns 2 toHoursRoundedUp(150) returns 3
This is how most service-based businesses calculate how many hours of labor are charged to the customer (i.e., a job that takes 15 minutes will cost the customer 1 hour of labor charges).
minutes
- a number of minutespublic static boolean isLeapYear(int year)
A year is always a leap year if it is evenly divisible by 400; for all other years, a year is a leap year if it is evenly divisible by 4 and not evenly divisible by 100. For example:
isLeapYear(2000) returns true (2000 is divisible by 400) isLeapYear(1900) returns false (1900 is divisible by 4 and 100) isLeapYear(2004) returns true (2004 is divisible by 4 but not 100) isLeapYear(2005) returns false (2005 is not divisible by 4)
year
- a yearIllegalArgumentException
- if year is less than zeropublic static int totalDays(int startYear, int endYear)
totalDays(2000, 2000) returns 366 (Jan 1, 2000 to Dec 31, 2000) totalDays(2001, 2002) returns 365 + 365 (Jan 1, 2001 to Dec 31, 2002) totalDays(2001, 2004) returns 365 + 365 + 365 + 366 (Jan 1, 2001 to Dec 31, 2004)
startYear
- the start yearendYear
- the end yearpublic static int mostFrequent(List<Integer> years)
years
- a sorted list of years