Prepare translating dates

This commit is contained in:
Eike Kettner 2021-04-12 10:53:34 +02:00
parent 7cb4f741e0
commit 5737eba82d
26 changed files with 593 additions and 154 deletions

View File

@ -18,7 +18,6 @@ import Http
import Messages.Comp.AttachmentMeta exposing (Texts)
import Styles as S
import Util.Http
import Util.Time
type alias Model =
@ -129,7 +128,7 @@ viewProposals2 texts props =
[ class S.basicLabel
, class "text-sm"
]
[ Util.Time.formatDateShort ms |> text
[ texts.formatDateShort ms |> text
]
in
div [ class "flex flex-col" ]

View File

@ -21,7 +21,6 @@ import Messages.Comp.CalEventInput exposing (Texts)
import Styles as S
import Util.Http
import Util.Maybe
import Util.Time
type alias Model =
@ -284,7 +283,7 @@ view2 texts extraClasses ev model =
, ul [ class "list-decimal list-inside text-sm" ]
(Maybe.map .next model.checkResult
|> Maybe.withDefault []
|> List.map Util.Time.formatDateTime
|> List.map texts.formatDateTime
|> List.map (\s -> li [ class "" ] [ text s ])
)
]

View File

@ -13,7 +13,6 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Messages.Comp.CustomFieldTable exposing (Texts)
import Styles as S
import Util.Time
type alias Model =
@ -59,13 +58,13 @@ view2 texts _ items =
]
]
, tbody []
(List.map viewItem2 items)
(List.map (viewItem2 texts) items)
]
]
viewItem2 : CustomField -> Html Msg
viewItem2 item =
viewItem2 : Texts -> CustomField -> Html Msg
viewItem2 texts item =
tr [ class S.tableRow ]
[ B.editLinkTableCell (EditItem item)
, td [ class "text-left py-4 md:py-2 pr-2" ]
@ -79,7 +78,7 @@ viewItem2 item =
|> text
]
, td [ class "text-center py-4 md:py-2 hidden sm:table-cell" ]
[ Util.Time.formatDateShort item.created
[ texts.formatDateShort item.created
|> text
]
]

View File

@ -13,7 +13,6 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Messages.Comp.FolderTable exposing (Texts)
import Styles as S
import Util.Time
type alias Model =
@ -69,12 +68,12 @@ view2 texts _ items =
]
]
, tbody []
(List.map viewItem2 items)
(List.map (viewItem2 texts) items)
]
viewItem2 : FolderItem -> Html Msg
viewItem2 item =
viewItem2 : Texts -> FolderItem -> Html Msg
viewItem2 texts item =
tr
[ class S.tableRow
]
@ -97,7 +96,7 @@ viewItem2 item =
|> text
]
, td [ class "text-center py-4 md:py-2" ]
[ Util.Time.formatDateShort item.created
[ texts.formatDateShort item.created
|> text
]
]

View File

