Пример #1
0
 def _parse_datetime(self, value):
     if date_re.match(value):
         date_obj = parse_date(value)
         return datetime.combine(date_obj, time.min)
     elif datetime_re.match(value):
         return parse_datetime(value)
     else:
         return None
Пример #2
0
 def _parse_datetime(self, value):
     if date_re.match(value):
         date_obj = parse_date(value)
         return datetime.combine(date_obj, time.min)
     elif datetime_re.match(value):
         return parse_datetime(value)
     else:
         return None
Пример #3
0
def parse_date(value):
    """Parse a string and return a nepali_datetime_field.date.

    Raise ValueError if the input is well formatted but not a valid date.
    Return None if the input isn't well formatted.
    """
    match = date_re.match(value)
    if match:
        kw = {k: int(v) for k, v in match.groupdict().items()}
        return nepali_datetime.date(**kw)
Пример #4
0
def validate_stripe_api_version(version):
    """
    Check the API version is formatted correctly for Stripe.

    The expected format is an iso8601 date: `YYYY-MM-DD`

    :param version: The version to set for the Stripe API.
    :type version: ``str``
    :returns bool: Whether the version is formatted correctly.
    """
    return date_re.match(version)
Пример #5
0
def validate_stripe_api_version(version):
	"""
	Check the API version is formatted correctly for Stripe.

	The expected format is an iso8601 date: `YYYY-MM-DD`

	:param version: The version to set for the Stripe API.
	:type version: ``str``
	:returns bool: Whether the version is formatted correctly.
	"""
	return date_re.match(version)
Пример #6
0
def check_stripe_api_version(version):
    """
    Check the API version is formatted correctly for Stripe.

    :param version: The version to set for the Stripe API.
    :type version: ``str``
    :raises ImproperlyConfigured: If the version is not formatted correctly.
    """
    if not date_re.match(version):
        raise ImproperlyConfigured(
            "The Stripe API version must be a valid date in the form of "
            "'YYYY-MM-DD'. Value provided: '{}'.".format(version))
Пример #7
0
def parse_date_leniently(value):
    """Parses a string and return a datetime.date.

    Raises ValueError if the input is well formatted but not a valid date.
    Returns None if the input isn't well formatted.
    """
    match = date_re.match(value)
    if match:
        kw = {k: int(v) for k, v in six.iteritems(match.groupdict())}
        try:
            return date(**kw)
        except ValueError:
            kw['day'] = number_of_days_in_month(kw['year'], kw['month'])
            return date(**kw)