<commit_before>module JdConverter where

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Signal
import String

import Astronomy exposing (JD, CustomDate, timeToJd, jdToTime, dateToJd, dateFromJd)
import Utils exposing (formatJD)


main =
    Signal.map (view actions.address) (Signal.foldp update initModel actions.signal)


type alias Model = CustomDate


initModel = { year = 0,  month = 0, day = 0, hour = 0, minute = 0, second = 0 }


type Action
    = NoOp
    | SetYear String
    | SetMonth String
    | SetDay String
    | SetHour String
    | SetMinute String
    | SetSecond String
    | SetJD String


actions : Signal.Mailbox Action
actions = Signal.mailbox NoOp


update : Action -> Model -> Model
update action model =
    case action of
        SetYear value -> case String.toInt value of
            Ok value -> { model | year <- value }
            Err _ -> model
        SetMonth value -> case String.toInt value of
            Ok value -> { model | month <- value }
            Err _ -> model
        SetDay value -> case String.toInt value of
            Ok value -> { model | day <- value }
            Err _ -> model
        SetHour value -> case String.toInt value of
            Ok value -> { model | hour <- value }
            Err _ -> model
        SetMinute value -> case String.toInt value of
            Ok value -> { model | minute <- value }
            Err _ -> model
        SetSecond value -> case String.toInt value of
            Ok value -> { model | second <- value }
            Err _ -> model
        SetJD value -> case String.toFloat value of
            Ok value -> dateFromJd value
            Err _ -> model


calendarInput : Signal.Address Action -> Int -> (String -> Action) -> Html
calendarInput address modelValue action =
    input
        [ class "form-control"
        , type' "number"
        , value (toString modelValue)
        , on "input" targetValue (\str -> Signal.message address (action str))
        ]
        []


view : Signal.Address Action -> Model -> Html
view address model =
    div []
        [ text (toString model)
        , label [] [text "Date and time (UTC)"]
        , div [ class "form-group row" ]
            [ div [ class "col-xs-2" ] [calendarInput address model.year SetYear]
            , div [ class "col-xs-2" ] [calendarInput address model.month SetMonth]
            , div [ class "col-xs-2" ] [calendarInput address model.day SetDay]
            , div [ class "col-xs-2" ] [calendarInput address model.hour SetHour]
            , div [ class "col-xs-2" ] [calendarInput address model.minute SetMinute]
            , div [ class "col-xs-2" ] [calendarInput address model.second SetSecond]
            ],
        div [class "form-group" ]
            [ label [] [text "JD"]
            , input
                [ class "form-control"
                , value (formatJD 4 <| dateToJd model)
                , on "input" targetValue (\str -> Signal.message address (SetJD str))
                ]
                []
            ]<commit_msg>Store both date and current JD in the model.<commit_after>module JdConverter where

import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Signal
import String
import Time exposing (every, second)

import Astronomy exposing (JD, CustomDate, timeToJd, jdToTime, dateToJd, dateFromJd)
import Utils exposing (formatJD)


main =
    Signal.map
        (view actions.address)
        (Signal.foldp update initModel
            (Signal.merge tick actions.signal))


tick : Signal Action
tick = Signal.map (Tick << timeToJd) (every second)

type alias Model =
    { date : CustomDate
    , currentJD : JD
    }


initDate = { year = 0,  month = 0, day = 0, hour = 0, minute = 0, second = 0 }
initModel = { date = initDate, currentJD = 0 }


type Action
    = NoOp
    | SetYear String
    | SetMonth String
    | SetDay String
    | SetHour String
    | SetMinute String
    | SetSecond String
    | SetJD String
    | Tick JD


actions : Signal.Mailbox Action
actions = Signal.mailbox NoOp


update : Action -> Model -> Model
update action model =
    let
        d = model.date
    in
    case action of
        SetYear value -> case String.toInt value of
            Ok value -> { model | date <- { d | year <- value } }
            Err _ -> model
        SetMonth value -> case String.toInt value of
            Ok value -> { model | date <- { d | month <- value } }
            Err _ -> model
        SetDay value -> case String.toInt value of
            Ok value -> { model | date <- { d | day <- value } }
            Err _ -> model
        SetHour value -> case String.toInt value of
            Ok value -> { model | date <- { d | hour <- value } }
            Err _ -> model
        SetMinute value -> case String.toInt value of
            Ok value -> { model | date <- { d | minute <- value } }
            Err _ -> model
        SetSecond value -> case String.toInt value of
            Ok value -> { model | date <- { d | second <- value } }
            Err _ -> model
        SetJD value -> case String.toFloat value of
            Ok value -> { model | date <- dateFromJd value }
            Err _ -> model
        Tick jd -> { model | currentJD <- jd }


calendarInput : Signal.Address Action -> Int -> (String -> Action) -> Html
calendarInput address modelValue action =
    input
        [ class "form-control"
        , type' "number"
        , value (toString modelValue)
        , on "input" targetValue (\str -> Signal.message address (action str))
        ]
        []


view : Signal.Address Action -> Model -> Html
view address model =
    div []
        [ text (toString model)
        , label [] [text "Date and time (UTC)"]
        , div [ class "form-group row" ]
            [ div [ class "col-xs-2" ] [calendarInput address model.date.year SetYear]
            , div [ class "col-xs-2" ] [calendarInput address model.date.month SetMonth]
            , div [ class "col-xs-2" ] [calendarInput address model.date.day SetDay]
            , div [ class "col-xs-2" ] [calendarInput address model.date.hour SetHour]
            , div [ class "col-xs-2" ] [calendarInput address model.date.minute SetMinute]
            , div [ class "col-xs-2" ] [calendarInput address model.date.second SetSecond]
            ],
        div [class "form-group" ]
            [ label [] [text "JD"]
            , input
                [ class "form-control"
                , value (formatJD 4 <| dateToJd model.date)
                , on "input" targetValue (\str -> Signal.message address (SetJD str))
                ]
                []
            ]
{'fraction_non_alphanumeric': 0.10487731897067624, 'fraction_numerical': 0.004039497307001795, 'mean_word_length': 1.8362324989393297, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '324872', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1833, 'n_words': 637}