@ -221,6 +221,14 @@ fulltextResultsContent2 item =
(List.map renderHighlightEntry2 item.highlighting)
templateCtx : Texts -> IT.TemplateContext
templateCtx texts =
{ dateFormatLong = texts.formatDateLong
, dateFormatShort = texts.formatDateShort
, directionLabel = texts.directionLabel
}
metaDataContent2 : Texts -> UiSettings -> ItemLight -> Html Msg
metaDataContent2 texts settings item =
let
@ -249,7 +257,7 @@ metaDataContent2 texts settings item =
, Comp.LinkTarget.makeSourceLink
[ ( "hover:opacity-60", True ) ]
SetLinkTarget
(IT.render IT.source item)
(IT.render IT.source (templateCtx texts) item)
]
]
]
@ -289,7 +297,7 @@ mainContent2 texts cardAction cardColor isConfirmed settings _ item =
[ class (Data.Direction.iconFromMaybe2 item.direction)
, class "mr-2 w-4 text-center"
, classList [ ( "hidden", fieldHidden Data.Fields.Direction ) ]
, IT.render IT.direction item |> title
, IT.render IT.direction (templateCtx texts) item |> title
]
[]
@ -330,9 +338,9 @@ mainContent2 texts cardAction cardColor isConfirmed settings _ item =
)
, div
[ class "font-bold py-1 text-lg"
, classList [ ( "hidden", IT.render titlePattern item == "" ) ]
, classList [ ( "hidden", IT.render titlePattern (templateCtx texts) item == "" ) ]
]
[ IT.render titlePattern item |> text
[ IT.render titlePattern (templateCtx texts) item |> text
]
, div
[ classList
@ -347,11 +355,11 @@ mainContent2 texts cardAction cardColor isConfirmed settings _ item =
, div
[ classList
[ ( "opacity-75", True )
, ( "hidden", IT.render subtitlePattern item == "" )
, ( "hidden", IT.render subtitlePattern (templateCtx texts) item == "" )
]
]
[ dirIcon
, IT.render subtitlePattern item |> text
, IT.render subtitlePattern (templateCtx texts) item |> text
]
, div [ class "" ]
[ mainTagsAndFields2 settings item
@ -466,7 +474,7 @@ previewMenu2 texts settings model item mainAttach =
|> Maybe.withDefault "/api/v1/sec/attachment/none"
dueDate =
IT.render IT.dueDateShort item
IT.render IT.dueDateShort (templateCtx texts) item
dueDateLabel =
div

View File

@ -32,7 +32,6 @@ import Styles as S
import Util.Folder
import Util.Person
import Util.Tag
import Util.Time
view2 : Texts -> Flags -> UiSettings -> Model -> Html Msg
@ -467,7 +466,7 @@ renderItemDateSuggestions : Texts -> Model -> Html Msg
renderItemDateSuggestions texts model =
renderSuggestions texts
model
Util.Time.formatDate
texts.formatDate
(List.take 6 model.itemProposals.itemDate)
SetItemDateSuggestion
@ -476,7 +475,7 @@ renderDueDateSuggestions : Texts -> Model -> Html Msg
renderDueDateSuggestions texts model =
renderSuggestions texts
model
Util.Time.formatDate
texts.formatDate
(List.take 6 model.itemProposals.dueDate)
SetDueDateSuggestion

View File

@ -19,7 +19,6 @@ import Messages.Comp.ItemDetail.ItemInfoHeader exposing (Texts)
import Page exposing (Page(..))
import Styles as S
import Util.Maybe
import Util.Time
view : Texts -> UiSettings -> Model -> Html Msg
@ -32,7 +31,7 @@ view texts settings model =
]
[ Icons.dateIcon2 "mr-2"
, Maybe.withDefault model.item.created model.item.itemDate
|> Util.Time.formatDate
|> texts.formatDate
|> text
]
, Data.UiSettings.fieldVisible settings Data.Fields.Date
@ -51,7 +50,7 @@ view texts settings model =
, title texts.dueDate
]
[ Icons.dueDateIcon2 "mr-2"
, Maybe.map Util.Time.formatDate model.item.dueDate
, Maybe.map texts.formatDate model.item.dueDate
|> Maybe.withDefault ""
|> text
]

View File

@ -292,14 +292,14 @@ itemIdInfo texts model =
, title texts.createdOn
]
[ i [ class "fa fa-sun font-thin mr-2" ] []
, Util.Time.formatDateTime model.item.created |> text
, texts.formatDateTime model.item.created |> text
]
, div
[ class "inline-flex items-center"
, title texts.lastUpdateOn
]
[ i [ class "fa fa-pencil-alt mr-2" ] []
, Util.Time.formatDateTime model.item.updated |> text
, texts.formatDateTime model.item.updated |> text
]
]

View File

