Skip to content

Commit 1058da3

Browse files
authored
Support all possible fields for RichTextElementParts.Date (#1536)
1 parent 98950d9 commit 1058da3

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

slack_sdk/models/blocks/block_elements.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,17 +2099,23 @@ class Date(RichTextElement):
20992099

21002100
@property
21012101
def attributes(self) -> Set[str]:
2102-
return super().attributes.union({"timestamp"})
2102+
return super().attributes.union({"timestamp", "format", "url", "fallback"})
21032103

21042104
def __init__(
21052105
self,
21062106
*,
21072107
timestamp: str,
2108+
format: str,
2109+
url: Optional[str] = None,
2110+
fallback: Optional[str] = None,
21082111
**others: dict,
21092112
):
21102113
super().__init__(type=self.type)
21112114
show_unknown_key_warning(self, others)
21122115
self.timestamp = timestamp
2116+
self.format = format
2117+
self.url = url
2118+
self.fallback = fallback
21132119

21142120
class Broadcast(RichTextElement):
21152121
type = "broadcast"

tests/slack_sdk/models/test_blocks.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,25 @@ def test_complex(self):
10031003
{"type": "usergroup", "usergroup_id": "S01BL602YLU"},
10041004
{"type": "text", "text": " "},
10051005
{"type": "channel", "channel_id": "C02GD0YEHDJ"},
1006+
{
1007+
"type": "date",
1008+
"timestamp": "1628633089",
1009+
"format": "{date_long}",
1010+
"url": "https://slack.com",
1011+
"fallback": "August 10, 2021",
1012+
},
1013+
{"type": "date", "timestamp": "1720710212", "format": "{date_num} at {time}", "fallback": "timey"},
1014+
{
1015+
"type": "date",
1016+
"timestamp": "1628633089",
1017+
"format": "{date_short_pretty}",
1018+
"url": "https://slack.com",
1019+
},
1020+
{
1021+
"type": "date",
1022+
"timestamp": "1628633089",
1023+
"format": "{ago}",
1024+
},
10061025
],
10071026
},
10081027
],
@@ -1078,6 +1097,12 @@ def test_complex(self):
10781097
_.UserGroup(usergroup_id="S01BL602YLU"),
10791098
_.Text(text=" "),
10801099
_.Channel(channel_id="C02GD0YEHDJ"),
1100+
_.Date(
1101+
timestamp="1628633089", format="{date_long}", url="https://slack.com", fallback="August 10, 2021"
1102+
),
1103+
_.Date(timestamp="1720710212", format="{date_num} at {time}", fallback="timey"),
1104+
_.Date(timestamp="1628633089", format="{date_short_pretty}", url="https://slack.com"),
1105+
_.Date(timestamp="1628633089", format="{ago}"),
10811106
]
10821107
),
10831108
],

0 commit comments

Comments
 (0)