Skip to content

kamihi.questions.datetime ⚓︎

Generic datetime reusable question.

License

MIT

Classes:

Name Description
Datetime

Generic date reusable question.

Datetime ⚓︎

Datetime(
    text: str,
    error_text: str = None,
    before: datetime | None = None,
    after: datetime | None = None,
    in_the_past: bool = False,
    in_the_future: bool = False,
)

Bases: Question

Generic date reusable question.

Initialize an instance of the Datetime question.

Parameters:

Name Type Description Default

text ⚓︎

str

The text of the question.

required

error_text ⚓︎

str

The error text to display for invalid responses. Defaults to a value from settings.

None

before ⚓︎

datetime | None

The latest acceptable date (exclusive). Defaults to None.

None

after ⚓︎

datetime | None

The earliest acceptable date (exclusive). Defaults to None

None

in_the_past ⚓︎

bool

Whether the date must be in the past. Defaults to False.

False

in_the_future ⚓︎

bool

Whether the date must be in the future. Defaults to False.

False
Source code in src/kamihi/questions/datetime.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def __init__(
    self,
    text: str,
    error_text: str = None,
    before: datetime | None = None,
    after: datetime | None = None,
    in_the_past: bool = False,  # noqa: FBT001, FBT002
    in_the_future: bool = False,  # noqa: FBT001, FBT002
) -> None:
    """
    Initialize an instance of the Datetime question.

    Args:
        text (str): The text of the question.
        error_text (str, optional): The error text to display for invalid responses. Defaults to a value from settings.
        before (datetime | None, optional): The latest acceptable date (exclusive). Defaults to None.
        after (datetime | None, optional): The earliest acceptable date (exclusive). Defaults to None
        in_the_past (bool, optional): Whether the date must be in the past. Defaults to False.
        in_the_future (bool, optional): Whether the date must be in the future. Defaults to False.

    """
    super().__init__()
    self.question_text = text

    if error_text is not None:
        self.error_text = error_text

    self.before = before
    if self.before and not before.tzinfo:
        self.before = before.replace(tzinfo=get_settings().timezone_obj)

    self.after = after
    if self.after and not after.tzinfo:
        self.after = after.replace(tzinfo=get_settings().timezone_obj)

    self.in_the_past = in_the_past
    self.in_the_future = in_the_future