@ -15,7 +15,6 @@ import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Messages.Comp.SentMails exposing (Texts)
import Styles as S
import Util.Time
type alias Model =
@ -82,7 +81,7 @@ view2 texts model =
[ text (texts.date ++ ":")
]
, div [ class "ml-2" ]
[ Util.Time.formatDateTime mail.created |> text
[ texts.formatDateTime mail.created |> text
]
]
, div [ class "flex flex-row" ]
@ -131,13 +130,13 @@ view2 texts model =
]
, tbody [] <|
List.map
renderLine2
(renderLine2 texts)
model.mails
]
renderLine2 : SentMail -> Html Msg
renderLine2 mail =
renderLine2 : Texts -> SentMail -> Html Msg
renderLine2 texts mail =
tr [ class S.tableRow ]
[ td []
[ B.linkLabel
@ -152,7 +151,7 @@ renderLine2 mail =
]
, td [ class "hidden" ] [ text mail.subject ]
, td [ class "hidden text-center xl:table-cell" ]
[ Util.Time.formatDateTime mail.created |> text
[ texts.formatDateTime mail.created |> text
]
, td [ class "hidden" ] [ text mail.sender ]
]

View File

@ -13,7 +13,6 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Messages.Comp.UserTable exposing (Texts)
import Styles as S
import Util.Time exposing (formatDateTime)
type alias Model =
@ -93,9 +92,9 @@ renderUserLine2 texts model user =
[ String.fromInt user.loginCount |> text
]
, td [ class "hidden sm:table-cell text-center" ]
[ Maybe.map formatDateTime user.lastLogin |> Maybe.withDefault "" |> text
[ Maybe.map texts.formatDateTime user.lastLogin |> Maybe.withDefault "" |> text
]
, td [ class "hidden md:table-cell text-center" ]
[ formatDateTime user.created |> text
[ texts.formatDateTime user.created |> text
]
]

View File

@ -1,5 +1,6 @@
module Data.ItemTemplate exposing
( ItemTemplate
, TemplateContext
, concEquip
, concPerson
, concat
@ -30,15 +31,21 @@ module Data.ItemTemplate exposing
import Api.Model.IdName exposing (IdName)
import Api.Model.ItemLight exposing (ItemLight)
import Data.Direction
import Data.Direction exposing (Direction)
import Set
import Util.List
import Util.String
import Util.Time
type alias TemplateContext =
{ dateFormatLong : Int -> String
, dateFormatShort : Int -> String
, directionLabel : Direction -> String
}
type ItemTemplate
= ItemTemplate (ItemLight -> String)
= ItemTemplate (TemplateContext -> ItemLight -> String)
readTemplate : String -> Maybe ItemTemplate
@ -55,16 +62,23 @@ readTemplate str =
Maybe.map read (splitTokens str)
render : ItemTemplate -> ItemLight -> String
render pattern item =
render : ItemTemplate -> TemplateContext -> ItemLight -> String
render pattern ctx item =
case pattern of
ItemTemplate f ->
f item
f ctx item
isEmpty : ItemTemplate -> ItemLight -> Bool
isEmpty pattern item =
render pattern item |> String.isEmpty
let
ctx =
{ dateFormatLong = \_ -> "non-empty"
, dateFormatShort = \_ -> "non-empty"
, directionLabel = \_ -> "non-empty"
}
in
render pattern ctx item |> String.isEmpty
nonEmpty : ItemTemplate -> ItemLight -> Bool
@ -80,14 +94,14 @@ map : (String -> String) -> ItemTemplate -> ItemTemplate
map f pattern =
case pattern of
ItemTemplate p ->
from (p >> f)
ItemTemplate (\ctx -> p ctx >> f)
map2 : (String -> String -> String) -> ItemTemplate -> ItemTemplate -> ItemTemplate
map2 f pattern1 pattern2 =
case ( pattern1, pattern2 ) of
( ItemTemplate p1, ItemTemplate p2 ) ->
from (\i -> f (p1 i) (p2 i))
ItemTemplate (\ctx -> \i -> f (p1 ctx i) (p2 ctx i))
combine : String -> ItemTemplate -> ItemTemplate -> ItemTemplate
@ -104,21 +118,23 @@ combine sep p1 p2 =
concat : List ItemTemplate -> ItemTemplate
concat patterns =
from
(\i ->
List.map (\p -> render p i) patterns
|> String.join ""
ItemTemplate
(\ctx ->
\i ->
List.map (\p -> render p ctx i) patterns
|> String.join ""
)
firstNonEmpty : List ItemTemplate -> ItemTemplate
firstNonEmpty patterns =
from
(\i ->
List.map (\p -> render p i) patterns
|> List.filter (String.isEmpty >> not)
|> List.head
|> Maybe.withDefault ""
ItemTemplate
(\ctx ->
\i ->
List.map (\p -> render p ctx i) patterns
|> List.filter (String.isEmpty >> not)
|> List.head
|> Maybe.withDefault ""
)
@ -128,17 +144,17 @@ firstNonEmpty patterns =
from : (ItemLight -> String) -> ItemTemplate
from f =
ItemTemplate f
ItemTemplate (\_ -> f)
fromMaybe : (ItemLight -> Maybe String) -> ItemTemplate
fromMaybe : (TemplateContext -> ItemLight -> Maybe String) -> ItemTemplate
fromMaybe f =
ItemTemplate (f >> Maybe.withDefault "")
ItemTemplate (\ctx -> f ctx >> Maybe.withDefault "")
literal : String -> ItemTemplate
literal str =
ItemTemplate (\_ -> str)
ItemTemplate (\_ -> \_ -> str)
empty : ItemTemplate
@ -148,57 +164,57 @@ empty =
name : ItemTemplate
name =
ItemTemplate (.name >> Util.String.underscoreToSpace)
from (.name >> Util.String.underscoreToSpace)
direction : ItemTemplate
direction =
let
dirStr ms =
dirStr ctx ms =
Maybe.andThen Data.Direction.fromString ms
|> Maybe.map Data.Direction.toString
|> Maybe.map ctx.directionLabel
in
fromMaybe (.direction >> dirStr)
fromMaybe (\ctx -> .direction >> dirStr ctx)
dateLong : ItemTemplate
dateLong =
ItemTemplate (.date >> Util.Time.formatDate)
ItemTemplate (\ctx -> .date >> ctx.dateFormatLong)
dateShort : ItemTemplate
dateShort =
ItemTemplate (.date >> Util.Time.formatDateShort)
ItemTemplate (\ctx -> .date >> ctx.dateFormatShort)
dueDateLong : ItemTemplate
dueDateLong =
fromMaybe (.dueDate >> Maybe.map Util.Time.formatDate)
fromMaybe (\ctx -> .dueDate >> Maybe.map ctx.dateFormatLong)
dueDateShort : ItemTemplate
dueDateShort =
fromMaybe (.dueDate >> Maybe.map Util.Time.formatDateShort)
fromMaybe (\ctx -> .dueDate >> Maybe.map ctx.dateFormatShort)
source : ItemTemplate
source =
ItemTemplate .source
from .source
folder : ItemTemplate
folder =
ItemTemplate (.folder >> getName)
from (.folder >> getName)
corrOrg : ItemTemplate
corrOrg =
ItemTemplate (.corrOrg >> getName)
from (.corrOrg >> getName)
corrPerson : ItemTemplate
corrPerson =
ItemTemplate (.corrPerson >> getName)
from (.corrPerson >> getName)
correspondent : ItemTemplate
@ -208,12 +224,12 @@ correspondent =
concPerson : ItemTemplate
concPerson =
ItemTemplate (.concPerson >> getName)
from (.concPerson >> getName)
concEquip : ItemTemplate
concEquip =
ItemTemplate (.concEquipment >> getName)
from (.concEquipment >> getName)
concerning : ItemTemplate
@ -223,7 +239,7 @@ concerning =
fileCount : ItemTemplate
fileCount =
ItemTemplate (.attachments >> List.length >> String.fromInt)
from (.attachments >> List.length >> String.fromInt)

View File

@ -1,6 +1,8 @@
module Messages.Comp.AttachmentMeta exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -15,6 +17,7 @@ type alias Texts =
, concerningEquipment : String
, itemDate : String
, itemDueDate : String
, formatDateShort : Int -> String
}
@ -31,4 +34,5 @@ gb =
, concerningEquipment = "Concerning Equipment"
, itemDate = "Item Date"
, itemDueDate = "Item Due Date"
, formatDateShort = DF.formatDateShort Messages.UiLanguage.English
}

View File

@ -1,5 +1,8 @@
module Messages.Comp.CalEventInput exposing (Texts, gb)
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
{ weekday : String
@ -11,6 +14,7 @@ type alias Texts =
, error : String
, schedule : String
, next : String
, formatDateTime : Int -> String
}
@ -25,4 +29,5 @@ gb =
, error = "Error"
, schedule = "Schedule"
, next = "Next"
, formatDateTime = DF.formatDateTimeLong Messages.UiLanguage.English
}

View File

@ -1,6 +1,8 @@
module Messages.Comp.CustomFieldTable exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -8,6 +10,7 @@ type alias Texts =
, nameLabel : String
, format : String
, usageCount : String
, formatDateShort : Int -> String
}
@ -17,4 +20,5 @@ gb =
, nameLabel = "Name/Label"
, format = "Format"
, usageCount = "#Usage"
, formatDateShort = DF.formatDateShort Messages.UiLanguage.English
}

