Commit 7ad684b6 authored by Cédric F.'s avatar Cédric F.

Rename birthDate for consistency

parent 1f4c555c
......@@ -8,8 +8,8 @@ import DateExtra
type alias Model =
{ dateOfBirth : Date
, dateOfBirthString : String
{ birthDate : Date
, birthDateString : String
, kidUntil : Int
, oldFrom : Int
, lifeExpectancy : Int
......@@ -22,7 +22,7 @@ type alias Model =
type alias JsonModel =
{ dateOfBirth : Date
{ birthDate : Date
, kidUntil : Int
, oldFrom : Int
, lifeExpectancy : Int
......@@ -40,8 +40,8 @@ type alias Event =
initialModel : Model
initialModel =
{ dateOfBirth = DateExtra.unsafeFromString "1988-07-24"
, dateOfBirthString = "1988-07-24"
{ birthDate = DateExtra.unsafeFromString "1988-07-24"
, birthDateString = "1988-07-24"
, kidUntil = 18
, oldFrom = 70
, lifeExpectancy = 80
......@@ -56,8 +56,8 @@ initialModel =
mergeJsonModel : JsonModel -> Model
mergeJsonModel jsonModel =
{ initialModel
| dateOfBirth = jsonModel.dateOfBirth
, dateOfBirthString = DateExtra.toISOString jsonModel.dateOfBirth
| birthDate = jsonModel.birthDate
, birthDateString = DateExtra.toISOString jsonModel.birthDate
, kidUntil = jsonModel.kidUntil
, oldFrom = jsonModel.oldFrom
, lifeExpectancy = jsonModel.lifeExpectancy
......@@ -110,7 +110,7 @@ type Msg
deathDate : Model -> Date
deathDate model =
partialDate model (Date.year model.dateOfBirth + model.lifeExpectancy)
partialDate model (Date.year model.birthDate + model.lifeExpectancy)
partialDate : Model -> Int -> Date
......@@ -118,6 +118,6 @@ partialDate model year =
DateExtra.unsafeFromString <|
String.join "-"
[ toString year
, toString <| DateExtra.monthToInt <| Date.month model.dateOfBirth
, toString <| Date.day model.dateOfBirth
, toString <| DateExtra.monthToInt <| Date.month model.birthDate
, toString <| Date.day model.birthDate
]
......@@ -40,7 +40,7 @@ serializeJson : Model -> String
serializeJson model =
Encode.encode 2 <|
Encode.object
[ ( "date-of-birth", encodeDate model.dateOfBirth )
[ ( "birth-date", encodeDate model.birthDate )
, ( "life-expectancy", Encode.int model.lifeExpectancy )
, ( "kid-until", Encode.int model.kidUntil )
, ( "old-from", Encode.int model.oldFrom )
......@@ -51,7 +51,7 @@ serializeJson model =
jsonDecoder : Decode.Decoder JsonModel
jsonDecoder =
Decode.map5 JsonModel
(Decode.field "date-of-birth" dateDecoder)
(Decode.field "birth-date" dateDecoder)
(Decode.field "kid-until" Decode.int)
(Decode.field "old-from" Decode.int)
(Decode.field "life-expectancy" Decode.int)
......
......@@ -42,12 +42,12 @@ update msg model =
Ok date ->
let
newModel =
{ model | dateOfBirthString = string, dateOfBirth = date }
{ model | birthDateString = string, birthDate = date }
in
( newModel, updateUrl newModel )
Err _ ->
( { model | dateOfBirthString = string }, Cmd.none )
( { model | birthDateString = string }, Cmd.none )
NewLifeExpectancy string ->
let
......
......@@ -166,7 +166,7 @@ year : Model -> Int -> List Form
year model index =
let
year =
Date.year model.dateOfBirth + index
Date.year model.birthDate + index
paddedIndex =
String.padLeft 2 '0' (toString index)
......@@ -223,7 +223,7 @@ week model year week =
outOfBounds : Model -> Time -> Bool
outOfBounds model time =
time < Date.toTime model.dateOfBirth || time > Date.toTime (deathDate model)
time < Date.toTime model.birthDate || time > Date.toTime (deathDate model)
isCurrentWeek : Model -> Time -> Bool
......@@ -244,7 +244,7 @@ isKid : Model -> Time -> Bool
isKid model time =
let
kidDate =
partialDate model (Date.year model.dateOfBirth + model.kidUntil)
partialDate model (Date.year model.birthDate + model.kidUntil)
in
Date.toTime kidDate >= time
......@@ -253,7 +253,7 @@ isOld : Model -> Time -> Bool
isOld model time =
let
oldDate =
partialDate model (Date.year model.dateOfBirth + model.oldFrom)
partialDate model (Date.year model.birthDate + model.oldFrom)
in
Date.toTime oldDate <= time
......@@ -262,7 +262,7 @@ yearWeekToTime : Model -> ( Int, Int ) -> Time
yearWeekToTime model ( year, week ) =
let
currentYear =
Date.year model.dateOfBirth + year
Date.year model.birthDate + year
beginningOfYear =
DateExtra.unsafeFromString <| toString currentYear ++ "-01-01"
......
......@@ -66,12 +66,15 @@ controls model =
links : Model -> List (Html Msg)
links model =
let
demo =
"ewogICJiaXJ0aC1kYXRlIjogIjE5ODgtMDctMjQiLAogICJsaWZlLWV4cGVjdGFuY3kiOiA4MCwKICAia2lkLXVudGlsIjogMTgsCiAgIm9sZC1mcm9tIjogNzAsCiAgImV2ZW50cyI6IFsKICAgIHsKICAgICAgImZyb20iOiAiMjAxMC0wOS0xNCIsCiAgICAgICJ0byI6ICIyMDE0LTAyLTAxIiwKICAgICAgImNvbG9yIjogIiNmNTc5MDAiLAogICAgICAibGFiZWwiOiAiY29sbGVnZSIKICAgIH0sCiAgICB7CiAgICAgICJmcm9tIjogIjIwMTUtMDYtMDEiLAogICAgICAidG8iOiAiMjAxNi0wNS0zMSIsCiAgICAgICJjb2xvciI6ICIjNzNkMjE2IiwKICAgICAgImxhYmVsIjogInRyaXAiCiAgICB9CiAgXQp9Cg=="
base64 =
Serializer.serialize model
in
[ nav [ class "nav nav-inline text-xs-center mb-1" ]
[ a [ class "nav-link", href "#" ] [ text "blank chart" ]
, a [ class "nav-link", href "#ewogICJkYXRlLW9mLWJpcnRoIjogIjE5ODgtMDctMTQiLAogICJsaWZlLWV4cGVjdGFuY3kiOiA4MCwKICAia2lkLXVudGlsIjogMTgsCiAgIm9sZC1mcm9tIjogNzAsCiAgImV2ZW50cyI6IFsKICAgIHsKICAgICAgImZyb20iOiAiMjAxMC0wOS0xNCIsCiAgICAgICJ0byI6ICIyMDE0LTAyLTAxIiwKICAgICAgImNvbG9yIjogIiNmNTc5MDAiLAogICAgICAibGFiZWwiOiAiY29sbGVnZSAoZXhhbXBsZSkiCiAgICB9LAogICAgewogICAgICAiZnJvbSI6ICIyMDE1LTA2LTAxIiwKICAgICAgInRvIjogIjIwMTYtMDUtMzEiLAogICAgICAiY29sb3IiOiAiIzczZDIxNiIsCiAgICAgICJsYWJlbCI6ICJ0cmlwIChleGFtcGxlKSIKICAgIH0KICBdCn0=" ] [ text "demo chart" ]
, a [ class "nav-link", href <| "#" ++ demo ] [ text "demo chart" ]
, a [ class "nav-link", href <| "#" ++ base64 ] [ text "bookmark your own chart" ]
]
]
......@@ -85,7 +88,7 @@ config model =
[ input
(List.append dateInputAttributes
[ class "form-control form-control-lg"
, value model.dateOfBirthString
, value model.birthDateString
, onInput NewDateOfBirth
]
)
......@@ -246,8 +249,8 @@ metrics model =
percentage =
100
* (model.now - Date.toTime model.dateOfBirth)
/ (Date.toTime (deathDate model) - Date.toTime model.dateOfBirth)
* (model.now - Date.toTime model.birthDate)
/ (Date.toTime (deathDate model) - Date.toTime model.birthDate)
|> clamp 0 100
|> roundToPadded 6
in
......
{
"birth-date": "1988-07-24",
"life-expectancy": 80,
"kid-until": 18,
"old-from": 70,
"events": [
{
"from": "2010-09-14",
"to": "2014-02-01",
"color": "#f57900",
"label": "college"
},
{
"from": "2015-06-01",
"to": "2016-05-31",
"color": "#73d216",
"label": "trip"
}
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment