aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/LoggedIn/View
diff options
context:
space:
mode:
authorJoris2016-04-04 01:27:36 +0200
committerJoris2016-04-04 01:27:36 +0200
commit8cd63a64abafe21378c35c2489d49f24c9ece3c9 (patch)
tree541145481d1492f3e388002d931cb3f8fec0acb2 /src/client/elm/LoggedIn/View
parent01e4ce0fa7c369996ec4ef3a033d16d6fa0eb715 (diff)
downloadbudget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.tar.gz
budget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.tar.bz2
budget-8cd63a64abafe21378c35c2489d49f24c9ece3c9.zip
Add income list CRUD in user page
Diffstat (limited to 'src/client/elm/LoggedIn/View')
-rw-r--r--src/client/elm/LoggedIn/View/Date.elm44
-rw-r--r--src/client/elm/LoggedIn/View/Price.elm37
2 files changed, 81 insertions, 0 deletions
diff --git a/src/client/elm/LoggedIn/View/Date.elm b/src/client/elm/LoggedIn/View/Date.elm
new file mode 100644
index 0000000..f9528d4
--- /dev/null
+++ b/src/client/elm/LoggedIn/View/Date.elm
@@ -0,0 +1,44 @@
+module LoggedIn.View.Date
+ ( renderShortDate
+ , renderLongDate
+ ) where
+
+import Date exposing (..)
+import Utils.Date exposing (monthToNum)
+import String
+
+import Model.Translations exposing (..)
+
+renderShortDate : Date -> Translations -> String
+renderShortDate date translations =
+ let params =
+ [ String.pad 2 '0' (toString (Date.day date))
+ , String.pad 2 '0' (toString (monthToNum (Date.month date)))
+ , toString (Date.year date)
+ ]
+ in getParamMessage params "ShortDate" translations
+
+renderLongDate : Date -> Translations -> String
+renderLongDate date translations =
+ let params =
+ [ toString (Date.day date)
+ , (getMessage (getMonthKey (Date.month date)) translations)
+ , toString (Date.year date)
+ ]
+ in getParamMessage params "LongDate" translations
+
+getMonthKey : Month -> String
+getMonthKey month =
+ case month of
+ Jan -> "January"
+ Feb -> "February"
+ Mar -> "March"
+ Apr -> "April"
+ May -> "May"
+ Jun -> "June"
+ Jul -> "July"
+ Aug -> "August"
+ Sep -> "September"
+ Oct -> "October"
+ Nov -> "November"
+ Dec -> "December"
diff --git a/src/client/elm/LoggedIn/View/Price.elm b/src/client/elm/LoggedIn/View/Price.elm
new file mode 100644
index 0000000..2bfed23
--- /dev/null
+++ b/src/client/elm/LoggedIn/View/Price.elm
@@ -0,0 +1,37 @@
+module LoggedIn.View.Price
+ ( price
+ ) where
+
+import String exposing (..)
+
+import Model.Conf exposing (Conf)
+
+price : Conf -> Int -> String
+price conf amount =
+ ( formatInt amount
+ ++ " "
+ ++ conf.currency
+ )
+
+formatInt : Int -> String
+formatInt n =
+ abs n
+ |> toString
+ |> toList
+ |> List.reverse
+ |> group 3
+ |> List.intersperse [' ']
+ |> List.concat
+ |> List.reverse
+ |> fromList
+ |> append (if n < 0 then "-" else "")
+
+group : Int -> List a -> List (List a)
+group n xs =
+ if List.length xs <= n
+ then
+ [xs]
+ else
+ let take = List.take n xs
+ drop = List.drop n xs
+ in take :: (group n drop)