packages feed

timerep (empty) → 1.0.0

raw patch · 5 files changed

+238/−0 lines, 5 filesdep +basedep +old-localedep +timesetup-changed

Dependencies added: base, old-locale, time

Files

+ Data/Time/RFC2822.hs view
@@ -0,0 +1,99 @@+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}+-- |                                                                               +-- Module      : Data.Time.RFC2822+-- Copyright   : (c) 2011 Hugo Daniel Gomes+--+-- License     : BSD-style+-- Maintainer  : mr.hugo.gomes@gmail.com+-- Stability   : experimental+-- Portability : GHC+--+-- Support for reading and displaying time in the format specified by +-- the RFC2822 <http://www.ietf.org/rfc/rfc2822.txt> section 3.3+--+-- Example of usage:+-- >+-- > import Data.Time.LocalTime+-- >+-- > showTime :: IO String+-- > showTime = getZonedTime >>= return . showRFC2822+-- >+-- > example1 = "Fri, 21 Nov 1997 09:55:06 -0600"+-- > example2 = "Tue, 15 Nov 1994 12:45:26 GMT"+-- > example3 = "Tue, 1 Jul 2003 10:52:37 +0200"+-- > example4 = "Thu, 13 Feb 1969 23:32:54 -0330"+-- > example5 = "Mon, 24 Nov 1997 14:22:01 -0800"+-- > example6 = "Thu,          13\n     Feb\n  1969\n        23:32\n     -0330"+-- > example7 = "Thu,          13\n     Feb\n  1969\n        23:32\n     -0330 (Newfoundland Time)"+-- > example8 = "24 Nov 1997 14:22:01 -0800"+-- > examples = [example1,example2,example3,example4,example5,example6,example7,example8]+-- >+-- > readAll = map readRFC2822 examples++module Data.Time.RFC2822 (+    -- * Basic type class+    -- $basic+    RFC2822(showRFC2822, readRFC2822)+) where++import Data.Time.Format+import Data.Time.LocalTime+import Data.Time.Calendar+import Data.Maybe +import System.Locale++test1  = "Fri, 21 Nov 1997 09:55:06 -0600"+test2  = "Tue, 15 Nov 1994 12:45:26 GMT"+test3  = "Tue, 1 Jul 2003 10:52:37 +0200"+test4  = "Thu, 13 Feb 1969 23:32:54 -0330"+test5  = "Mon, 24 Nov 1997 14:22:01 -0800"+test6  = "Thu,          13\n     Feb\n  1969\n        23:32\n     -0330"+test7  = "Thu,          13\n     Feb\n  1969\n        23:32\n     -0330 (Newfoundland Time)"+test8  = "24 Nov 1997 14:22:01 -0800"+test9  = "15 Nov 1994 12:45:26 GMT"+test10 = "Mon,24 Nov 1997 14:22:01 -0800"+test11 = "Thu,\t13\n     Feb\n  1969\n        23:32\n     -0330 (Newfoundland Time)"+tests = [test1, test2, test3, test4, test5, test6, test7, test8, test9, test10+        , test11]+testParse = length (catMaybes (map readRFC2822 tests)) == length tests++-- ----------------------------------------------------------------------------+-- The RFC2822 class definition++-- | This class is here to allow future support for other data types +-- like Data.Text or Data.ByteString if that becomes necessary+class RFC2822 a where+  showRFC2822 :: ZonedTime -> a+  readRFC2822 :: a -> Maybe ZonedTime++-- | For now there is only an instance for the String data type+instance RFC2822 String where+  showRFC2822 zt@(ZonedTime lt z) = +    formatTime defaultTimeLocale "%a, %e %b %Y %T" zt ++ printZone+    where+      timeZoneStr = timeZoneOffsetString z+      printZone = if timeZoneStr == timeZoneOffsetString utc+                    then " GMT"+                    else " " ++ timeZoneStr++  readRFC2822 t = foldr (tryP t') Nothing [ p "%a, %e %b %Y %T GMT"+                                          , p "%a, %e %b %Y %T %z"+                                          , p "%e %b %Y %T GMT"+                                          , p "%e %b %Y %T %z"+                                          -- , p "%FT%T%QZ"+                                          ]+    where +      p :: String -> String -> Maybe ZonedTime+      p f s = parseTime defaultTimeLocale f s++      tryP :: String -> (String -> Maybe a) -> Maybe a -> Maybe a+      tryP s f acc | isJust acc = acc+                   | otherwise = f s++      -- t' is a trimmed t (currently only \n is trimmed)+      -- TODO: trim other white space characters +      t' :: String+      t' = lines t >>= ("" ++)++showTime :: IO String+showTime = getZonedTime >>= return . showRFC2822
+ Data/Time/RFC3339.hs view
@@ -0,0 +1,82 @@+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}+-- |                                                                               +-- Module      : Data.Time.RFC3339+-- Copyright   : (c) 2011 Hugo Daniel Gomes+--+-- License     : BSD-style+-- Maintainer  : mr.hugo.gomes@gmail.com+-- Stability   : experimental+-- Portability : GHC+--+-- Support for reading and displaying time in the format specified by +-- the RFC3339 <http://www.ietf.org/rfc/rfc3339.txt>+--+-- Example of usage:+-- >+-- > import Data.Time.LocalTime+-- >+-- > showTime :: IO String+-- > showTime = getZonedTime >>= return . showRFC3339+-- >+-- > example1 = "1985-04-12T23:20:50.52Z"+-- > example2 = "1996-12-19T16:39:57-08:00"+-- > example3 = "1990-12-31T23:59:60Z"+-- > example4 = "1990-12-31T15:59:60-08:00"+-- > example5 = "1937-01-01T12:00:27.87+00:20"+-- > examples = [example1,example2,example3,example4,example5]+-- >+-- > readAll = map readRFC3339 examples++module Data.Time.RFC3339 (+    -- * Basic type class+    -- $basic+    RFC3339(showRFC3339, readRFC3339)+) where++import Data.Time.Format+import Data.Time.LocalTime+import Data.Time.Calendar+import Data.Maybe +import System.Locale++test1 = "1985-04-12T23:20:50.52Z"+test2 = "1996-12-19T16:39:57-08:00"+test3 = "1990-12-31T23:59:60Z"+test4 = "1990-12-31T15:59:60-08:00"+test5 = "1937-01-01T12:00:27.87+00:20"+tests = [test1, test2, test3, test4, test5]+testParse = length (catMaybes (map readRFC3339 tests)) == length tests++-- ----------------------------------------------------------------------------+-- The RFC3339 class definition++-- | This class is here to allow future support for other data types +-- like Data.Text or Data.ByteString if that becomes necessary+class RFC3339 a where+  showRFC3339 :: ZonedTime -> a+  readRFC3339 :: a -> Maybe ZonedTime++-- | For now there is only an instance for the String data type+instance RFC3339 String where+  showRFC3339 zt@(ZonedTime lt z) = +    formatTime defaultTimeLocale "%FT%T" zt ++ printZone+    where+      timeZoneStr = timeZoneOffsetString z+      printZone = if timeZoneStr == timeZoneOffsetString utc+                    then "Z"+                    else take 3 timeZoneStr ++ ":" ++ drop 3 timeZoneStr+  readRFC3339 t = foldr (tryP t) Nothing [ p "%FT%TZ"+                                         , p "%FT%T%z"+                                         , p "%FT%T%Q%z"+                                         , p "%FT%T%QZ"+                                         ]+    where +      p :: String -> String -> Maybe ZonedTime+      p f s = parseTime defaultTimeLocale f s++      tryP :: String -> (String -> Maybe a) -> Maybe a -> Maybe a+      tryP s f acc | isJust acc = acc+                   | otherwise = f s++showTime :: IO String+showTime = getZonedTime >>= return . showRFC3339
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2010 Hugo Daniel H. O. Gomes <hugo.gomes@fcsh.unl.pt>++This software is provided 'as-is', without any express or implied+warranty. In no event will the authors be held liable for any damages+arising from the use of this software.++Permission is granted to anyone to use this software for any purpose,+including commercial applications, and to alter it and redistribute it+freely, subject to the following restrictions:++1. The origin of this software must not be misrepresented; you must not+   claim that you wrote the original software. If you use this software+   in a product, an acknowledgment in the product documentation would+   be appreciated but is not required.++2. Altered source versions must be plainly marked as such, and must not+   be misrepresented as being the original software.++3. This notice may not be removed or altered from any source+   distribution.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ timerep.cabal view
@@ -0,0 +1,35 @@+Name:          timerep+Version:       1.0.0+Category:      Web, Time+Synopsis:      Parse and display time according to some RFCs (RFC3339, RFC2822)+Description:   +    .+    Parse and display time according to some RFC's.+    Supported: +    RFC3339 <http://www.ietf.org/rfc/rfc3339.txt>+    RFC2822 <http://www.ietf.org/rfc/rfc2822.txt>+    .+    This package defines a type class to parse and read time representations +    specified in some RFC's.+    Right now there is only support for reading and showing String+    .+Build-type:    Simple+Maintainer:    Hugo Daniel Gomes <mr.hugo.gomes@gmail.com>+Author:        Hugo Daniel Gomes <mr.hugo.gomes@gmail.com>+Copyright:     Hugo Daniel Gomes+Cabal-version: >= 1.6+License:       BSD3+License-file:  LICENSE+source-repository head                                                             +  type:     git                                                                    +  location: git://github.com/HugoDaniel/RFC3339.git++library+  build-depends:+    base < 5, time >= 1.2, old-locale++  exposed-modules:+    Data.Time.RFC3339+    Data.Time.RFC2822++  extensions: TypeSynonymInstances