net.opentsdb.utils
public class DateTime extends Object
| Modifier and Type | Field and Description | 
|---|---|
static HashMap<String,TimeZone> | 
timezones
Immutable cache mapping a timezone name to its object. 
 | 
| Constructor and Description | 
|---|
DateTime()  | 
| Modifier and Type | Method and Description | 
|---|---|
static boolean | 
isRelativeDate(String value)
Returns whether or not a date is specified in a relative fashion. 
 | 
static long | 
parseDateTimeString(String datetime,
                   String tz)
Attempts to parse a timestamp from a given string
 Formats accepted are:
 
 Relative:  
5m-ago, 1h-ago, etc. | 
static long | 
parseDuration(String duration)
Parses a human-readable duration (e.g, "10m", "3h", "14d") into seconds. 
 | 
static void | 
setDefaultTimezone(String tzname)
Sets the default timezone for this running OpenTSDB instance 
 | 
static void | 
setTimeZone(SimpleDateFormat fmt,
           String tzname)
Applies the given timezone to the given date format. 
 | 
public static final HashMap<String,TimeZone> timezones
public static final long parseDateTimeString(String datetime, String tz)
5m-ago, 1h-ago, etc. See 
 parseDuration(java.lang.String)datetime - The string to parse a value forNullPointerException - if the timestamp is nullIllegalArgumentException - if the request was malformedpublic static final long parseDuration(String duration)
Formats supported:
ms: millisecondss: secondsm: minutesh: hoursd: daysw: weeksn: month (30 days)y: years (365 days)duration - The human-readable duration to parse.IllegalArgumentException - if the interval was malformed.public static boolean isRelativeDate(String value)
 A date is specified in a relative fashion if it ends in "-ago",
 e.g. 1d-ago is the same as 24h-ago.
value - The value to parsetrue if the parameter is passed and is a relative date.
 Note the method doesn't attempt to validate the relative date.  So this
 function can return true on something that looks like a relative date,
 but is actually invalid once we really try to parse it.NullPointerException - if the value is nullpublic static void setTimeZone(SimpleDateFormat fmt, String tzname)
fmt - Date format to apply the timezone to.tzname - Name of the timezone, or null in which case this
 function is a no-op.IllegalArgumentException - if tzname isn't a valid timezone name.NullPointerException - if the format is nullpublic static void setDefaultTimezone(String tzname)
WARNING If OpenTSDB is used with a Security Manager, setting the default timezone only works for the running thread. Otherwise it will work for the entire application.
tzname - Name of the timezone to useIllegalArgumentException - if tzname isn't a valid timezone name