I am trying to initialize my model with the current date. I do not want to use my own module. I am trying to do this with task and effects. I am stuck in my method getCurrentTime. What is the cleanest way?
import Time exposing ( Time )
import StartApp
import Task
import Effects exposing (Never)
import Html exposing ( Html )
app =
StartApp.start
{ init = init
, view = view
, update = update
, inputs = []}
main =
app.html
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks
type alias Model =
{ clock : Time}
init : (Model, Effects.Effects Action)
init = ((Model ), Effects.none)
type Action = ShowClock
update : Action -> Model -> (Model, Effects.Effects Action)
update action model =
case action of
ShowClock c ->
({ model | clock = c}, Effects.none)
getCurrentTime : Effects.Effects Action
getCurrentTime =
-- stuck here
|> Task.map ShowClock
|> Effects.task
view : Signal.Address Action -> Model -> Html
view address model =
Signal.map Html.text model.clock
It would also be convenient to convert the time to a string with the format "YYYY-MM-DD".
source
share