Package adams.parser

Class BaseDateTimeMsecExpression

  • All Implemented Interfaces:
    Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, SizeOfHandler, GrammarSupplier, Serializable

    public class BaseDateTimeMsecExpression
    extends AbstractExpressionEvaluator<Date>
    implements GrammarSupplier
    Evaluates date/time (with msec) expressions.

    Format:
    (<date>|NOW|TODAY|TOMORROW|YESTERDAY|-INF|+INF|START|END) [expr (MILLISECOND|SECOND|MINUTE|HOUR|DAY|BUSINESSDAY|WEEK|MONTH|YEAR)]*

    expr ::= ( expr )
    | - expr
    | + expr
    | expr + expr
    | expr - expr
    | expr * expr
    | expr / expr
    | expr % expr
    | expr ^ expr
    | abs ( expr )
    | sqrt ( expr )
    | log ( expr )
    | exp ( expr )
    | rint ( expr )
    | floor ( expr )
    | pow[er] ( expr , expr )
    | ceil ( expr )
    | NUMBER

    Note:
    TODAY/TOMORROW/YESTERDAY generate a date at the start of the day.


    Examples:
    1999-12-31 01:02:03.123
    1999-12-31 01:02:03.123 +1 MINUTE
    NOW
    +INF
    NOW +1 YEAR
    NOW +14 DAY
    NOW +(2*3) DAY

    Amounts can be chained as well:
    NOW -1 MONTH +1 DAY

    START and END can only be set programmatically; by default they are equal to -INF and +INF.

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -env <java.lang.String> (property: environment)
        The class to use for determining the environment.
        default: adams.env.Environment
     
    -expression <java.lang.String> (property: expression)
        The boolean expression to evaluate (must evaluate to a boolean).
        default: NOW
     
    -business-days <MONDAY_TO_FRIDAY|MONDAY_TO_SATURDAY|SATURDAY_TO_THURSDAY|SUNDAY_TO_THURSDAY|SUNDAY_TO_FRIDAY> (property: businessDays)
        How to interpret business days.
        default: MONDAY_TO_FRIDAY
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Detail

      • m_BusinessDays

        protected BusinessDays m_BusinessDays
        how to interpret business days.
    • Constructor Detail

      • BaseDateTimeMsecExpression

        public BaseDateTimeMsecExpression()
    • Method Detail

      • getGrammar

        public String getGrammar()
        Returns a string representation of the grammar.
        Specified by:
        getGrammar in interface GrammarSupplier
        Returns:
        the grammar, null if not available
      • expressionTipText

        public String expressionTipText()
        Returns the tip text for this property.
        Specified by:
        expressionTipText in class AbstractExpressionEvaluator<Date>
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setBusinessDays

        public void setBusinessDays​(BusinessDays value)
        Sets what business days to use.
        Parameters:
        value - the type
      • getBusinessDays

        public BusinessDays getBusinessDays()
        Returns what business days to use.
        Returns:
        the type
      • businessDaysTipText

        public String businessDaysTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • initializeSymbol

        protected Object initializeSymbol​(String name,
                                          String value)
        Initializes the symbol.
        Parameters:
        name - the name of the symbol
        value - the string representation of the symbol
        Returns:
        the object representation of the symbol
      • evaluate

        public Date evaluate​(Date start,
                             Date end)
                      throws Exception
        Performs the evaluation.
        Parameters:
        start - the start datetime, can be null
        end - the end datetime, can be null
        Returns:
        the evaluation, or null in case of error
        Throws:
        Exception - if evaluation fails
      • evaluate

        public static Date evaluate​(String expr,
                                    Date start,
                                    Date end,
                                    BusinessDays bdays)
                             throws Exception
        Parses and evaluates the given expression. Returns the result of the boolean expression, based on the given values of the symbols.
        Parameters:
        expr - the expression to evaluate
        start - the start datetime, can be null
        end - the end datetime, can be null
        bdays - how to interpret business days
        Returns:
        the evaluated result
        Throws:
        Exception - if something goes wrong
        See Also:
        BaseDateTimeMsec.START, BaseDateTimeMsec.END
      • main

        public static void main​(String[] args)
        Runs the evaluator from command-line.
        Parameters:
        args - the command-line options, use "-help" to list them