Class AutomationDateTool

java.lang.Object
org.apache.velocity.tools.generic.SafeConfig
org.apache.velocity.tools.generic.LocaleConfig
org.apache.velocity.tools.generic.FormatConfig
org.apache.velocity.tools.generic.DateTool
com.logicaldoc.core.automation.AutomationDateTool
All Implemented Interfaces:
Serializable

public class AutomationDateTool extends org.apache.velocity.tools.generic.DateTool
Utility class to handle dates from inside the Automation
Since:
7.3
Author:
Marco Meschieri - LogicalDOC
See Also:
  • Field Summary

    Fields inherited from class org.apache.velocity.tools.generic.DateTool

    TIMEZONE_KEY

    Fields inherited from class org.apache.velocity.tools.generic.FormatConfig

    DEFAULT_FORMAT, FORMAT_KEY

    Fields inherited from class org.apache.velocity.tools.generic.LocaleConfig

    DEFAULT_LOCALE

    Fields inherited from class org.apache.velocity.tools.generic.SafeConfig

    LOCK_CONFIG_KEY, LOGGER_NAME_KEY, SAFE_MODE_KEY, USE_CLASS_LOGGER_KEY
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    AutomationDateTool(String dateFormat, String dateFormatLong, String dateFormatShort)
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addDays(Date src, int amount)
    Adds a given amount of days to a date(you can add negative values to go back in time)
    addMilliseconds(Date src, int amount)
    Adds a given amount of milliseconds to a date(you can add negative values to go back in time)
    addMinutes(Date src, int amount)
    Adds a given amount of minutes to a date(you can add negative values to go back in time)
    addMonths(Date src, int amount)
    Adds a given amount of months to a date(you can add negative values to go back in time)
    addSeconds(Date src, int amount)
    Adds a given amount of seconds to a date(you can add negative values to go back in time)
    addYears(Date src, int amount)
    Adds a given amount of years to a date(you can add negative values to go back in time)
    Gets the current time
    format(Date date, boolean time)
    Formats a date
    format(Date date, String format)
    Formats a date using a specific format
    format(Date date, String timeZone, boolean time)
    Formats a date
    format(Date date, String format, String timeZone)
    Formats a date using a specific format
    Formats a date using the normal format that also includes the time
    formatDate(Date date, String timeZone)
    Formats a date using the normal format that also includes the time
    Formats a date using the long format that includes the time and milliseconds
    formatDateLong(Date date, String timeZone)
    Formats a date using the long format that includes the time and milliseconds
    Formats a date using the short format that just includes the date
    formatDateShort(Date date, String timeZone)
    Formats a date using the short format that just includes the date
    Formats a date using the ISO format: yyyy-MM-dd'T'HH:mm:ss
    Formats a date using the SQL format: yyyy-MM-dd
     
    Retrieves the default date format with time specification adn milliseconds
    Retrieves the default date format without time specification
     
    parse(String date, String format)
    Parses a string and to retrieve a date
    void
    setDateFormat(String dateFormat)
     
    void
    setDateFormatLong(String dateFormatLong)
    Sets the default long format(date with time)
    void
    setDateFormatShort(String dateFormatShort)
    Sets the default short format(date without time)
    void
    setTimeZone(String timeZone)
     
    long
    toDays(long ms)
    Calculates how many days are contained in a given amount of milliseconds
    long
    toHours(long ms)
    Calculates how many hours are contained in a given amount of milliseconds
    long
    toMinutes(long ms)
    Calculates how many minutes are contained in a given amount of milliseconds
    long
    toMonths(long ms)
    Calculates how many months are contained in a given amount of milliseconds
    long
    toSeconds(long ms)
    Calculates how many seconds are contained in a given amount of milliseconds
    long
    toWeeks(long ms)
    Calculates how many weeks are contained in a given amount of milliseconds
    long
    toYears(long ms)
    Calculates how many years are contained in a given amount of milliseconds

    Methods inherited from class org.apache.velocity.tools.generic.DateTool

    format, format, format, format, format, format, format, get, get, getCalendar, getDate, getDateFormat, getDateFormat, getDay, getDay, getMonth, getMonth, getSystemCalendar, getSystemDate, getSystemTime, getValue, getValue, getValue, getYear, getYear, toCalendar, toCalendar, toCalendar, toCalendar, toCalendar, toDate, toDate, toDate, toDate, toDate, toDate, toLocalizedPattern, toString

    Methods inherited from class org.apache.velocity.tools.generic.FormatConfig

    getFormat

    Methods inherited from class org.apache.velocity.tools.generic.LocaleConfig

    getLocale, toLocale

    Methods inherited from class org.apache.velocity.tools.generic.SafeConfig

    configure, isConfigLocked, isSafeMode

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AutomationDateTool

      public AutomationDateTool(Locale locale)
    • AutomationDateTool

      public AutomationDateTool(String dateFormat, String dateFormatLong, String dateFormatShort)
    • AutomationDateTool

      public AutomationDateTool()
  • Method Details

    • format

      public String format(Date date, String timeZone, boolean time)
      Formats a date
      Parameters:
      date - the date to format
      timeZone - the time zone
      time - if the output must contain the time also
      Returns:
      the formatted string
    • format

      public String format(Date date, boolean time)
      Formats a date
      Parameters:
      date - the date to format
      time - if the output must contain the time also
      Returns:
      the formatted string
    • formatDate

      public String formatDate(Date date, String timeZone)
      Formats a date using the normal format that also includes the time
      Parameters:
      date - the date to format
      timeZone - the time zone
      Returns:
      the formatted string
    • formatDate

      public String formatDate(Date date)
      Formats a date using the normal format that also includes the time
      Parameters:
      date - the date to format
      Returns:
      the formatted string
    • formatDateShort

      public String formatDateShort(Date date, String timeZone)
      Formats a date using the short format that just includes the date
      Parameters:
      date - the date to format
      timeZone - the time zone
      Returns:
      the formatted string
    • formatDateShort

      public String formatDateShort(Date date)
      Formats a date using the short format that just includes the date
      Parameters:
      date - the date to format
      Returns:
      the formatted string
    • formatDateLong

      public String formatDateLong(Date date, String timeZone)
      Formats a date using the long format that includes the time and milliseconds
      Parameters:
      date - the date to format
      timeZone - the time zone
      Returns:
      the formatted string
    • formatDateLong

      public String formatDateLong(Date date)
      Formats a date using the long format that includes the time and milliseconds
      Parameters:
      date - the date to format
      Returns:
      the formatted string
    • formatISO

      public String formatISO(Date date)
      Formats a date using the ISO format: yyyy-MM-dd'T'HH:mm:ss
      Parameters:
      date - the date to format
      Returns:
      the formatted string
    • formatSQL

      public String formatSQL(Date date)
      Formats a date using the SQL format: yyyy-MM-dd
      Parameters:
      date - the date to format
      Returns:
      the formatted string
    • format

      public String format(Date date, String format, String timeZone)
      Formats a date using a specific format
      Parameters:
      date - the date to format
      format - the format to use eg: dd/MM/yyyy
      timeZone - the time zone
      Returns:
      the formatted string
      See Also:
    • format

      public String format(Date date, String format)
      Formats a date using a specific format
      Parameters:
      date - the date to format
      format - the format to use eg: dd/MM/yyyy
      Returns:
      the formatted string
      See Also:
    • parse

      public Date parse(String date, String format)
      Parses a string and to retrieve a date
      Parameters:
      date - string to parse
      format - the format to use
      Returns:
      the parsed date
      See Also:
    • getDateFormatShort

      public String getDateFormatShort()
      Retrieves the default date format without time specification
      Returns:
      the default date short format
    • setDateFormatShort

      public void setDateFormatShort(String dateFormatShort)
      Sets the default short format(date without time)
      Parameters:
      dateFormatShort - the short format
    • getDateFormatLong

      public String getDateFormatLong()
      Retrieves the default date format with time specification adn milliseconds
      Returns:
      the default date long format
    • setDateFormatLong

      public void setDateFormatLong(String dateFormatLong)
      Sets the default long format(date with time)
      Parameters:
      dateFormatLong - the long format
    • currentTime

      public Date currentTime()
      Gets the current time
      Returns:
      the current time
    • addYears

      public Date addYears(Date src, int amount)
      Adds a given amount of years to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of years
      Returns:
      the new date
    • addMonths

      public Date addMonths(Date src, int amount)
      Adds a given amount of months to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of months
      Returns:
      the new date
    • addDays

      public Date addDays(Date src, int amount)
      Adds a given amount of days to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of days
      Returns:
      the new date
    • addMinutes

      public Date addMinutes(Date src, int amount)
      Adds a given amount of minutes to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of minutes
      Returns:
      the new date
    • addSeconds

      public Date addSeconds(Date src, int amount)
      Adds a given amount of seconds to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of seconds
      Returns:
      the new date
    • addMilliseconds

      public Date addMilliseconds(Date src, int amount)
      Adds a given amount of milliseconds to a date(you can add negative values to go back in time)
      Parameters:
      src - the date to use
      amount - number of milliseconds
      Returns:
      the new date
    • toDays

      public long toDays(long ms)
      Calculates how many days are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of days
    • toHours

      public long toHours(long ms)
      Calculates how many hours are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of hours
    • toMinutes

      public long toMinutes(long ms)
      Calculates how many minutes are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of minutes
    • toMonths

      public long toMonths(long ms)
      Calculates how many months are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of months
    • toSeconds

      public long toSeconds(long ms)
      Calculates how many seconds are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of seconds
    • toWeeks

      public long toWeeks(long ms)
      Calculates how many weeks are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of weeks
    • toYears

      public long toYears(long ms)
      Calculates how many years are contained in a given amount of milliseconds
      Parameters:
      ms - the milliseconds
      Returns:
      number of years
    • getDateFormat

      public String getDateFormat()
    • setDateFormat

      public void setDateFormat(String dateFormat)
    • getTimeZone

      public TimeZone getTimeZone()
      Overrides:
      getTimeZone in class org.apache.velocity.tools.generic.DateTool
    • setTimeZone

      public void setTimeZone(String timeZone)