View File

@ -1,11 +1,14 @@
module Messages.Comp.FolderTable exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
{ basics : Messages.Basics.Texts
, memberCount : String
, formatDateShort : Int -> String
}
@ -13,4 +16,5 @@ gb : Texts
gb =
{ basics = Messages.Basics.gb
, memberCount = "#Member"
, formatDateShort = DF.formatDateShort Messages.UiLanguage.English
}

View File

@ -1,6 +1,10 @@
module Messages.Comp.ItemCard exposing (Texts, gb)
import Data.Direction exposing (Direction)
import Messages.Basics
import Messages.Data.Direction
import Messages.DateFormat
import Messages.UiLanguage
type alias Texts =
@ -10,6 +14,9 @@ type alias Texts =
, openAttachmentFile : String
, gotoDetail : String
, cycleAttachments : String
, formatDateLong : Int -> String
, formatDateShort : Int -> String
, directionLabel : Direction -> String
}
@ -21,4 +28,7 @@ gb =
, openAttachmentFile = "Open attachment file"
, gotoDetail = "Go to detail view"
, cycleAttachments = "Cycle attachments"
, formatDateLong = Messages.DateFormat.formatDateLong Messages.UiLanguage.English
, formatDateShort = Messages.DateFormat.formatDateShort Messages.UiLanguage.English
, directionLabel = Messages.Data.Direction.gb
}

