From: PHO Date: Sun, 4 Dec 2011 08:32:19 +0000 (+0900) Subject: Delete Data.Time.Asctime.Internal X-Git-Tag: RELEASE-0.3~1^2~13 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=d62f138;p=time-http.git Delete Data.Time.Asctime.Internal Ditz-issue: 0a3272772c73cf31486eb2b6691fa38232d3c4c5 --- diff --git a/Data/Time/Asctime.hs b/Data/Time/Asctime.hs index 0814e45..39d9961 100644 --- a/Data/Time/Asctime.hs +++ b/Data/Time/Asctime.hs @@ -1,5 +1,6 @@ {-# LANGUAGE - UnicodeSyntax + OverloadedStrings + , UnicodeSyntax #-} -- |This module provides functions for ANSI C's asctime() format. -- @@ -31,11 +32,13 @@ module Data.Time.Asctime , asctime ) where -import Data.Ascii (Ascii) +import Data.Ascii (Ascii, AsciiBuilder) import qualified Data.Ascii as A -import qualified Data.Attoparsec.Char8 as P +import Data.Attoparsec.Char8 +import Data.Monoid.Unicode import Data.Time -import Data.Time.Asctime.Internal +import Data.Time.Calendar.WeekDate +import Data.Time.HTTP.Common import Prelude.Unicode -- |Convert a 'LocalTime' to ANSI C's @asctime()@ string. @@ -45,8 +48,51 @@ toAscii = A.fromAsciiBuilder ∘ toAsciiBuilder -- |Parse an ANSI C's @asctime()@ string. When the string can't be -- parsed, it returns @'Left' err@. fromAscii ∷ Ascii → Either String LocalTime -fromAscii = P.parseOnly p ∘ A.toByteString +fromAscii = parseOnly p ∘ A.toByteString where p = do zt ← asctime - P.endOfInput + endOfInput return zt + +-- |Parse an ANSI C's @asctime()@ string. +asctime ∷ Parser LocalTime +asctime = do weekDay ← shortWeekDayNameP + _ ← char ' ' + month ← shortMonthNameP + _ ← char ' ' + day ← read2' + _ ← char ' ' + hour ← read2 + _ ← char ':' + minute ← read2 + _ ← char ':' + second ← read2 + _ ← char ' ' + year ← read4 + + gregDay ← assertGregorianDateIsGood year month day + _ ← assertWeekDayIsGood weekDay gregDay + tod ← assertTimeOfDayIsGood hour minute second + + return (LocalTime gregDay tod) + +-- |Convert a 'LocalTime' to ANSI C's @asctime()@ string. +toAsciiBuilder ∷ LocalTime → AsciiBuilder +toAsciiBuilder localTime + = let (year, month, day) = toGregorian (localDay localTime) + (_, _, week) = toWeekDate (localDay localTime) + timeOfDay = localTimeOfDay localTime + in + shortWeekDayName week + ⊕ A.toAsciiBuilder " " + ⊕ shortMonthName month + ⊕ A.toAsciiBuilder " " + ⊕ show2' day + ⊕ A.toAsciiBuilder " " + ⊕ show2 (todHour timeOfDay) + ⊕ A.toAsciiBuilder ":" + ⊕ show2 (todMin timeOfDay) + ⊕ A.toAsciiBuilder ":" + ⊕ show2 (floor (todSec timeOfDay) ∷ Int) + ⊕ A.toAsciiBuilder " " + ⊕ show4 year diff --git a/Data/Time/Asctime/Internal.hs b/Data/Time/Asctime/Internal.hs deleted file mode 100644 index 1681fc0..0000000 --- a/Data/Time/Asctime/Internal.hs +++ /dev/null @@ -1,61 +0,0 @@ -{-# LANGUAGE - OverloadedStrings - , UnicodeSyntax - #-} --- |Internal functions for "Data.Time.Asctime". -module Data.Time.Asctime.Internal - ( asctime - , toAsciiBuilder - ) - where -import Data.Ascii (AsciiBuilder) -import qualified Data.Ascii as A -import Data.Attoparsec.Char8 -import Data.Monoid.Unicode -import Data.Time -import Data.Time.Calendar.WeekDate -import Data.Time.HTTP.Common - --- |Parse an ANSI C's @asctime()@ string. -asctime ∷ Parser LocalTime -asctime = do weekDay ← shortWeekDayNameP - _ ← char ' ' - month ← shortMonthNameP - _ ← char ' ' - day ← read2' - _ ← char ' ' - hour ← read2 - _ ← char ':' - minute ← read2 - _ ← char ':' - second ← read2 - _ ← char ' ' - year ← read4 - - gregDay ← assertGregorianDateIsGood year month day - _ ← assertWeekDayIsGood weekDay gregDay - tod ← assertTimeOfDayIsGood hour minute second - - return (LocalTime gregDay tod) - --- |Convert a 'LocalTime' to ANSI C's @asctime()@ string. -toAsciiBuilder ∷ LocalTime → AsciiBuilder -toAsciiBuilder localTime - = let (year, month, day) = toGregorian (localDay localTime) - (_, _, week) = toWeekDate (localDay localTime) - timeOfDay = localTimeOfDay localTime - in - shortWeekDayName week - ⊕ A.toAsciiBuilder " " - ⊕ shortMonthName month - ⊕ A.toAsciiBuilder " " - ⊕ show2' day - ⊕ A.toAsciiBuilder " " - ⊕ show2 (todHour timeOfDay) - ⊕ A.toAsciiBuilder ":" - ⊕ show2 (todMin timeOfDay) - ⊕ A.toAsciiBuilder ":" - ⊕ show2 (floor (todSec timeOfDay) ∷ Int) - ⊕ A.toAsciiBuilder " " - ⊕ show4 year - diff --git a/Data/Time/HTTP/Internal.hs b/Data/Time/HTTP/Internal.hs index e945670..aada8bd 100644 --- a/Data/Time/HTTP/Internal.hs +++ b/Data/Time/HTTP/Internal.hs @@ -13,7 +13,7 @@ import Data.Attoparsec.Char8 import Data.Time import qualified Data.Time.RFC1123.Internal as RFC1123 import qualified Data.Time.RFC733.Internal as RFC733 -import qualified Data.Time.Asctime.Internal as Asctime +import qualified Data.Time.Asctime as Asctime import Prelude.Unicode -- |Parse a date and time string in any formats allowed by HTTP\/1.1 diff --git a/bugs/issue-0a3272772c73cf31486eb2b6691fa38232d3c4c5.yaml b/bugs/issue-0a3272772c73cf31486eb2b6691fa38232d3c4c5.yaml index 8792f58..f7be4fa 100644 --- a/bugs/issue-0a3272772c73cf31486eb2b6691fa38232d3c4c5.yaml +++ b/bugs/issue-0a3272772c73cf31486eb2b6691fa38232d3c4c5.yaml @@ -5,7 +5,7 @@ type: :task component: time-http release: time-http-0.3 reporter: PHO -status: :unstarted +status: :in_progress disposition: creation_time: 2011-12-01 01:58:17.790699 Z references: [] @@ -16,4 +16,8 @@ log_events: - PHO - created - "" +- - 2011-12-01 23:15:25.041203 Z + - PHO + - changed status from unstarted to in_progress + - "" git_branch: diff --git a/time-http.cabal b/time-http.cabal index d8c1c2a..eae4ffa 100644 --- a/time-http.cabal +++ b/time-http.cabal @@ -33,7 +33,6 @@ Library Data.Time.RFC822 Other-modules: - Data.Time.Asctime.Internal Data.Time.HTTP.Common Data.Time.HTTP.Internal Data.Time.RFC1123.Internal @@ -47,6 +46,8 @@ Library blaze-textual == 0.2.*, base == 4.*, base-unicode-symbols == 0.2.*, + convertible-text == 0.3.*, + tagged == 0.2.*, time == 1.2.* Default-Language: @@ -67,6 +68,8 @@ Test-Suite test-time-http blaze-textual == 0.2.*, base == 4.*, base-unicode-symbols == 0.2.*, + convertible-text == 0.3.*, + tagged == 0.2.*, time == 1.2.* GHC-Options: -Wall -fno-warn-orphans