2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// Constants for [TimePicker] specific properties and events.
|
2021-09-07 17:36:50 +03:00
|
|
|
const (
|
2024-09-12 14:05:11 +03:00
|
|
|
// TimeChangedEvent is the constant for "time-changed" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `TimePicker`.
|
|
|
|
// Occur when current time of the time picker has been changed.
|
|
|
|
//
|
|
|
|
// General listener format:
|
|
|
|
// `func(picker rui.TimePicker, newTime, oldTime time.Time)`.
|
|
|
|
//
|
|
|
|
// where:
|
|
|
|
// picker - Interface of a time picker which generated this event,
|
|
|
|
// newTime - New time value,
|
|
|
|
// oldTime - Old time value.
|
|
|
|
//
|
|
|
|
// Allowed listener formats:
|
|
|
|
// `func(picker rui.TimePicker, newTime time.Time)`,
|
|
|
|
// `func(newTime, oldTime time.Time)`,
|
|
|
|
// `func(newTime time.Time)`,
|
|
|
|
// `func(picker rui.TimePicker)`,
|
|
|
|
// `func()`.
|
2024-11-13 12:56:39 +03:00
|
|
|
TimeChangedEvent PropertyName = "time-changed"
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
// TimePickerMin is the constant for "time-picker-min" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `TimePicker`.
|
|
|
|
// The minimum value of the time.
|
|
|
|
//
|
|
|
|
// Supported types: `time.Time`, `string`.
|
|
|
|
//
|
|
|
|
// Internal type is `time.Time`, other types converted to it during assignment.
|
|
|
|
//
|
|
|
|
// Conversion rules:
|
|
|
|
// `string` - values of this type parsed and converted to `time.Time`. The following formats are supported:
|
|
|
|
// "HH:MM:SS" - "08:15:00".
|
|
|
|
// "HH:MM:SS PM" - "08:15:00 AM".
|
|
|
|
// "HH:MM" - "08:15".
|
|
|
|
// "HH:MM PM" - "08:15 AM".
|
2024-11-13 12:56:39 +03:00
|
|
|
TimePickerMin PropertyName = "time-picker-min"
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
// TimePickerMax is the constant for "time-picker-max" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `TimePicker`.
|
|
|
|
// The maximum value of the time.
|
|
|
|
//
|
|
|
|
// Supported types: `time.Time`, `string`.
|
|
|
|
//
|
|
|
|
// Internal type is `time.Time`, other types converted to it during assignment.
|
|
|
|
//
|
|
|
|
// Conversion rules:
|
|
|
|
// `string` - values of this type parsed and converted to `time.Time`. The following formats are supported:
|
|
|
|
// "HH:MM:SS" - "08:15:00".
|
|
|
|
// "HH:MM:SS PM" - "08:15:00 AM".
|
|
|
|
// "HH:MM" - "08:15".
|
|
|
|
// "HH:MM PM" - "08:15 AM".
|
2024-11-13 12:56:39 +03:00
|
|
|
TimePickerMax PropertyName = "time-picker-max"
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
// TimePickerStep is the constant for "time-picker-step" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `TimePicker`.
|
|
|
|
// Time step in seconds.
|
|
|
|
//
|
|
|
|
// Supported types: `int`, `string`.
|
|
|
|
//
|
|
|
|
// Values:
|
|
|
|
// >= `0` or >= "0" - Step value in seconds used to increment or decrement time.
|
2024-11-13 12:56:39 +03:00
|
|
|
TimePickerStep PropertyName = "time-picker-step"
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
// TimePickerValue is the constant for "time-picker-value" property tag.
|
2024-09-18 13:50:06 +03:00
|
|
|
//
|
|
|
|
// Used by `TimePicker`.
|
|
|
|
// Current value.
|
|
|
|
//
|
|
|
|
// Supported types: `time.Time`, `string`.
|
|
|
|
//
|
|
|
|
// Internal type is `time.Time`, other types converted to it during assignment.
|
|
|
|
//
|
|
|
|
// Conversion rules:
|
|
|
|
// `string` - values of this type parsed and converted to `time.Time`. The following formats are supported:
|
|
|
|
// "HH:MM:SS" - "08:15:00".
|
|
|
|
// "HH:MM:SS PM" - "08:15:00 AM".
|
|
|
|
// "HH:MM" - "08:15".
|
|
|
|
// "HH:MM PM" - "08:15 AM".
|
2024-11-13 12:56:39 +03:00
|
|
|
TimePickerValue PropertyName = "time-picker-value"
|
2024-09-12 14:05:11 +03:00
|
|
|
|
|
|
|
timeFormat = "15:04:05"
|
2021-09-07 17:36:50 +03:00
|
|
|
)
|
|
|
|
|
2024-09-12 14:05:11 +03:00
|
|
|
// TimePicker represents a TimePicker view
|
2021-09-07 17:36:50 +03:00
|
|
|
type TimePicker interface {
|
|
|
|
View
|
|
|
|
}
|
|
|
|
|
|
|
|
type timePickerData struct {
|
|
|
|
viewData
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTimePicker create new TimePicker object and return it
|
|
|
|
func NewTimePicker(session Session, params Params) TimePicker {
|
|
|
|
view := new(timePickerData)
|
2022-09-01 11:04:50 +03:00
|
|
|
view.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
setInitParams(view, params)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTimePicker(session Session) View {
|
2024-11-13 12:56:39 +03:00
|
|
|
return new(timePickerData)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2022-09-01 11:04:50 +03:00
|
|
|
func (picker *timePickerData) init(session Session) {
|
|
|
|
picker.viewData.init(session)
|
2021-09-07 17:36:50 +03:00
|
|
|
picker.tag = "TimePicker"
|
2024-04-23 18:24:51 +03:00
|
|
|
picker.hasHtmlDisabled = true
|
2024-11-13 12:56:39 +03:00
|
|
|
picker.normalize = normalizeTimePickerTag
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.set = picker.setFunc
|
|
|
|
picker.changed = picker.propertyChanged
|
2022-05-22 12:54:02 +03:00
|
|
|
}
|
|
|
|
|
2022-01-15 01:20:04 +03:00
|
|
|
func (picker *timePickerData) Focusable() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func normalizeTimePickerTag(tag PropertyName) PropertyName {
|
|
|
|
tag = defaultNormalize(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
switch tag {
|
|
|
|
case Type, Min, Max, Step, Value:
|
|
|
|
return "time-picker-" + tag
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
return normalizeDataListTag(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func stringToTime(value string) (time.Time, bool) {
|
|
|
|
lowText := strings.ToUpper(value)
|
|
|
|
pm := strings.HasSuffix(lowText, "PM") || strings.HasSuffix(lowText, "AM")
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
var format string
|
|
|
|
switch len(strings.Split(value, ":")) {
|
|
|
|
case 2:
|
|
|
|
if pm {
|
|
|
|
format = "3:04 PM"
|
2021-11-20 11:15:28 +03:00
|
|
|
} else {
|
2024-11-13 12:56:39 +03:00
|
|
|
format = "15:04"
|
2024-05-18 18:57:41 +03:00
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
default:
|
2024-11-13 12:56:39 +03:00
|
|
|
if pm {
|
|
|
|
format = "03:04:05 PM"
|
|
|
|
} else {
|
|
|
|
format = "15:04:05"
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
result, err := time.Parse(format, value)
|
|
|
|
if err != nil {
|
|
|
|
ErrorLog(err.Error())
|
|
|
|
return time.Now(), false
|
|
|
|
}
|
|
|
|
return result, true
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
func (picker *timePickerData) setFunc(tag PropertyName, value any) []PropertyName {
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
setTimeValue := func(tag PropertyName) []PropertyName {
|
2021-09-07 17:36:50 +03:00
|
|
|
switch value := value.(type) {
|
|
|
|
case time.Time:
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.setRaw(tag, value)
|
2024-11-13 12:56:39 +03:00
|
|
|
return []PropertyName{tag}
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case string:
|
2024-11-13 12:56:39 +03:00
|
|
|
if isConstantName(value) {
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.setRaw(tag, value)
|
2024-11-13 12:56:39 +03:00
|
|
|
return []PropertyName{tag}
|
|
|
|
}
|
2022-06-09 13:08:39 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
if time, ok := stringToTime(value); ok {
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.setRaw(tag, time)
|
2024-11-13 12:56:39 +03:00
|
|
|
return []PropertyName{tag}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
notCompatibleType(tag, value)
|
2024-11-13 12:56:39 +03:00
|
|
|
return nil
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case TimePickerMin:
|
2024-11-13 12:56:39 +03:00
|
|
|
return setTimeValue(TimePickerMin)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case TimePickerMax:
|
2024-11-13 12:56:39 +03:00
|
|
|
return setTimeValue(TimePickerMax)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case TimePickerStep:
|
2024-11-18 17:20:25 +03:00
|
|
|
return setIntProperty(picker, TimePickerStep, value)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case TimePickerValue:
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.setRaw("old-time", GetTimePickerValue(picker))
|
2024-11-13 12:56:39 +03:00
|
|
|
return setTimeValue(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
case TimeChangedEvent:
|
2024-11-18 17:20:25 +03:00
|
|
|
return setTwoArgEventListener[TimePicker, time.Time](picker, tag, value)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
case DataList:
|
2024-11-18 17:20:25 +03:00
|
|
|
return setDataList(picker, value, timeFormat)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
return picker.viewData.setFunc(tag, value)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
func (picker *timePickerData) propertyChanged(tag PropertyName) {
|
2024-11-13 12:56:39 +03:00
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
session := picker.Session()
|
2024-11-13 12:56:39 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
switch tag {
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
case TimePickerMin:
|
2024-11-18 17:20:25 +03:00
|
|
|
if time, ok := GetTimePickerMin(picker); ok {
|
|
|
|
session.updateProperty(picker.htmlID(), "min", time.Format(timeFormat))
|
2024-11-13 12:56:39 +03:00
|
|
|
} else {
|
2024-11-18 17:20:25 +03:00
|
|
|
session.removeProperty(picker.htmlID(), "min")
|
2024-11-13 12:56:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case TimePickerMax:
|
2024-11-18 17:20:25 +03:00
|
|
|
if time, ok := GetTimePickerMax(picker); ok {
|
|
|
|
session.updateProperty(picker.htmlID(), "max", time.Format(timeFormat))
|
2024-11-13 12:56:39 +03:00
|
|
|
} else {
|
2024-11-18 17:20:25 +03:00
|
|
|
session.removeProperty(picker.htmlID(), "max")
|
2024-11-13 12:56:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case TimePickerStep:
|
2024-11-18 17:20:25 +03:00
|
|
|
if step := GetTimePickerStep(picker); step > 0 {
|
|
|
|
session.updateProperty(picker.htmlID(), "step", strconv.Itoa(step))
|
2024-11-13 12:56:39 +03:00
|
|
|
} else {
|
2024-11-18 17:20:25 +03:00
|
|
|
session.removeProperty(picker.htmlID(), "step")
|
2024-11-13 12:56:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case TimePickerValue:
|
2024-11-18 17:20:25 +03:00
|
|
|
value := GetTimePickerValue(picker)
|
|
|
|
session.callFunc("setInputValue", picker.htmlID(), value.Format(timeFormat))
|
2024-11-13 12:56:39 +03:00
|
|
|
|
2024-11-18 17:20:25 +03:00
|
|
|
if listeners := GetTimeChangedListeners(picker); len(listeners) > 0 {
|
2024-11-13 12:56:39 +03:00
|
|
|
oldTime := time.Now()
|
2024-11-18 17:20:25 +03:00
|
|
|
if val := picker.getRaw("old-time"); val != nil {
|
2024-11-13 12:56:39 +03:00
|
|
|
if time, ok := val.(time.Time); ok {
|
|
|
|
oldTime = time
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, listener := range listeners {
|
2024-11-18 17:20:25 +03:00
|
|
|
listener(picker, value, oldTime)
|
2024-11-13 12:56:39 +03:00
|
|
|
}
|
|
|
|
}
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
default:
|
2024-11-18 17:20:25 +03:00
|
|
|
picker.viewData.propertyChanged(tag)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (picker *timePickerData) htmlTag() string {
|
|
|
|
return "input"
|
|
|
|
}
|
|
|
|
|
2024-05-18 18:57:41 +03:00
|
|
|
func (picker *timePickerData) htmlSubviews(self View, buffer *strings.Builder) {
|
2024-11-13 12:56:39 +03:00
|
|
|
dataListHtmlSubviews(self, buffer, func(text string, session Session) string {
|
|
|
|
text, _ = session.resolveConstants(text)
|
|
|
|
if time, ok := stringToTime(text); ok {
|
|
|
|
return time.Format(timeFormat)
|
|
|
|
}
|
|
|
|
return text
|
|
|
|
})
|
2024-05-18 18:57:41 +03:00
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
func (picker *timePickerData) htmlProperties(self View, buffer *strings.Builder) {
|
|
|
|
picker.viewData.htmlProperties(self, buffer)
|
|
|
|
|
|
|
|
buffer.WriteString(` type="time"`)
|
|
|
|
|
|
|
|
if min, ok := getTimeProperty(picker, TimePickerMin, Min); ok {
|
|
|
|
buffer.WriteString(` min="`)
|
|
|
|
buffer.WriteString(min.Format(timeFormat))
|
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
|
|
|
if max, ok := getTimeProperty(picker, TimePickerMax, Max); ok {
|
|
|
|
buffer.WriteString(` max="`)
|
|
|
|
buffer.WriteString(max.Format(timeFormat))
|
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
|
|
|
if step, ok := intProperty(picker, TimePickerStep, picker.Session(), 0); ok && step > 0 {
|
|
|
|
buffer.WriteString(` step="`)
|
|
|
|
buffer.WriteString(strconv.Itoa(step))
|
|
|
|
buffer.WriteByte('"')
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.WriteString(` value="`)
|
2022-08-31 22:17:46 +03:00
|
|
|
buffer.WriteString(GetTimePickerValue(picker).Format(timeFormat))
|
2021-09-07 17:36:50 +03:00
|
|
|
buffer.WriteByte('"')
|
|
|
|
|
|
|
|
buffer.WriteString(` oninput="editViewInputEvent(this)"`)
|
2022-04-15 15:41:44 +03:00
|
|
|
if picker.getRaw(ClickEvent) == nil {
|
|
|
|
buffer.WriteString(` onclick="stopEventPropagation(this, event)"`)
|
|
|
|
}
|
2024-05-18 18:57:41 +03:00
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
dataListHtmlProperties(picker, buffer)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func (picker *timePickerData) handleCommand(self View, command PropertyName, data DataObject) bool {
|
2021-09-07 17:36:50 +03:00
|
|
|
switch command {
|
|
|
|
case "textChanged":
|
|
|
|
if text, ok := data.PropertyValue("text"); ok {
|
|
|
|
if value, err := time.Parse(timeFormat, text); err == nil {
|
2022-08-31 22:17:46 +03:00
|
|
|
oldValue := GetTimePickerValue(picker)
|
2021-09-07 17:36:50 +03:00
|
|
|
picker.properties[TimePickerValue] = value
|
|
|
|
if value != oldValue {
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, listener := range GetTimeChangedListeners(picker) {
|
2023-04-23 18:54:53 +03:00
|
|
|
listener(picker, value, oldValue)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
2024-11-13 12:56:39 +03:00
|
|
|
if listener, ok := picker.changeListener[TimePickerValue]; ok {
|
|
|
|
listener(picker, TimePickerValue)
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return picker.viewData.handleCommand(self, command, data)
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
func getTimeProperty(view View, mainTag, shortTag PropertyName) (time.Time, bool) {
|
2022-07-26 18:36:00 +03:00
|
|
|
valueToTime := func(value any) (time.Time, bool) {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value != nil {
|
|
|
|
switch value := value.(type) {
|
|
|
|
case time.Time:
|
|
|
|
return value, true
|
|
|
|
|
|
|
|
case string:
|
|
|
|
if text, ok := view.Session().resolveConstants(value); ok {
|
2024-11-13 12:56:39 +03:00
|
|
|
if result, ok := stringToTime(text); ok {
|
2021-09-07 17:36:50 +03:00
|
|
|
return result, true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return time.Now(), false
|
|
|
|
}
|
|
|
|
|
|
|
|
if view != nil {
|
|
|
|
if result, ok := valueToTime(view.getRaw(mainTag)); ok {
|
|
|
|
return result, true
|
|
|
|
}
|
|
|
|
|
2024-11-13 12:56:39 +03:00
|
|
|
for _, tag := range []PropertyName{mainTag, shortTag} {
|
|
|
|
if value := valueFromStyle(view, tag); value != nil {
|
|
|
|
if result, ok := valueToTime(value); ok {
|
|
|
|
return result, true
|
|
|
|
}
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return time.Now(), false
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimePickerMin returns the min time of TimePicker subview and "true" as the second value if the min time is set,
|
|
|
|
// "false" as the second value otherwise.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTimePickerMin(view View, subviewID ...string) (time.Time, bool) {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2021-09-07 17:36:50 +03:00
|
|
|
return getTimeProperty(view, TimePickerMin, Min)
|
|
|
|
}
|
|
|
|
return time.Now(), false
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimePickerMax returns the max time of TimePicker subview and "true" as the second value if the min time is set,
|
|
|
|
// "false" as the second value otherwise.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTimePickerMax(view View, subviewID ...string) (time.Time, bool) {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view != nil {
|
2021-09-07 17:36:50 +03:00
|
|
|
return getTimeProperty(view, TimePickerMax, Max)
|
|
|
|
}
|
|
|
|
return time.Now(), false
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimePickerStep returns the time changing step in seconds of TimePicker subview.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTimePickerStep(view View, subviewID ...string) int {
|
2022-07-28 12:11:27 +03:00
|
|
|
return intStyledProperty(view, subviewID, TimePickerStep, 60)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimePickerValue returns the time of TimePicker subview.
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
|
|
func GetTimePickerValue(view View, subviewID ...string) time.Time {
|
2024-11-24 16:43:31 +03:00
|
|
|
if view = getSubview(view, subviewID); view == nil {
|
2021-09-07 17:36:50 +03:00
|
|
|
return time.Now()
|
|
|
|
}
|
|
|
|
time, _ := getTimeProperty(view, TimePickerValue, Value)
|
|
|
|
return time
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTimeChangedListeners returns the TimeChangedListener list of an TimePicker subview.
|
|
|
|
// If there are no listeners then the empty list is returned
|
2022-08-31 22:17:46 +03:00
|
|
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
2023-04-23 18:54:53 +03:00
|
|
|
func GetTimeChangedListeners(view View, subviewID ...string) []func(TimePicker, time.Time, time.Time) {
|
2024-11-18 17:20:25 +03:00
|
|
|
return getTwoArgEventListeners[TimePicker, time.Time](view, subviewID, TimeChangedEvent)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|