View File

@ -7,6 +7,8 @@ import Messages.Comp.ItemDetail.Notes
import Messages.Comp.ItemDetail.SingleAttachment
import Messages.Comp.ItemMail
import Messages.Comp.SentMails
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -34,6 +36,7 @@ type alias Texts =
, createdOn : String
, lastUpdateOn : String
, sendingMailNow : String
, formatDateTime : Int -> String
}
@ -63,4 +66,5 @@ gb =
, createdOn = "Created on"
, lastUpdateOn = "Last update on"
, sendingMailNow = "Sending e-mail"
, formatDateTime = DF.formatDateTimeLong Messages.UiLanguage.English
}

View File

@ -2,6 +2,8 @@ module Messages.Comp.ItemDetail.EditForm exposing (Texts, gb)
import Messages.Basics
import Messages.Comp.CustomFieldMultiInput
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -21,6 +23,7 @@ type alias Texts =
, addNewEquipment : String
, editEquipment : String
, suggestions : String
, formatDate : Int -> String
}
@ -47,4 +50,5 @@ item visible. This message will disappear then.
, addNewEquipment = "Add new equipment"
, editEquipment = "Edit equipment"
, suggestions = "Suggestions"
, formatDate = DF.formatDateLong Messages.UiLanguage.English
}

