Пример #1
0
def future_date_from_string(date_str):
    """Validation method for a date in the future, formatted as a string."""
    try:
        parsed_date = parser.parse(date_str)
    except ValueError:
        raise ValueError(
            f"Failed to parse '{date_str}' as a valid date. You can use any format "
            "recognized by dateutil.parser. For example, all of the strings below "
            "are valid ways to represent the same date: '2018-5-13' -or- '05/13/2018' "
            "-or- 'May 13 2018'.")

    if parsed_date.date() < date.today():
        raise ValueError(
            f"Successfully parsed {date_str} as "
            f"{parsed_date.strftime(DATE_MONTH_NAME)}. However, this value must be a "
            f"date in the future and {parsed_date.strftime(DATE_MONTH_NAME)} is BEFORE "
            f"{datetime.now().strftime(DATE_MONTH_NAME)}")
    deadline = datetime.combine(parsed_date.date(), time.max)
    deadline_utc = make_tzaware(deadline, use_tz=timezone.utc)
    return deadline_utc
Пример #2
0
 def registered_on_str(self):
     registered_on_utc = make_tzaware(self.registered_on,
                                      use_tz=timezone.utc,
                                      localize=False)
     return localized_dt_string(registered_on_utc,
                                use_tz=get_local_utcoffset())
Пример #3
0
 def deadline_str(self):
     deadline_utc = make_tzaware(self.deadline,
                                 use_tz=timezone.utc,
                                 localize=False)
     return localized_dt_string(deadline_utc, use_tz=get_local_utcoffset())
Пример #4
0
 def created_at_str(self):
     created_at_utc = make_tzaware(self.created_at,
                                   use_tz=timezone.utc,
                                   localize=False)
     return localized_dt_string(created_at_utc,
                                use_tz=get_local_utcoffset())