public String toString()

in velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ComparisonDateTool.java [810:888]


        public String toString()
        {
            long ms = milliseconds;

            // first check if there is a difference
            if (ms == 0)
            {
                String sameKey = (abbreviate) ? ABBR_SUFFIX : "";
                if (type == CURRENT_TYPE)
                {
                    sameKey = CURRENT_PREFIX + EQUAL_KEY + sameKey;
                }
                else if (type == RELATIVE_TYPE)
                {
                    sameKey = EQUAL_KEY + sameKey;
                }
                else
                {
                    sameKey = ZERO_KEY + sameKey;
                }
                return getText(sameKey, locale);
            }

            boolean isBefore = false;
            if (ms < 0)
            {
                isBefore = true;
                // convert() only works with positive values
                ms *= -1;
            }

            // get the base value
            String friendly = toString(type == EXACT_TYPE ? 0 : ms , depth);

            // if we only want the difference...
            if (type == DIFF_TYPE)
            {
                // add the sign (if negative)
                if (isBefore)
                {
                    friendly = "-" + friendly;
                }
                // then return without direction suffix
                return friendly;
            }

            // otherwise, get the appropriate direction key
            String directionKey = (isBefore) ? BEFORE_KEY : AFTER_KEY;
            if (type == CURRENT_TYPE)
            {
                directionKey = CURRENT_PREFIX + directionKey;

                if (friendly != null && friendly.startsWith("1"))
                {
                    // check for the corner case of "1 day ago" or "1 day away"
                    // and convert those to "yesterday" or "tomorrow"
                    String dayKey = (abbreviate) ? DAY_KEY + ABBR_SUFFIX : DAY_KEY;
                    if (friendly.equals("1 " + getText(dayKey, locale)))
                    {
                        // add .day
                        directionKey += ONE_DAY_SUFFIX;
                        // and return only the value of this key
                        // (which means we throw away the friendly value
                        //  and don't bother abbreviating things)
                        return getText(directionKey, locale);
                    }
                }
            }

            // in the default bundle, this doesn't change anything.
            // but in may in user-provided bundles
            if (abbreviate)
            {
                directionKey += ABBR_SUFFIX;
            }

            // then combine them
            return friendly +  " " + getText(directionKey, locale);
        }