Skip to content

Commit

Permalink
[WIP] Fix #11: improve parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Apr 26, 2023
1 parent 586b692 commit 63fc5fa
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/Foliage/Meta.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Data.Maybe (fromMaybe)
import Data.Ord (Down (Down))
import Data.Text (Text)
import Data.Text qualified as T
import Data.Time.LocalTime (utc, utcToZonedTime, zonedTimeToUTC)
import Data.Time.Format (defaultTimeLocale, formatTime, parseTimeM)
import Development.Shake.Classes (Binary, Hashable, NFData)
import Distribution.Aeson ()
import Distribution.Parsec (simpleParsec)
Expand Down Expand Up @@ -214,7 +214,12 @@ revisionMetaCodec =
.= revisionNumber

timeCodec :: Toml.Key -> TomlCodec UTCTime
timeCodec key = Toml.dimap (utcToZonedTime utc) zonedTimeToUTC $ Toml.zonedTime key
timeCodec = Toml.textBy showTime parseTime
where
showTime = T.pack . formatTime defaultTimeLocale "%FT%T%QZ"
parseTime t = case parseTimeM True defaultTimeLocale "%FT%T%QZ" (T.unpack $ T.dropAround (`elem` ['\'', '\"']) t) of
Nothing -> Left $ "Invalid timestamp format, expected 'YYYY-MM-DDTHH:MM:SSZ': " <> t
Just time -> Right time

latestRevisionNumber :: PackageVersionSpec -> Maybe Int
latestRevisionNumber sm =
Expand Down

0 comments on commit 63fc5fa

Please sign in to comment.