implementation module Util import StdBool, StdList, StdFile, StdMisc, StdArray, StdString, StdTuple, StdGeneric, StdOrdList, Maybe, Time, Text, JSON, Void, Error, GenEq from SystemTypes import :: Date{..}, :: Time{..}, :: DateTime(..) from IWorld import :: IWorld{localDateTime,timestamp} mb2list :: !(Maybe [a]) -> [a] mb2list Nothing = [] mb2list (Just a) = a list2mb :: ![a] -> (Maybe [a]) list2mb [] = Nothing list2mb a = (Just a) voidNothing :: Maybe Void voidNothing = Nothing mb2error :: !e !(Maybe a) -> MaybeError e a mb2error error mbV = maybe (Error error) Ok mbV pad :: !Int !Int -> String pad len num = (createArray (max 0 (len - size nums)) '0' ) +++ nums where nums = toString num decFormat :: !Int -> String decFormat x = toString (x / 100) +++ "." +++ pad 2 (x rem 100) camelCaseToWords :: !String -> String camelCaseToWords label = {c \\ c <- [toUpper lname : addspace lnames]} where [lname:lnames] = fromString label addspace [] = [] addspace [c:cs] | c == '_' = [' ':addspace cs] | isUpper c = [' ',toLower c:addspace cs] | otherwise = [c:addspace cs] currentTime :: !*IWorld -> (!Time,!*IWorld) currentTime iworld=:{localDateTime=l=:(DateTime _ time)} = (time,iworld) currentDate :: !*IWorld -> (!Date,!*IWorld) currentDate iworld=:{localDateTime=l=:(DateTime date _)} = (date,iworld) currentDateTime :: !*IWorld -> (!DateTime,!*IWorld) currentDateTime iworld=:{localDateTime} = (localDateTime,iworld) currentTimestamp :: !*IWorld -> (!Timestamp,!*IWorld) currentTimestamp iworld=:{timestamp} = (timestamp,iworld) currentTimestampError :: !*IWorld -> (!MaybeErrorString Timestamp,!*IWorld) currentTimestampError iworld=:{timestamp} = (Ok timestamp,iworld) currentDateTimeWorld :: !*World -> (!DateTime,!*World) currentDateTimeWorld world # (tm,world) = localTime world = (tmToDateTime tm,world) timestampToGmDateTime :: !Timestamp -> DateTime timestampToGmDateTime timestamp = tmToDateTime (toGmTime timestamp) tmToDateTime :: !Tm -> DateTime tmToDateTime tm # date = {Date| day = tm.Tm.mday, mon = 1 + tm.Tm.mon, year = 1900 + tm.Tm.year} # time = {Time|hour = tm.Tm.hour, min = tm.Tm.min, sec= tm.Tm.sec} = DateTime date time instance toString (Maybe a) | toString a where toString Nothing = "" toString (Just x) = toString x