Skip to content

Instantly share code, notes, and snippets.

@mmynsted

mmynsted/snip.hs Secret

Created December 1, 2020 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmynsted/2df78282ccd2ec4ac026b85e390d2d73 to your computer and use it in GitHub Desktop.
Save mmynsted/2df78282ccd2ec4ac026b85e390d2d73 to your computer and use it in GitHub Desktop.
getUpdatedUTC :: MonadMetadata m => TimeLocale -> Identifier -> m Clock.UTCTime
getUpdatedUTC locale id' = do
metadata <- getMetadata id'
let tryField k fmt = lookupString k metadata >>= parseTime' fmt
maybe empty' pure $ msum [tryField "updated" fmt | fmt <- formats]
where
empty' = fail $ "Hakyll.Web.Template.Context.getUpdatedUTC: " <> "could not parse time for " <> show id'
parseTime' = parseTimeM True locale
formats =
[ "%a, %d %b %Y %H:%M:%S %Z"
, "%Y-%m-%dT%H:%M:%S%Z"
, "%Y-%m-%d %H:%M:%S%Z"
, "%Y-%m-%d"
, "%B %e, %Y %l:%M %p"
, "%B %e, %Y"
, "%b %d, %Y"
]
@mmynsted
Copy link
Author

mmynsted commented Dec 1, 2020

    • Could not deduce (MonadFail m) arising from a use of ‘fail’
      from the context: MonadMetadata m
        bound by the type signature for:
                   getUpdatedUTC :: forall (m :: * -> *).
                                    MonadMetadata m =>
                                    TimeLocale -> Identifier -> m UTCTime
        at src/site.hs:534:1-79
      Possible fix:
        add (MonadFail m) to the context of
          the inferred type of empty' :: m a
          or the type signature for:
               getUpdatedUTC :: forall (m :: * -> *).
                                MonadMetadata m =>
                                TimeLocale -> Identifier -> m UTCTime
    • In the expression:
        fail
          $ "Hakyll.Web.Template.Context.getUpdatedUTC: "
              ++ "could not parse time for " ++ show id'
      In an equation for ‘empty'’:
          empty'
            = fail
                $ "Hakyll.Web.Template.Context.getUpdatedUTC: "
                    ++ "could not parse time for " ++ show id'
      In an equation for ‘getUpdatedUTC’:
          getUpdatedUTC locale id'
            = do metadata <- getMetadata id'
                 let tryField k fmt = ...
                 maybe empty' return
                   $ msum [tryField "updated" fmt | fmt <- formats]
            where
                empty'
                  = fail
                      $ "Hakyll.Web.Template.Context.getUpdatedUTC: "
                          ++ "could not parse time for " ++ show id'
                parseTime' = parseTimeM True locale
                formats = ["%a, %d %b %Y %H:%M:%S %Z", ....]
    |
540 |     empty'     = fail $ "Hakyll.Web.Template.Context.getUpdatedUTC: " ++ "could not parse time for " ++ show id'
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment