contract BonusableCrowdsale is Consts, Crowdsale {
    /**
     * @dev Override to extend the way in which ether is converted to tokens.
     * @param _weiAmount Value in wei to be converted into tokens
     * @return Number of tokens that can be purchased with the specified _weiAmount
     */
    function _getTokenAmount(uint256 _weiAmount)
        internal view returns (uint256)
    {
        uint256 bonusRate = getBonusRate(_weiAmount);
        return _weiAmount.mul(bonusRate).div(1 ether);
    }

    function getBonusRate(uint256 _weiAmount) internal view returns (uint256) {
        uint256 bonusRate = rate;

        
        // apply bonus for time & weiRaised
        uint[3] memory weiRaisedStartsBounds = [uint(0),uint(16666666666666666666667),uint(33333333333333333333333)];
        uint[3] memory weiRaisedEndsBounds = [uint(16666666666666666666667),uint(33333333333333333333333),uint(50000000000000000000000)];
        uint64[3] memory timeStartsBounds = [uint64(1550239740),uint64(1550934540),uint64(1551625740)];
        uint64[3] memory timeEndsBounds = [uint64(1550934540),uint64(1551625740),uint64(1552835335)];
        uint[3] memory weiRaisedAndTimeRates = [uint(500),uint(300),uint(100)];

        for (uint i = 0; i < 3; i++) {
            bool weiRaisedInBound = (weiRaisedStartsBounds[i] <= weiRaised) && (weiRaised < weiRaisedEndsBounds[i]);
            bool timeInBound = (timeStartsBounds[i] <= now) && (now < timeEndsBounds[i]);
            if (weiRaisedInBound && timeInBound) {
                bonusRate += bonusRate * weiRaisedAndTimeRates[i] / 1000;
            }
        }
        

        

        return bonusRate;
    }
}
function _getTokenAmount(uint256 _weiAmount)
        internal view returns (uint256)
    {
        uint256 bonusRate = getBonusRate(_weiAmount);
        return _weiAmount.mul(bonusRate).div(1 ether);
    }
/**
 * @dev Override to extend the way in which ether is converted to tokens.
 * @param _weiAmount Value in wei to be converted into tokens
 * @return Number of tokens that can be purchased with the specified _weiAmount
 */