contract TimedCrowdsale is Crowdsale {
    using SafeMath for uint256;

    // uint256 private _duration_crowndsale;

    uint256 private _openingTime;
    uint256 private _closingTime;
    uint256 public _finalizedTime;
    bool public _isStopped = false;
    bool public isDepositedTokenSale = false;

    function start() public onlyOwner {
        require(!isOpen(), "TimedCrowdsale: opened");
        require(isDepositedTokenSale, "TimedCrowdsale: no token sale");
        _openingTime = block.timestamp;
        // _closingTime = _openingTime.add(_duration_crowndsale);
    }

    function stop() public onlyOwner {
        require(isOpen(), "TimedCrowdsale: closed");
        // _closingTime = block.timestamp;
        _isStopped = true;
    }

    // constructor(uint256 duration_crowndsale) internal {
    //     require(duration_crowndsale > 0);
    //     _duration_crowndsale = duration_crowndsale;
    // }

    /**
     * @dev Reverts if not in crowdsale time range.
     */
    modifier onlyWhileOpen {
        require(isOpen() && !_isStopped, "TimedCrowdsale: not open");
        _;
    }

    /**
     * @return the crowdsale opening time.
     */
    function openingTime() public view returns (uint256) {
        return _openingTime;
    }

    /**
     * @return the crowdsale closing time.
     */
    // function closingTime() public view returns (uint256) {
    //     return _closingTime;
    // }

    /**
     * @return true if the crowdsale is open, false otherwise.
     */
    function isOpen() public view returns (bool) {
        // solhint-disable-next-line not-rely-on-time
        return _openingTime > 0 && block.timestamp >= _openingTime;
    }

    /**
     * @dev Checks whether the period in which the crowdsale is open has already elapsed.
     * @return Whether crowdsale period has elapsed
     */
    function hasClosed() public view returns (bool) {
        // solhint-disable-next-line not-rely-on-time
        return _openingTime > 0 && _isStopped;
    }

    function withdrawable() public view returns (bool) {
        // solhint-disable-next-line not-rely-on-time
        return
            _finalizedTime > 0 &&
            block.timestamp > _finalizedTime.add(30 minutes);
    }

    /**
     * @dev Extend parent behavior requiring to be within contributing period.
     * @param beneficiary Token purchaser
     * @param weiAmount Amount of wei contributed
     */
    function _preValidatePurchase(address beneficiary, uint256 weiAmount)
        internal
        view
        onlyWhileOpen
    {
        super._preValidatePurchase(beneficiary, weiAmount);
    }
}
/**
 * @title TimedCrowdsale
 * @dev Crowdsale accepting contributions only within a time frame.
 */
function openingTime() public view returns (uint256) {
    return _openingTime;
}

/**
 * @return the crowdsale opening time.
 */