예제 #1
0
def datedif(ctx, start_date, end_date, unit):
    """
    Calculates the number of days, months, or years between two dates.
    """
    start_date = conversions.to_date(start_date, ctx)
    end_date = conversions.to_date(end_date, ctx)
    unit = conversions.to_string(unit, ctx).lower()

    if start_date > end_date:
        raise ValueError("Start date cannot be after end date")

    if unit == 'y':
        return relativedelta(end_date, start_date).years
    elif unit == 'm':
        delta = relativedelta(end_date, start_date)
        return 12 * delta.years + delta.months
    elif unit == 'd':
        return (end_date - start_date).days
    elif unit == 'md':
        return relativedelta(end_date, start_date).days
    elif unit == 'ym':
        return relativedelta(end_date, start_date).months
    elif unit == 'yd':
        return (end_date - start_date.replace(year=end_date.year)).days

    raise ValueError("Invalid unit value: %s" % unit)
예제 #2
0
def datedif(ctx, start_date, end_date, unit):
    """
    Calculates the number of days, months, or years between two dates.
    """
    start_date = conversions.to_date(start_date, ctx)
    end_date = conversions.to_date(end_date, ctx)
    unit = conversions.to_string(unit, ctx).lower()

    if start_date > end_date:
        raise ValueError("Start date cannot be after end date")

    if unit == 'y':
        return relativedelta(end_date, start_date).years
    elif unit == 'm':
        delta = relativedelta(end_date, start_date)
        return 12 * delta.years + delta.months
    elif unit == 'd':
        return (end_date - start_date).days
    elif unit == 'md':
        return relativedelta(end_date, start_date).days
    elif unit == 'ym':
        return relativedelta(end_date, start_date).months
    elif unit == 'yd':
        return (end_date - start_date.replace(year=end_date.year)).days

    raise ValueError("Invalid unit value: %s" % unit)
예제 #3
0
파일: tests.py 프로젝트: pld/flows
    def evaluate(self, runner, run, context, text):
        try:
            date = conversions.to_date(text, context)
            if self.evaluate_for_date(runner, context, date):
                return Test.Result.match(date)
        except EvaluationError:
            pass

        return Test.Result.NO_MATCH
예제 #4
0
파일: tests.py 프로젝트: jofomah/flows
    def evaluate(self, runner, run, context, text):
        try:
            date = conversions.to_date(text, context)
            if self.evaluate_for_date(runner, context, date):
                return Test.Result.match(date)
        except EvaluationError:
            pass

        return Test.Result.NO_MATCH
예제 #5
0
파일: tests.py 프로젝트: pld/flows
    def evaluate_for_date(self, runner, context, date):
        test, errors = runner.substitute_variables(self.test, context)

        if not errors:
            try:
                test_val = conversions.to_date(test, context)
                return self.do_comparison(date, test_val)
            except Exception:
                pass

        return False
예제 #6
0
파일: tests.py 프로젝트: jofomah/flows
    def evaluate_for_date(self, runner, context, date):
        test, errors = runner.substitute_variables(self.test, context)

        if not errors:
            try:
                test_val = conversions.to_date(test, context)
                return self.do_comparison(date, test_val)
            except Exception:
                pass

        return False
예제 #7
0
def datevalue(ctx, text):
    """
    Converts date stored in text to an actual date
    """
    return conversions.to_date(text, ctx)
예제 #8
0
def datevalue(ctx, text):
    """
    Converts date stored in text to an actual date
    """
    return conversions.to_date(text, ctx)