Move this into the TIMESTAMP if statement below. You only need one TimeUnit.getTimeUnit call, as it's fine to let it throw if it's invalid below.