Repository: slack-go/slack
Pull request #1145 (2022-12-19 19:38:06)

add datetimepicker component

This is a new component that Slack supports `Datetimepicker` where date and time components are in the same row.
This new component takes number which I think it should be int64 for golang because Go's epoch API returns int64 data type. 
Since `datetimepicker` takes two columns, it's not supported in Accessory.  So, I don't include it as part of Section serialization/deserialization. 

PS. Sorry I deleted and restored a couple times. First didn't realize that I pushed the upstream, then I changed my mind because I tested it and it's working as expected. 

##### Pull Request Guidelines

These are recommendations for pull requests.
They are strictly guidelines to help manage expectations.

##### PR preparation
Run `make pr-prep` from the root of the repository to run formatting, linting and tests.

##### Should this be an issue instead
- [ ] is it a convenience method? (no new functionality, streamlines some use case)
- [ ] exposes a previously private type, const, method, etc.
- [ ] is it application specific (caching, retry logic, rate limiting, etc)
- [ ] is it performance related.

##### API changes

Since API changes have to be maintained they undergo a more detailed review and are more likely to require changes.

- no tests, if you're adding to the API include at least a single test of the happy case.
- If you can accomplish your goal without changing the API, then do so.
- dependency changes. updates are okay. adding/removing need justification.

###### Examples of API changes that do not meet guidelines:
- in library cache for users. caches are use case specific.
- Convenience methods for Sending Messages, update, post, ephemeral, etc. consider opening an issue instead.



Patch:
diff --git a/block.go b/block.go
index 240f552..18222bd 100644
--- a/block.go
+++ b/block.go
@@ -50,6 +50,7 @@ type BlockAction struct {
 	SelectedConversations []string            `json:"selected_conversations"`
 	SelectedDate          string              `json:"selected_date"`
 	SelectedTime          string              `json:"selected_time"`
+	SelectedDateTime      int64               `json:"selected_date_time"`
 	InitialOption         OptionBlockObject   `json:"initial_option"`
 	InitialUser           string              `json:"initial_user"`
 	InitialChannel        string              `json:"initial_channel"`
diff --git a/block_conv.go b/block_conv.go
index 555e481..4ab58de 100644
--- a/block_conv.go
+++ b/block_conv.go
@@ -110,6 +110,8 @@ func (b *InputBlock) UnmarshalJSON(data []byte) error {
 		e = &DatePickerBlockElement{}
 	case "timepicker":
 		e = &TimePickerBlockElement{}
+	case "datetimepicker":
+		e = &DateTimePickerBlockElement{}
 	case "plain_text_input":
 		e = &PlainTextInputBlockElement{}
 	case "email_text_input":
@@ -190,6 +192,8 @@ func (b *BlockElements) UnmarshalJSON(data []byte) error {
 			blockElement = &DatePickerBlockElement{}
 		case "timepicker":
 			blockElement = &TimePickerBlockElement{}
+		case "datetimepicker":
+			blockElement = &DateTimePickerBlockElement{}
 		case "plain_text_input":
 			blockElement = &PlainTextInputBlockElement{}
 		case "email_text_input":
@@ -233,6 +237,7 @@ func (a *Accessory) MarshalJSON() ([]byte, error) {
 
 // UnmarshalJSON implements the Unmarshaller interface for Accessory, so that any JSON
 // unmarshalling is delegated and proper type determination can be made before unmarshal
+// Note: datetimepicker is not supported in Accessory
 func (a *Accessory) UnmarshalJSON(data []byte) error {
 	var r json.RawMessage
 
diff --git a/block_element.go b/block_element.go
index aba29c6..a70d8f2 100644
--- a/block_element.go
+++ b/block_element.go
@@ -9,6 +9,7 @@ const (
 	METOverflow       MessageElementType = "overflow"
 	METDatepicker     MessageElementType = "datepicker"
 	METTimepicker     MessageElementType = "timepicker"
+	METDatetimepicker MessageElementType = "datetimepicker"
 	METPlainTextInput MessageElementType = "plain_text_input"
 	METRadioButtons   MessageElementType = "radio_buttons"
 	METEmailTextInput MessageElementType = "email_text_input"
@@ -392,6 +393,29 @@ func NewTimePickerBlockElement(actionID string) *TimePickerBlockElement {
 	}
 }
 
+// DateTimePickerBlockElement defines an element that allows the selection of both
+// a date and a time of day formatted as a UNIX timestamp.
+// More Information: https://api.slack.com/reference/messaging/block-elements#datetimepicker
+type DateTimePickerBlockElement struct {
+	Type            MessageElementType       `json:"type"`
+	ActionID        string                   `json:"action_id,omitempty"`
+	InitialDateTime int64                    `json:"initial_date_time,omitempty"`
+	Confirm         *ConfirmationBlockObject `json:"confirm,omitempty"`
+}
+
+// ElementType returns the type of the Element
+func (s DateTimePickerBlockElement) ElementType() MessageElementType {
+	return s.Type
+}
+
+// NewDatePickerBlockElement returns an instance of a datetime picker element
+func NewDateTimePickerBlockElement(actionID string) *DateTimePickerBlockElement {
+	return &DateTimePickerBlockElement{
+		Type:     METDatetimepicker,
+		ActionID: actionID,
+	}
+}
+
 // EmailTextInputBlockElement creates a field where a user can enter email
 // data.
 // email-text-input elements are currently only available in modals.


Test patch:
diff --git a/block_element_test.go b/block_element_test.go
index 164f8e2..0c47aff 100644
--- a/block_element_test.go
+++ b/block_element_test.go
@@ -133,6 +133,12 @@ func TestNewTimePickerBlockElement(t *testing.T) {
 	assert.Equal(t, timepickerElement.ActionID, "test")
 }
 
+func TestNewDateTimePickerBlockElement(t *testing.T) {
+	datetimepickerElement := NewDateTimePickerBlockElement("test")
+	assert.Equal(t, string(datetimepickerElement.Type), "datetimepicker")
+	assert.Equal(t, datetimepickerElement.ActionID, "test")
+}
+
 func TestNewPlainTextInputBlockElement(t *testing.T) {
 
 	plainTextInputElement := NewPlainTextInputBlockElement(nil, "test")