com.atlassian.core.util
Class DateUtils

java.lang.Object
  extended by com.atlassian.core.util.DateUtils

public class DateUtils
extends java.lang.Object


Nested Class Summary
static class DateUtils.DateRange
           
static class DateUtils.Duration
           
 
Field Summary
static java.lang.String AM
           
static long DAY_MILLIS
           
static long HOUR_MILLIS
           
static java.text.DateFormat ISO8601DateFormat
          Date Format to be used for internal logging operations
static long MINUTE_MILLIS
           
static long MONTH_MILLIS
           
static java.lang.String PM
           
static long SECOND_MILLIS
           
static long YEAR_MILLIS
           
 
Constructor Summary
DateUtils(java.util.ResourceBundle resourceBundle)
           
 
Method Summary
static java.lang.String dateDifference(long dateA, long dateB, long resolution, java.util.ResourceBundle resourceBundle)
          Resolution is the degree of difference.
 java.lang.String dateDifferenceBean(long dateA, long dateB, long resolution, java.util.ResourceBundle resourceBundle)
           
static boolean equalTimestamps(java.sql.Timestamp t1, java.sql.Timestamp t2)
          compares if these two timestamps are within 10 milliseconds of each other (precision error)
static java.lang.String formatDateISO8601(java.util.Date ts)
           
 java.lang.String formatDurationPretty(long l)
          This is used by the Velocity templates as a bean
 java.lang.String formatDurationPretty(java.lang.String seconds)
          This is used by the Velocity templates as a bean
 java.lang.String formatDurationString(long l)
          This is used by the WebWork tags as a bean
static int get24HourTime(java.lang.String meridianIndicator, int hours)
           
static java.util.Calendar getCalendarDay(int year, int month, int day)
           
static java.util.Date getDateDay(int year, int month, int day)
           
static long getDuration(java.lang.String durationStr)
          Given a duration string, get the number of seconds it represents (all case insensitive): w = weeks d = days h = hours m = minutes If no category is specified, assume minutes.
Each field must be separated by a space, and they can come in any order.
static long getDuration(java.lang.String durationStr, DateUtils.Duration defaultUnit)
          Given a duration string, get the number of seconds it represents (all case insensitive): w = weeks d = days h = hours m = minutes ie 2h = 7200, 60m = 3600, 3d = 259200, 30m
static long getDuration(java.lang.String durationStr, int hoursPerDay, int daysPerWeek)
          This function retrieves a duration in seconds that depends on number of hours in a day and days in a week.
static long getDuration(java.lang.String durationStr, int hoursPerDay, int daysPerWeek, DateUtils.Duration defaultUnit)
          This function retrieves a duration in seconds that depends on number of hours in a day and days in a week
static java.lang.String getDurationPretty(long numSecs, int hoursPerDay, int daysPerWeek, java.util.ResourceBundle resourceBundle)
          Converts a number of seconds into a pretty formatted data string.
static java.lang.String getDurationPretty(long numSecs, java.util.ResourceBundle resourceBundle)
          Converts a number of seconds into a pretty formatted data string.
static java.lang.String getDurationPrettySecondsResolution(long numSecs, int hoursPerDay, int daysPerWeek, java.util.ResourceBundle resourceBundle)
          Converts a number of seconds into a pretty formatted data string.
static java.lang.String getDurationPrettySecondsResolution(long numSecs, java.util.ResourceBundle resourceBundle)
          Converts a number of seconds into a pretty formatted data string.
static java.lang.String getDurationString(long seconds)
          Get String representation of a duration

static java.lang.String getDurationString(long l, int hoursPerDay, int daysPerWeek)
           
static java.lang.String getDurationStringWithNegative(long seconds)
          Get String representation of a (possibly negative) duration.
static long getDurationWithNegative(java.lang.String durationStr)
          Get a duration string with the possibility of a negative.
static java.util.Date getSqlDateDay(int year, int month, int day)
           
static DateUtils.DateRange toDateRange(java.util.Calendar date, int period)
          Given a period, and a date that falls within that period, create a range of dates such that the period is contained exactly within [startDate <= {range} < endDate]
static java.util.Calendar toEndOfPeriod(java.util.Calendar calendar, int period)
          Change the date of a Calendar object so that it has the maximum resolution of "period" where period is one of the constants in CALENDAR_PERIODS above.
static java.util.Date tomorrow()
           
static java.util.Calendar toStartOfPeriod(java.util.Calendar calendar, int period)
          Change the date of a Calendar object so that it has the minimum resolution of "period" where period is one of the constants in CALENDAR_PERIODS above.
