001package com.box.sdk;
002
003import java.util.Date;
004
005/**
006 * Class is used to be a range for two dates. Ususally paired with varying search filters.
007 */
008public class DateRange {
009    private Date from;
010    private Date to;
011
012    /**
013     * Used for specify a date range to filter to be used in search.
014     *
015     * @param from is the start date in a range.
016     * @param to   is the end date in a range.
017     */
018    public DateRange(Date from, Date to) {
019        this.from = from;
020        this.to = to;
021    }
022
023    /**
024     * Returns the from date which is the start date.
025     *
026     * @return Date this is start date.
027     */
028    public Date getFromDate() {
029        return this.from;
030    }
031
032    /**
033     * Set the from date which is equivalent to the start date.
034     *
035     * @param from date which is the starting point.
036     */
037    public void setFrom(Date from) {
038        this.from = from;
039    }
040
041    /**
042     * Returns the to date which is the end date.
043     *
044     * @return Date this is the end date.
045     */
046    public Date getToDate() {
047        return this.to;
048    }
049
050    /**
051     * Set the to date which is equivalent to the start date.
052     *
053     * @param to date which is the end point.
054     */
055    public void setTo(Date to) {
056        this.to = to;
057    }
058
059    /**
060     * Used to build out a string a http box api friendly range string.
061     *
062     * @return String that is uses as a rest parameter.
063     */
064    public String buildRangeString() {
065
066        String fromString = BoxDateFormat.format(this.from);
067        String toString = BoxDateFormat.format(this.to);
068
069
070        String rangeString = String.format("%s,%s", fromString, toString);
071        if (rangeString == ",") {
072            rangeString = null;
073        }
074        return rangeString;
075    }
076}