no.ntnu.vegare.visualizer.client.utils
Class TimeUtils

java.lang.Object
  extended by no.ntnu.vegare.visualizer.client.utils.TimeUtils

public class TimeUtils
extends java.lang.Object

Provides access to commonly used date and time utility functions. All methods are static and universally available, and should not depend on any state.

Author:
vegare

Field Summary
static int DAY
           
static int HOUR
           
static int MINUTE
           
static int WEEK
           
static int YEAR
           
 
Constructor Summary
TimeUtils()
           
 
Method Summary
static int dateToTimestamp(java.util.Date value)
          Convert a Date object to a UNIX timestamp
static java.util.Date getCurrentDate()
           
static java.util.Date getCurrentPlus(int seconds)
          Returns the current time, plus/minus a given number of seconds.
static int getCurrentTime()
           
static int round(int timestamp, int closest)
          Round a UNIX timestamp to the closest interval.
static java.lang.String timestampToDate(java.lang.Integer value)
          Convert a UNIX timestamp to a Date object
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINUTE

public static final int MINUTE
See Also:
Constant Field Values

HOUR

public static final int HOUR
See Also:
Constant Field Values

DAY

public static final int DAY
See Also:
Constant Field Values

WEEK

public static final int WEEK
See Also:
Constant Field Values

YEAR

public static final int YEAR
See Also:
Constant Field Values
Constructor Detail

TimeUtils

public TimeUtils()
Method Detail

getCurrentTime

public static int getCurrentTime()
Returns:
Current UNIX timestamp (seconds since epoch)

getCurrentDate

public static java.util.Date getCurrentDate()
Returns:
Current datetime as a Date instance

getCurrentPlus

public static java.util.Date getCurrentPlus(int seconds)
Returns the current time, plus/minus a given number of seconds. Parameter can be negative, causing a backward movement.

Parameters:
seconds - Difference from current time in seconds
Returns:
Date instance for the specified time

dateToTimestamp

public static int dateToTimestamp(java.util.Date value)
Convert a Date object to a UNIX timestamp

Parameters:
value - Date object
Returns:
UNIX timestamp

timestampToDate

public static java.lang.String timestampToDate(java.lang.Integer value)
Convert a UNIX timestamp to a Date object

Parameters:
value - UNIX timestamp
Returns:
Date object

round

public static int round(int timestamp,
                        int closest)
Round a UNIX timestamp to the closest interval. Can e.g. be used to round to closest day or year.

Parameters:
timestamp - UNIX timestamp
closest - Size of interval
Returns:
New UNIX timestamp