@@ -127,10 +127,19 @@ end
127
127
128
128
_parse (:: Type{S} , x) where {S} = parse (S, x)
129
129
function _parse (:: Type{Dates.Time} , x)
130
- h, m = parse .(Int, split (x, ' :' ))
130
+ segments = split (x, ' :' )
131
+ length (segments) >= 2 && all (! isempty, segments) || return nothing
132
+ h, m = parse .(Int, segments)
131
133
Dates. Time (h, m)
132
134
end
133
135
136
+ function _string (x:: Dates.Time )
137
+ h = Dates. hour (x)
138
+ m = Dates. minute (x)
139
+ string (lpad (h, 2 , " 0" ), " :" , lpad (m, 2 , " 0" ))
140
+ end
141
+ _string (x:: Dates.Date ) = string (x)
142
+
134
143
"""
135
144
`datepicker(value::Union{Dates.Date, Observable, Nothing}=nothing)`
136
145
@@ -149,17 +158,18 @@ for (func, typ, str, unit) in [(:timepicker, :(Dates.Time), "time", Dates.Second
149
158
@eval begin
150
159
function $func (:: WidgetTheme , val= nothing ; value= val, kwargs... )
151
160
(value isa AbstractObservable) || (value = Observable {Union{$typ, Nothing}} (value))
152
- f = x -> x === nothing ? " " : split ( string (x), ' . ' )[ 1 ]
161
+ f = x -> x === nothing ? " " : _string (x)
153
162
g = t -> _parse ($ typ, t)
154
163
pair = ObservablePair (value, f= f, g= g)
155
164
ui = input (pair. second; typ= $ str, kwargs... )
156
165
Widget {$(Expr(:quote, func))} (ui, output = value)
157
166
end
158
167
159
168
function $func (T:: WidgetTheme , vals:: AbstractRange , val= medianelement (vals); value= val, kwargs... )
160
- f = x -> x === nothing ? " " : split ( string (x), ' . ' )[ 1 ]
169
+ f = x -> x === nothing ? " " : _string (x)
161
170
fs = x -> x === nothing ? " " : split (string (convert ($ unit, x)), ' ' )[1 ]
162
- $ func (T; value= value, min= f (minimum (vals)), max= f (maximum (vals)), step= fs (step (vals)), kwargs... )
171
+ min, max = extrema (vals)
172
+ $ func (T; value= value, min= f (min), max= f (max), step= fs (step (vals)), kwargs... )
163
173
end
164
174
end
165
175
end
0 commit comments