From 763c8a14dea77658269d0551c0b2835a49c0a8b9 Mon Sep 17 00:00:00 2001 From: Paarth Shah Date: Wed, 4 Sep 2024 12:45:25 -0700 Subject: [PATCH] Add Date object --- blockkit/elements.py | 3 ++- blockkit/objects.py | 12 ++++++++++++ tests/test_elements.py | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/blockkit/elements.py b/blockkit/elements.py index e206b54..9668408 100644 --- a/blockkit/elements.py +++ b/blockkit/elements.py @@ -9,6 +9,7 @@ from blockkit.enums import ListStyle, Style from blockkit.objects import ( Confirm, + Date, DispatchActionConfig, Emoji, Filter, @@ -679,7 +680,7 @@ def __init__( ) -RichTextObject = Union[Text, Emoji] +RichTextObject = Union[Text, Date, Emoji] class RichTextPreformatted(Component): diff --git a/blockkit/objects.py b/blockkit/objects.py index aa62a64..e392a1d 100644 --- a/blockkit/objects.py +++ b/blockkit/objects.py @@ -18,6 +18,7 @@ "Text", "Style", "Emoji", + "Date", ] @@ -83,6 +84,17 @@ def __init__(self, *, name: str): super().__init__(name=name) +class Date(Component): + type: str = "date" + timestamp: int = Field(...) + format: str = Field(..., min_length=1) + url: Optional[str] = None + fallback: Optional[str] = None + + def __init__(self, *, timestamp: int, format: str, url: Optional[str] = None, fallback: Optional[str] = None): + super().__init__(timestamp=timestamp, format=format, url=url, fallback=fallback) + + class Confirm(Component): title: Union[PlainText, str] text: Union[PlainText, MarkdownText, str] diff --git a/tests/test_elements.py b/tests/test_elements.py index ed873f8..3b4ce28 100644 --- a/tests/test_elements.py +++ b/tests/test_elements.py @@ -34,6 +34,7 @@ ) from blockkit.objects import ( Confirm, + Date, DispatchActionConfig, Emoji, Filter, @@ -1430,6 +1431,7 @@ def test_builds_rich_text_quote(): Text(text="is better than well "), Text(text="said.", style=Style(bold=True, strike=True)), Emoji(name="wink"), + Date(timestamp=123456789, format="{ago}", url="https://example.com", fallback="Yep"), ] ).build() == { "type": "rich_text_quote", @@ -1439,6 +1441,7 @@ def test_builds_rich_text_quote(): {"type": "text", "text": "is better than well "}, {"type": "text", "text": "said.", "style": {"bold": True, "strike": True}}, {"type": "emoji", "name": "wink"}, + {"type": "date", "timestamp": 123456789, "format": "{ago}", "url": "https://example.com", "fallback": "Yep"}, ], }