| | |
| | |
|
| | | /**
|
| | | * Utility class of time functions.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class TimeUtils {
|
| | | public static final long MIN = 1000 * 60L;
|
| | |
| | | public static final long ONEDAY = ONEHOUR * 24L;
|
| | |
|
| | | public static final long ONEYEAR = ONEDAY * 365L;
|
| | | |
| | |
|
| | | private final ResourceBundle translation;
|
| | | |
| | |
|
| | | private final TimeZone timezone;
|
| | | |
| | |
|
| | | public TimeUtils() {
|
| | | this(null, null);
|
| | | }
|
| | | |
| | |
|
| | | public TimeUtils(ResourceBundle translation, TimeZone timezone) {
|
| | | this.translation = translation;
|
| | | this.timezone = timezone;
|
| | |
| | |
|
| | | /**
|
| | | * Returns true if date is today.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @return true if date is today
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * Returns true if date is yesterday.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @return true if date is yesterday
|
| | | */
|
| | |
| | | /**
|
| | | * Returns the string representation of the duration as days, months and/or
|
| | | * years.
|
| | | * |
| | | *
|
| | | * @param days
|
| | | * @return duration as string in days, months, and/or years
|
| | | */
|
| | |
| | | /**
|
| | | * Returns the number of minutes ago between the start time and the end
|
| | | * time.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @param endTime
|
| | | * @param roundup
|
| | |
| | |
|
| | | /**
|
| | | * Return the difference in minutes between now and the date.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @param roundup
|
| | | * @return minutes ago
|
| | |
| | |
|
| | | /**
|
| | | * Return the difference in hours between now and the date.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @param roundup
|
| | | * @return hours ago
|
| | |
| | |
|
| | | /**
|
| | | * Return the difference in days between now and the date.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @return days ago
|
| | | */
|
| | |
| | | /**
|
| | | * Returns the string representation of the duration between now and the
|
| | | * date.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @return duration as a string
|
| | | */
|
| | |
| | |
|
| | | /**
|
| | | * Returns the CSS class for the date based on its age from Now.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @return the css class
|
| | | */
|
| | |
| | | /**
|
| | | * Returns the string representation of the duration OR the css class for
|
| | | * the duration.
|
| | | * |
| | | *
|
| | | * @param date
|
| | | * @param css
|
| | | * @return the string representation of the duration OR the css class
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | public String inFuture(Date date) {
|
| | | long diff = date.getTime() - System.currentTimeMillis();
|
| | | if (diff > ONEDAY) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | private String translate(String key, String defaultValue) {
|
| | | String value = defaultValue;
|
| | | if (translation != null && translation.containsKey(key)) {
|
| | |
| | | }
|
| | | return value;
|
| | | }
|
| | | |
| | |
|
| | | private String translate(int val, String key, String defaultPattern) {
|
| | | String pattern = defaultPattern;
|
| | | if (translation != null && translation.containsKey(key)) {
|
| | |
| | |
|
| | | /**
|
| | | * Convert a frequency string into minutes.
|
| | | * |
| | | *
|
| | | * @param frequency
|
| | | * @return minutes
|
| | | */
|