Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.3
-
None
Description
These DateUtils-features can make it possible to calculate a date-part in any time-unit. For example: the number of minutes of this year, the number of seconds of today, etc.
I've started with some coding, and if there's enough interest we can make it more solid.
public static long getFragmentInSeconds(Date date, int fragment)
{ return getFragment(date, fragment, Calendar.SECOND); }public static long getFragmentInMinutes(Date date, int fragment)
{ return getFragment(date, fragment, Calendar.MINUTE); }public static long getFragmentInHours(Date date, int fragment)
{ return getFragment(date, fragment, Calendar.HOUR_OF_DAY); }public static long getFragmentInDays(Date date, int fragment)
{ return getFragment(date, fragment, Calendar.DAY_OF_YEAR); }public static long getFragmentInSeconds(Calendar calendar, int fragment)
{ return getFragment(calendar, fragment, Calendar.SECOND); }public static long getFragmentInMinutes(Calendar calendar, int fragment)
{ return getFragment(calendar, fragment, Calendar.MINUTE); }public static long getFragmentInHours(Calendar calendar, int fragment)
{ return getFragment(calendar, fragment, Calendar.HOUR_OF_DAY); }public static long getFragmentInDays(Calendar calendar, int fragment)
{ return getFragment(calendar, fragment, Calendar.DAY_OF_YEAR); }private static long getFragment(Date date, int fragment, int unit)
{ Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return getFragment(calendar, fragment, unit); } private static long getFragment(Calendar calendar, int fragment, int unit) {
long millisPerUnit = getMillisPerFragment(unit);
long result = 0;
switch (fragment)
return result;
}
private static long getMillisPerFragment(int fragment) {
long result = Long.MAX_VALUE;
switch (fragment)
return result;
}