aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 15:54:05 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 15:54:34 -0800
commit3a0b3df00701eef2a0549487e08fa4d63c3ab8d9 (patch)
treed95457d3aa1253158a36223752f8f89948b24a97 /src/Text/Pandoc/Shared.hs
parent98e5b6170383882f948c53a461059ac213d9fab3 (diff)
downloadpandoc-3a0b3df00701eef2a0549487e08fa4d63c3ab8d9.tar.gz
Put date in YYYY-MM-DD format if possible for HTML, docx metadata.
Added normalizeDate to Text.Pandoc.Shared.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 952218176..7e63c2161 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -46,6 +46,8 @@ module Text.Pandoc.Shared (
toRomanNumeral,
escapeURI,
tabFilter,
+ -- * Date/time
+ normalizeDate,
-- * Pandoc block and inline list processing
orderedListMarkers,
normalizeSpaces,
@@ -81,9 +83,12 @@ import System.Directory
import System.FilePath ( (</>) )
import Data.Generics (Typeable, Data)
import qualified Control.Monad.State as S
+import Control.Monad (msum)
import Paths_pandoc (getDataFileName)
import Text.Pandoc.Highlighting (Style, pygments)
import Text.Pandoc.Pretty (charWidth)
+import System.Locale (defaultTimeLocale)
+import Data.Time
--
-- List processing
@@ -218,6 +223,18 @@ tabFilter tabStop =
in go tabStop
--
+-- Date/time
+--
+
+-- | Parse a date and convert (if possible) to "YYYY-MM-DD" format.
+normalizeDate :: String -> Maybe String
+normalizeDate s = fmap (formatTime defaultTimeLocale "%F")
+ (msum $ map (\fs -> parsetimeWith fs s) formats :: Maybe Day)
+ where parsetimeWith = parseTime defaultTimeLocale
+ formats = ["%x","%m/%d/%Y", "%D","%F", "%d %b %Y",
+ "%d %B %Y", "%b. %d, %Y", "%B %d, %Y"]
+
+--
-- Pandoc block and inline list processing
--