View File

@ -1,6 +1,8 @@
module Messages.Comp.ItemDetail.ItemInfoHeader exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -9,6 +11,7 @@ type alias Texts =
, dueDate : String
, source : String
, new : String
, formatDate : Int -> String
}
@ -19,4 +22,5 @@ gb =
, dueDate = "Due Date"
, source = "Source"
, new = "New"
, formatDate = DF.formatDateLong Messages.UiLanguage.English
}

View File

@ -1,5 +1,8 @@
module Messages.Comp.SentMails exposing (Texts, gb)
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
{ from : String
@ -8,6 +11,7 @@ type alias Texts =
, subject : String
, sent : String
, sender : String
, formatDateTime : Int -> String
}
@ -19,4 +23,5 @@ gb =
, subject = "Subject"
, sent = "Sent"
, sender = "Sender"
, formatDateTime = DF.formatDateTimeLong Messages.UiLanguage.English
}

View File

@ -1,6 +1,8 @@
module Messages.Comp.UserTable exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -10,6 +12,7 @@ type alias Texts =
, email : String
, logins : String
, lastLogin : String
, formatDateTime : Int -> String
}
@ -21,4 +24,5 @@ gb =
, email = "E-Mail"
, logins = "Logins"
, lastLogin = "Last Login"
, formatDateTime = DF.formatDateTimeLong Messages.UiLanguage.English
}

View File

@ -0,0 +1,13 @@
module Messages.Data.Direction exposing (gb)
import Data.Direction exposing (Direction(..))
gb : Direction -> String
gb dir =
case dir of
Incoming ->
"Incoming"
Outgoing ->
"Outgoing"

View File

