contract NmxCrowdsale is AllowanceCrowdsale, IncreasingPriceCrowdsale {

  // solium-disable-next-line max-len
  event CrowdsaleCreated(address owner, uint256 openingTime, uint256 closingTime, uint256 rate);

  /**
   * @param _openingTime  time in Unix epoch - opening the crowdsale
   * @param _closingTime  time in Unix epoch - closing the crowdsale
   * @param _rate         how many tokens per 1 Ether in first stage
   * @param _ratePublic   how many tokens per 1 Ether in last stage
   * @param _wallet       wallet to collect Ether
   * @param _token        ERC20 token to put on sale
   * @param _tokenHolder  address of the token holder - to approve crowdsale
   */
  constructor(
    uint256 _openingTime,
    uint256 _closingTime,
    uint256 _rate,
    uint256 _ratePublic,
    address _wallet,
    StandardToken _token,
    address _tokenHolder
  )
    public
    Crowdsale(_rate, _wallet, _token)
    AllowanceCrowdsale(_tokenHolder)
    TimedCrowdsale(_openingTime, _closingTime)
    IncreasingPriceCrowdsale(_rate, _ratePublic)
  {
    emit CrowdsaleCreated(
      msg.sender, 
      _openingTime, 
      _closingTime, 
      _rate);
  }

  /**
  * There are only 2 rates: private and public - equally long
  */
  function getCurrentRate() public view returns (uint256) {
    // solium-disable-next-line security/no-block-members
    uint256 elapsedTime = block.timestamp.sub(openingTime);
    uint256 timeRange = closingTime.sub(openingTime);
    if (elapsedTime < timeRange.div(2)) {
      return initialRate;
    } else {
      return finalRate;
    }
  }
}
/**
 * @title NmxCrowdsale
 * TimedCrowdsale - sets a time boundary for raising funds
 * AllowanceCrowdsale - allows to purchase tokens from external wallet
 */
function getCurrentRate() public view returns (uint256) {
  // solium-disable-next-line security/no-block-members
  uint256 elapsedTime = block.timestamp.sub(openingTime);
  uint256 timeRange = closingTime.sub(openingTime);
  if (elapsedTime < timeRange.div(2)) {
    return initialRate;
  } else {
    return finalRate;
  }
}

/**
 * There are only 2 rates: private and public - equally long
 */