2015-03-10 23:13:42 +00:00
|
|
|
module Import
|
|
|
|
( module Import
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Foundation as Import
|
|
|
|
import Import.NoFoundation as Import
|
2015-07-20 20:10:30 +00:00
|
|
|
import Yesod.Form.Bootstrap3 as Import
|
2015-08-16 22:14:33 +00:00
|
|
|
import Text.Printf
|
|
|
|
import Data.List (unfoldr)
|
2015-07-20 20:10:30 +00:00
|
|
|
|
2015-07-22 00:01:58 +00:00
|
|
|
loginOrDo :: ((Key User, User) -> Handler Html) -> Handler Html
|
2015-07-20 20:10:30 +00:00
|
|
|
loginOrDo cont = do
|
|
|
|
maid <- maybeAuthId
|
|
|
|
muid <- case maid of
|
2015-08-16 22:14:33 +00:00
|
|
|
Just uid -> fmap ((,) uid) <$> runDB (get uid)
|
2015-07-20 20:10:30 +00:00
|
|
|
Nothing -> return Nothing
|
|
|
|
case muid of
|
|
|
|
Nothing -> redirect (AuthR LoginR)
|
2015-07-22 00:01:58 +00:00
|
|
|
Just (uid,u) -> cont (uid,u)
|
2015-08-16 22:14:33 +00:00
|
|
|
|
|
|
|
prettyISK :: Int64 -> String
|
|
|
|
prettyISK isk = signIsk++pretty++","++ printf "%02u" cents
|
|
|
|
where
|
|
|
|
signIsk = if isk >= 0 then "" else "-"
|
|
|
|
(isk',cents) = divMod (abs isk) 100
|
|
|
|
thousands = unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` 1000, b `div` 1000)) isk'
|
|
|
|
pretty = case reverse thousands of
|
|
|
|
(ht:t) -> intercalate "." $ show ht : (printf "%03u" <$> t)
|
|
|
|
[] -> "0"
|
|
|
|
|
|
|
|
showTime :: Int64 -> String
|
|
|
|
showTime t = printf "%2u" hours ++ ":" ++ printf "%02u" minutes ++ ":" ++ printf "%02u" seconds
|
|
|
|
where
|
|
|
|
(hours, minutes') = divMod t 3600
|
|
|
|
(minutes, seconds) = divMod minutes' 60
|
|
|
|
|
|
|
|
showDateTime :: UTCTime -> String
|
|
|
|
showDateTime t = (show . utctDay $ t) ++ " " ++
|
|
|
|
(showTime . round . utctDayTime $ t)
|