@ -0,0 +1,433 @@
module Messages.DateFormat exposing
( format
, formatDateLong
, formatDateShort
, formatDateTimeLong
)
import DateFormat exposing (Token)
import DateFormat.Language as DL
import Messages.UiLanguage exposing (UiLanguage(..))
import Time
exposing
( Month(..)
, Weekday(..)
)
type alias DateTimeMsg =
{ dateLong : List Token
, dateShort : List Token
, dateTimeLong : List Token
, dateTimeShort : List Token
, lang : DL.Language
}
get : UiLanguage -> DateTimeMsg
get lang =
case lang of
English ->
gb
format : UiLanguage -> (DateTimeMsg -> List Token) -> Int -> String
format lang pattern millis =
let
msg =
get lang
fmt =
DateFormat.formatWithLanguage msg.lang (pattern msg)
in
fmt Time.utc (Time.millisToPosix millis)
formatDateTimeLong : UiLanguage -> Int -> String
formatDateTimeLong lang millis =
format lang .dateTimeLong millis
formatDateLong : UiLanguage -> Int -> String
formatDateLong lang millis =
format lang .dateLong millis
formatDateShort : UiLanguage -> Int -> String
formatDateShort lang millis =
format lang .dateShort millis
--- Language Definitions
gb : DateTimeMsg
gb =
{ dateLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ", "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.dayOfMonthSuffix
, DateFormat.text ", "
, DateFormat.yearNumber
]
, dateShort =
[ DateFormat.yearNumber
, DateFormat.text "/"
, DateFormat.monthFixed
, DateFormat.text "/"
, DateFormat.dayOfMonthFixed
]
, dateTimeLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ", "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.dayOfMonthSuffix
, DateFormat.text ", "
, DateFormat.yearNumber
, DateFormat.text ", "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, dateTimeShort =
[ DateFormat.yearNumber
, DateFormat.text "/"
, DateFormat.monthFixed
, DateFormat.text "/"
, DateFormat.dayOfMonthFixed
, DateFormat.text " "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, lang = DL.english
}
de : DateTimeMsg
de =
{ dateLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ", "
, DateFormat.dayOfMonthSuffix
, DateFormat.text " "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.yearNumber
]
, dateShort =
[ DateFormat.dayOfMonthFixed
, DateFormat.text "."
, DateFormat.monthFixed
, DateFormat.text "."
, DateFormat.yearNumber
]
, dateTimeLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ". "
, DateFormat.dayOfMonthSuffix
, DateFormat.text " "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.yearNumber
, DateFormat.text ", "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, dateTimeShort =
[ DateFormat.dayOfMonthFixed
, DateFormat.text "."
, DateFormat.monthFixed
, DateFormat.text "."
, DateFormat.yearNumber
, DateFormat.text " "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, lang = german
}
{-| French date formats; must be reviewed!
-}
fr : DateTimeMsg
fr =
{ dateLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ", "
, DateFormat.dayOfMonthSuffix
, DateFormat.text " "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.yearNumber
]
, dateShort =
[ DateFormat.dayOfMonthFixed
, DateFormat.text "."
, DateFormat.monthFixed
, DateFormat.text "."
, DateFormat.yearNumber
]
, dateTimeLong =
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ". "
, DateFormat.dayOfMonthSuffix
, DateFormat.text " "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.yearNumber
, DateFormat.text ", "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, dateTimeShort =
[ DateFormat.dayOfMonthFixed
, DateFormat.text "."
, DateFormat.monthFixed
, DateFormat.text "."
, DateFormat.yearNumber
, DateFormat.text " "
, DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
, lang = french
}
--- Languages for the DateFormat module
-- French
{-| The French language!
-}
french : DL.Language
french =
DL.Language
toFrenchMonthName
toFrenchMonthAbbreviation
toFrenchWeekdayName
(toFrenchWeekdayName >> String.left 3)
toEnglishAmPm
toFrenchOrdinalSuffix
toFrenchMonthName : Month -> String
toFrenchMonthName month =
case month of
Jan ->
"janvier"
Feb ->
"février"
Mar ->
"mars"
Apr ->
"avril"
May ->
"mai"
Jun ->
"juin"
Jul ->
"juillet"
Aug ->
"août"
Sep ->
"septembre"
Oct ->
"octobre"
Nov ->
"novembre"
Dec ->
"décembre"
toFrenchMonthAbbreviation : Month -> String
toFrenchMonthAbbreviation month =
case month of
Jan ->
"janv"
Feb ->
"févr"
Mar ->
"mars"
Apr ->
"avr"
May ->
"mai"
Jun ->
"juin"
Jul ->
"juil"
Aug ->
"août"
Sep ->
"sept"
Oct ->
"oct"
Nov ->
"nov"
Dec ->
"déc"
toFrenchWeekdayName : Weekday -> String
toFrenchWeekdayName weekday =
case weekday of
Mon ->
"lundi"
Tue ->
"mardi"
Wed ->
"mercredi"
Thu ->
"jeudi"
Fri ->
"vendredi"
Sat ->
"samedi"
Sun ->
"dimanche"
toFrenchOrdinalSuffix : Int -> String
toFrenchOrdinalSuffix n =
if n == 1 then
"er"
else
""
-- German
{-| The German language!
-}
german : DL.Language
german =
let
withDot str =
str ++ "."
in
DL.Language
toGermanMonthName
(toGermanMonthName >> String.left 3 >> withDot)
toGermanWeekdayName
(toGermanWeekdayName >> String.left 2 >> withDot)
toEnglishAmPm
(\_ -> ".")
toGermanMonthName : Month -> String
toGermanMonthName month =
case month of
Jan ->
"Januar"
Feb ->
"Februar"
Mar ->
"März"
Apr ->
"April"
May ->
"Mai"
Jun ->
"Juni"
Jul ->
"Juli"
Aug ->
"August"
Sep ->
"September"
Oct ->
"Oktober"
Nov ->
"November"
Dec ->
"Dezember"
toGermanWeekdayName : Weekday -> String
toGermanWeekdayName weekday =
case weekday of
Mon ->
"Montag"
Tue ->
"Dienstag"
Wed ->
"Mittwoch"
Thu ->
"Donnerstag"
Fri ->
"Freitag"
Sat ->
"Samstag"
Sun ->
"Sonntag"
--- Copy from DateFormat.Language
toEnglishAmPm : Int -> String
toEnglishAmPm hour =
if hour > 11 then
"pm"
else
"am"

