]> gitweb @ CieloNegro.org - Lucu.git/blobdiff - Network/HTTP/Lucu/RFC1123DateTime.hs
Optimized as possible as I can.
[Lucu.git] / Network / HTTP / Lucu / RFC1123DateTime.hs
index 354286fb1d8da0b262d2d1209f23c421bc971b24..3be2dd414b0bd67ba39166a6d9d95c2395977c16 100644 (file)
@@ -11,31 +11,45 @@ module Network.HTTP.Lucu.RFC1123DateTime
 import           Control.Monad
 import qualified Data.ByteString.Lazy.Char8 as B
 import           Data.ByteString.Lazy.Char8 (ByteString)
+import           Network.HTTP.Lucu.Format
 import           Network.HTTP.Lucu.Parser
 import           System.Time
 import           System.Locale
-import           Text.Printf
 
-month = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
-week  = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
+month :: [String]
+month =  ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
+
+week :: [String]
+week =  ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
 
 -- |Format a @CalendarTime@ to RFC 1123 Date and Time string.
 formatRFC1123DateTime :: CalendarTime -> String
 formatRFC1123DateTime time
-    = printf "%s, %02d %s %04d %02d:%02d:%02d %s"
-      (week     !! fromEnum (ctWDay  time))
-      (ctDay    time)
-      (month    !! fromEnum (ctMonth time))
-      (ctYear   time)
-      (ctHour   time)
-      (ctMin    time)
-      (ctSec    time)
-      (ctTZName time)
+    = time `seq`
+
+      id       (week     !! fromEnum (ctWDay  time))
+      ++ ", " ++
+      fmtDec 2 (ctDay    time)
+      ++ " "  ++
+      id       (month    !! fromEnum (ctMonth time))
+      ++ " "  ++
+      fmtDec 4 (ctYear   time)
+      ++ " "  ++
+      fmtDec 2 (ctHour   time)
+      ++ ":"  ++
+      fmtDec 2 (ctMin    time)
+      ++ ":"  ++
+      fmtDec 2 (ctSec    time)
+      ++ ":"  ++
+      id       (ctTZName time)
+      
 
 -- |Format a @ClockTime@ to HTTP Date and Time. Time zone will be
 -- always UTC but prints as GMT.
 formatHTTPDateTime :: ClockTime -> String
-formatHTTPDateTime = formatRFC1123DateTime . (\cal -> cal { ctTZName = "GMT" }) . toUTCTime
+formatHTTPDateTime time
+    = time `seq`
+      formatRFC1123DateTime $! (\cal -> cal { ctTZName = "GMT" }) $! toUTCTime time
 
 -- |Parse an HTTP Date and Time.
 --