Remove code duplication by extract getAmountInPeriod method