def _notification_created_before_today_deadline(notification_created_at): current_est_datetime = convert_utc_to_est(datetime.utcnow()) todays_deadline = current_est_datetime.replace( hour=LETTER_PROCESSING_DEADLINE.hour, minute=LETTER_PROCESSING_DEADLINE.minute, ) notification_created_at_in_est = convert_utc_to_est( notification_created_at) return notification_created_at_in_est <= todays_deadline
def printing_today_or_tomorrow(): now_utc = datetime.utcnow() now_est = convert_utc_to_est(now_utc) if now_est.time() < time(17, 30): return "today" else: return "tomorrow"
def _notification_created_before_that_day_deadline(notification_created_at): notification_created_at_est_datetime = convert_utc_to_est( notification_created_at) created_at_day_deadline = notification_created_at_est_datetime.replace( hour=LETTER_PROCESSING_DEADLINE.hour, minute=LETTER_PROCESSING_DEADLINE.minute, ) return notification_created_at_est_datetime <= created_at_day_deadline
def letter_can_be_cancelled(notification_status, notification_created_at): ''' If letter does not have status of created or pending-virus-check => can't be cancelled (it has already been processed) If it's after 5.30pm local time and the notification was created today before 5.30pm local time => can't be cancelled (it will already be zipped up to be sent) ''' if notification_status not in ('created', 'pending-virus-check'): return False if _after_letter_processing_deadline( ) and _notification_created_before_today_deadline(notification_created_at): return False if _notification_created_before_that_day_deadline( notification_created_at) and notification_created_at.date( ) < convert_utc_to_est(datetime.utcnow()).date(): return False if (convert_utc_to_est(datetime.utcnow()).date() - notification_created_at.date()).days > 1: return False return True
def _after_letter_processing_deadline(): current_utc_datetime = datetime.utcnow() est_time = convert_utc_to_est(current_utc_datetime).time() return est_time >= LETTER_PROCESSING_DEADLINE
def test_get_utc_in_est_returns_expected_date(date, expected_date): ret_date = convert_utc_to_est(date) assert ret_date == expected_date