[Haskell-cafe] Re: AW: Example for formatted show in HStringTemplate
John MacFarlane
fiddlosopher at gmail.com
Tue Jul 14 12:55:10 EDT 2009
Torsten,
I'm not quite sure what you're asking -- but this simple example seems
to work fine:
Prelude Text.StringTemplate> let (a :: StringTemplate String) = newSTMP "$day;format=\"%d.%b.%Y\"$"
Prelude Text.StringTemplate Data.Time> render $ setAttribute "day" (ModifiedJulianDay 234) a
"09.Jul.1859"
John
+++ Kemps-Benedix Torsten [Jul 14 09 12:20 ]:
> John,
>
> thanks for your answer, but HStringtemplate has instance definitions for Date.Time.Day. The question is more on the script side: How do I have to write the ST calls with ";format=" embedded in HTML?
>
> regards,
>
> Torsten
>
>
>
> -----Ursprüngliche Nachricht-----
> Von: John MacFarlane [mailto:fiddlosopher at gmail.com]
> Gesendet: Dienstag, 14. Juli 2009 08:20
> An: Kemps-Benedix Torsten
> Cc: HAppS at googlegroups.com; haskell-cafe at haskell.org
> Betreff: Re: Example for formatted show in HStringTemplate
>
> +++ Kemps-Benedix Torsten [Jul 13 09 23:56 ]:
> > Hello,
> >
> > is there a working example of how to use the format clause with HStringTemplate, e.g. for Data.Time.Day? I think, if there is a parameter $day$, a reasonable template might contain e.g.:
> >
> > $day;format="%d.%b.%Y"$
> >
> > But I only get "toModifiedJulianDay: [54960]" as the result which corresponds to the unformatted show.
>
> You probably need to define a StringTemplateShows instance for
> Data.Time.Day, and then use stShowsToSE to define a ToSElem instance.
> Something like
>
> instance StringTemplateShows Day
> where stringTemplateFormattedShow formatString = formatTime defaultTimeLocale formatString
> {- or whatever -- I'm not sure what the correct time-formatting function is -}
>
> instance ToSElem Day
> where toSElem = stShowsToSE
>
> John
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list