contract SafeMath {

    uint constant DAY_IN_SECONDS = 86400;

    function mul(uint256 a, uint256 b) constant internal returns (uint256) {
        uint256 c = a * b;
        assert(a == 0 || c / a == b);
        return c;
    }

    function div(uint256 a, uint256 b) constant internal returns (uint256) {
        assert(b != 0); // Solidity automatically throws when dividing by 0
        uint256 c = a / b;
        assert(a == b * c + a % b); // There is no case in which this doesn't hold
        return c;
    }

    function sub(uint256 a, uint256 b) constant internal returns (uint256) {
        assert(b <= a);
        return a - b;
    }

    function add(uint256 a, uint256 b) constant internal returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
    }

    function mulByFraction(uint256 number, uint256 numerator, uint256 denominator) internal returns (uint256) {
        return div(mul(number, numerator), denominator);
    }

    // ICO date bonus calculation
    function dateBonus(uint startIco) internal returns (uint256) {

        // day from ICO start
        uint daysFromStart = (now - startIco) / DAY_IN_SECONDS + 1;

        if(daysFromStart >= 1  && daysFromStart <= 14) return 20; // +20% tokens
        if(daysFromStart >= 15 && daysFromStart <= 28) return 15; // +20% tokens
        if(daysFromStart >= 29 && daysFromStart <= 42) return 10; // +10% tokens
        if(daysFromStart >= 43)                        return 5;  // +5% tokens

        // no discount
        return 0;
    }

}
/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
function dateBonus(uint startIco) internal returns (uint256) {

    // day from ICO start
    uint daysFromStart = (now - startIco) / DAY_IN_SECONDS + 1;

    if(daysFromStart >= 1  && daysFromStart <= 14) return 20; // +20% tokens
    if(daysFromStart >= 15 && daysFromStart <= 28) return 15; // +20% tokens
    if(daysFromStart >= 29 && daysFromStart <= 42) return 10; // +10% tokens
    if(daysFromStart >= 43)                        return 5;  // +5% tokens

    // no discount
    return 0;
}

// ICO date bonus calculation