static boolean validDuration(java.lang.String s)
          Check whether a given duration string is valid
static java.util.Date yesterday()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECOND_MILLIS

public static final long SECOND_MILLIS

MINUTE_MILLIS

public static final long MINUTE_MILLIS

HOUR_MILLIS

public static final long HOUR_MILLIS

DAY_MILLIS

public static final long DAY_MILLIS

MONTH_MILLIS

public static final long MONTH_MILLIS

YEAR_MILLIS

public static final long YEAR_MILLIS

AM

public static final java.lang.String AM
See Also:
Constant Field Values

PM

public static final java.lang.String PM
See Also:
Constant Field Values

ISO8601DateFormat

public static final java.text.DateFormat ISO8601DateFormat
Date Format to be used for internal logging operations

Constructor Detail

DateUtils

public DateUtils(java.util.ResourceBundle resourceBundle)
Method Detail

equalTimestamps

public static boolean equalTimestamps(java.sql.Timestamp t1,
                                      java.sql.Timestamp t2)
compares if these two timestamps are within 10 milliseconds of each other (precision error)


dateDifferenceBean

public java.lang.String dateDifferenceBean(long dateA,
                                           long dateB,
                                           long resolution,
                                           java.util.ResourceBundle resourceBundle)

dateDifference

public static java.lang.String dateDifference(long dateA,
                                              long dateB,
                                              long resolution,
                                              java.util.ResourceBundle resourceBundle)
Resolution is the degree of difference.

0 = months 1 = days 2 = hours 3 = minutes 4 = seconds


formatDateISO8601

public static java.lang.String formatDateISO8601(java.util.Date ts)

validDuration

public static boolean validDuration(java.lang.String s)
Check whether a given duration string is valid

Parameters:
s - the duration string
Returns:
true if it a valid duration

getDuration

public static long getDuration(java.lang.String durationStr)
                        throws InvalidDurationException
Given a duration string, get the number of seconds it represents (all case insensitive): If no category is specified, assume minutes.
Each field must be separated by a space, and they can come in any order. Case is ignored.

ie 2h = 7200, 60m = 3600, 3d = 259200, 30m

Parameters:
durationStr - the duration string
Returns:
the duration in seconds
Throws:
InvalidDurationException - if the duration is invalid

getDuration

public static long getDuration(java.lang.String durationStr,
                               DateUtils.Duration defaultUnit)
                        throws InvalidDurationException
Given a duration string, get the number of seconds it represents (all case insensitive): ie 2h = 7200, 60m = 3600, 3d = 259200, 30m

Parameters:
durationStr - the duration string
defaultUnit - the unit used when another is not specified in the durationStr
Returns:
the duration in seconds
Throws:
InvalidDurationException - if the duration is invalid

getDuration

public static long getDuration(java.lang.String durationStr,
                               int hoursPerDay,
                               int daysPerWeek)
                        throws InvalidDurationException
This function retrieves a duration in seconds that depends on number of hours in a day and days in a week. The default unit is MINUTE (i.e. "2" == "2 minutes")

Parameters:
durationStr - to convert to a duration
hoursPerDay - Number of hourse i day
daysPerWeek - Days Per Week
Returns:
the duration in seconds
Throws:
InvalidDurationException - if its badly formatted duration

getDuration

public static long getDuration(java.lang.String durationStr,
                               int hoursPerDay,
                               int daysPerWeek,
                               DateUtils.Duration defaultUnit)
                        throws InvalidDurationException
This function retrieves a duration in seconds that depends on number of hours in a day and days in a week

Parameters:
durationStr - to convert to a duration
hoursPerDay - Number of hourse i day
daysPerWeek - Days Per Week
defaultUnit - the unit used when one is not specified on a measure in the durationStr
Returns:
the duration in seconds
Throws:
InvalidDurationException - if its badly formatted duration

getDurationWithNegative

public static long getDurationWithNegative(java.lang.String durationStr)
                                    throws InvalidDurationException
Get a duration string with the possibility of a negative.

A duration will be considered negative if the first non-space character is a - sign.

Parameters:
durationStr - the duration string
Returns:
the duration in seconds, which can be negative
Throws:
InvalidDurationException - if its a badly formatted duration

getDurationString

public static java.lang.String getDurationString(long seconds)
Get String representation of a duration

Parameters:
seconds - Number of seconds
Returns:
String representing duration, eg: "1h 30m"
See Also:
getDurationStringWithNegative(long)

getDurationStringWithNegative

public static java.lang.String getDurationStringWithNegative(long seconds)
Get String representation of a (possibly negative) duration.