View File

@ -1,6 +1,8 @@
module Messages.Page.Queue exposing (Texts, gb)
import Messages.Basics
import Messages.DateFormat as DF
import Messages.UiLanguage
type alias Texts =
@ -23,6 +25,7 @@ type alias Texts =
, retries : String
, changePriority : String
, prio : String
, formatDateTime : Int -> String
}
@ -47,4 +50,5 @@ gb =
, retries = "Retries"
, changePriority = "Change priority of this job"
, prio = "Prio"
, formatDateTime = DF.formatDateTimeLong Messages.UiLanguage.English
}

View File

@ -13,7 +13,7 @@ import Html.Events exposing (onClick)
import Messages.Page.Queue exposing (Texts)
import Page.Queue.Data exposing (..)
import Styles as S
import Util.Time exposing (formatDateTime, formatIsoDateTime)
import Util.Time exposing (formatIsoDateTime)
viewSidebar : Texts -> Bool -> Flags -> UiSettings -> Model -> Html Msg
@ -397,7 +397,7 @@ renderInfoCard texts model job =
, div [ class "flex flex-row space-x-2 items-center flex-wrap" ]
[ div [ class "flex flex-row justify-start " ]
[ div [ class "text-xs font-semibold" ]
[ Util.Time.formatDateTime job.submitted |> text
[ texts.formatDateTime job.submitted |> text
]
]
, div [ class "flex-grow flex flex-row justify-end space-x-2 flex-wrap" ]

View File

@ -1,47 +1,9 @@
module Util.Time exposing
( formatDate
, formatDateShort
, formatDateTime
, formatIsoDateTime
)
module Util.Time exposing (formatIsoDateTime)
import DateFormat
import Time exposing (Posix, Zone, utc)
dateFormatter : Zone -> Posix -> String
dateFormatter =
DateFormat.format
[ DateFormat.dayOfWeekNameAbbreviated
, DateFormat.text ", "
, DateFormat.monthNameFull
, DateFormat.text " "
, DateFormat.dayOfMonthSuffix
, DateFormat.text ", "
, DateFormat.yearNumber
]
dateFormatterShort : Zone -> Posix -> String
dateFormatterShort =
DateFormat.format
[ DateFormat.yearNumber
, DateFormat.text "/"
, DateFormat.monthFixed
, DateFormat.text "/"
, DateFormat.dayOfMonthFixed
]
timeFormatter : Zone -> Posix -> String
timeFormatter =
DateFormat.format
[ DateFormat.hourMilitaryNumber
, DateFormat.text ":"
, DateFormat.minuteFixed
]
isoDateTimeFormatter : Zone -> Posix -> String
isoDateTimeFormatter =
DateFormat.format
@ -64,44 +26,7 @@ timeZone =
utc
{- Format millis into "Wed, 10. Jan 2018, 18:57" -}
formatDateTime : Int -> String
formatDateTime millis =
formatDate millis ++ ", " ++ formatTime millis
formatIsoDateTime : Int -> String
formatIsoDateTime millis =
Time.millisToPosix millis
|> isoDateTimeFormatter timeZone
{- Format millis into "18:57". The current time (not the duration of
the millis).
-}
formatTime : Int -> String
formatTime millis =
Time.millisToPosix millis
|> timeFormatter timeZone
{- Format millis into "Wed, 10. Jan 2018" -}
formatDate : Int -> String
formatDate millis =
Time.millisToPosix millis
|> dateFormatter timeZone
formatDateShort : Int -> String
formatDateShort millis =
Time.millisToPosix millis
|> dateFormatterShort timeZone