Parameters:
seconds - Number of seconds
Returns:
String representing duration, eg: "-1h 30m"
See Also:
getDurationString(long)

getDurationString

public static java.lang.String getDurationString(long l,
                                                 int hoursPerDay,
                                                 int daysPerWeek)

getDurationPretty

public static java.lang.String getDurationPretty(long numSecs,
                                                 java.util.ResourceBundle resourceBundle)
Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds.

So for example 76 becomes '1 minute', while 42 becomes '42 seconds'

Parameters:
numSecs - the number of seconds in the duration
resourceBundle - a resouce bundle for i18n
Returns:
a string in readable pretty duration format, using minute resolution

getDurationPretty

public static java.lang.String getDurationPretty(long numSecs,
                                                 int hoursPerDay,
                                                 int daysPerWeek,
                                                 java.util.ResourceBundle resourceBundle)
Converts a number of seconds into a pretty formatted data string. The resolution is in minutes. So if the number of seconds is greater than a minute, it will only be shown down top minute resolution. If the number of seconds is less than a minute it will be shown in seconds.

So for example 76 becomes '1 minute', while 42 becomes '42 seconds'

Parameters:
numSecs - the number of seconds in the duration
hoursPerDay - the hours in a day
daysPerWeek - the number of days in a week
resourceBundle - a resouce bundle for i18n
Returns:
a string in readable pretty duration format, using minute resolution

getDurationPrettySecondsResolution

public static java.lang.String getDurationPrettySecondsResolution(long numSecs,
                                                                  java.util.ResourceBundle resourceBundle)
Converts a number of seconds into a pretty formatted data string. The resolution is in seconds.

So for example 76 becomes '1 minute, 16 seconds', while 42 becomes '42 seconds'

Parameters:
numSecs - the number of seconds in the duration
resourceBundle - a resouce bundle for i18n
Returns:
a string in readable pretty duration format, using second resolution

getDurationPrettySecondsResolution

public static java.lang.String getDurationPrettySecondsResolution(long numSecs,
                                                                  int hoursPerDay,
                                                                  int daysPerWeek,
                                                                  java.util.ResourceBundle resourceBundle)
Converts a number of seconds into a pretty formatted data string. The resolution is in seconds.

So for example 76 becomes '1 minute, 16 seconds', while 42 becomes '42 seconds'

Parameters:
numSecs - the number of seconds in the duration
hoursPerDay - the hours in a day
daysPerWeek - the number of days in a week
resourceBundle - a resouce bundle for i18n
Returns:
a string in readable pretty duration format, using second resolution

formatDurationPretty

public java.lang.String formatDurationPretty(long l)
This is used by the Velocity templates as a bean


formatDurationPretty

public java.lang.String formatDurationPretty(java.lang.String seconds)
This is used by the Velocity templates as a bean


formatDurationString

public java.lang.String formatDurationString(long l)
This is used by the WebWork tags as a bean


toEndOfPeriod

public static java.util.Calendar toEndOfPeriod(java.util.Calendar calendar,
                                               int period)
Change the date of a Calendar object so that it has the maximum resolution of "period" where period is one of the constants in CALENDAR_PERIODS above.

e.g. to obtain the maximum value for a month, call toEndOfPeriod(calendarObject, Calendar.MONTH)

Parameters:
calendar - The Calendar to change
period - The period to "maximise"
Returns:
A modified Calendar object

toStartOfPeriod

public static java.util.Calendar toStartOfPeriod(java.util.Calendar calendar,
                                                 int period)
Change the date of a Calendar object so that it has the minimum resolution of "period" where period is one of the constants in CALENDAR_PERIODS above.


toDateRange

public static DateUtils.DateRange toDateRange(java.util.Calendar date,
                                              int period)
Given a period, and a date that falls within that period, create a range of dates such that the period is contained exactly within [startDate <= {range} < endDate]

Parameters:
date - a calendar object of a date falling in that range
period - something in CALENDAR_PERIODS

getCalendarDay

public static java.util.Calendar getCalendarDay(int year,
                                                int month,
                                                int day)

getDateDay

public static java.util.Date getDateDay(int year,
                                        int month,
                                        int day)

getSqlDateDay

public static java.util.Date getSqlDateDay(int year,
                                           int month,
                                           int day)

get24HourTime

public static int get24HourTime(java.lang.String meridianIndicator,
                                int hours)

tomorrow

public static java.util.Date tomorrow()

yesterday

public static java.util.Date yesterday()


Copyright © 2009 Atlassian Pty Ltd. All Rights Reserved.