Skip to content

Commit 3a46d69

Browse files
committed
Add text-iso8601
1 parent 212c324 commit 3a46d69

File tree

14 files changed

+964
-4
lines changed

14 files changed

+964
-4
lines changed

.github/workflows/haskell-ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ jobs:
213213
touch cabal.project
214214
echo "packages: $GITHUB_WORKSPACE/source/." >> cabal.project
215215
echo "packages: $GITHUB_WORKSPACE/source/attoparsec-iso8601" >> cabal.project
216+
echo "packages: $GITHUB_WORKSPACE/source/text-iso8601" >> cabal.project
216217
echo "packages: $GITHUB_WORKSPACE/source/examples" >> cabal.project
217218
echo "packages: $GITHUB_WORKSPACE/source/benchmarks" >> cabal.project
218219
cat cabal.project
@@ -230,6 +231,8 @@ jobs:
230231
echo "PKGDIR_aeson=${PKGDIR_aeson}" >> "$GITHUB_ENV"
231232
PKGDIR_attoparsec_iso8601="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/attoparsec-iso8601-[0-9.]*')"
232233
echo "PKGDIR_attoparsec_iso8601=${PKGDIR_attoparsec_iso8601}" >> "$GITHUB_ENV"
234+
PKGDIR_text_iso8601="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/text-iso8601-[0-9.]*')"
235+
echo "PKGDIR_text_iso8601=${PKGDIR_text_iso8601}" >> "$GITHUB_ENV"
233236
PKGDIR_aeson_examples="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/aeson-examples-[0-9.]*')"
234237
echo "PKGDIR_aeson_examples=${PKGDIR_aeson_examples}" >> "$GITHUB_ENV"
235238
PKGDIR_aeson_benchmarks="$(find "$GITHUB_WORKSPACE/unpacked" -maxdepth 1 -type d -regex '.*/aeson-benchmarks-[0-9.]*')"
@@ -239,20 +242,23 @@ jobs:
239242
touch cabal.project.local
240243
echo "packages: ${PKGDIR_aeson}" >> cabal.project
241244
echo "packages: ${PKGDIR_attoparsec_iso8601}" >> cabal.project
245+
echo "packages: ${PKGDIR_text_iso8601}" >> cabal.project
242246
echo "packages: ${PKGDIR_aeson_examples}" >> cabal.project
243247
echo "packages: ${PKGDIR_aeson_benchmarks}" >> cabal.project
244248
echo "package aeson" >> cabal.project
245249
echo " ghc-options: -Werror=missing-methods" >> cabal.project
246250
echo "package attoparsec-iso8601" >> cabal.project
247251
echo " ghc-options: -Werror=missing-methods" >> cabal.project
252+
echo "package text-iso8601" >> cabal.project
253+
echo " ghc-options: -Werror=missing-methods" >> cabal.project
248254
echo "package aeson-examples" >> cabal.project
249255
echo " ghc-options: -Werror=missing-methods" >> cabal.project
250256
echo "package aeson-benchmarks" >> cabal.project
251257
echo " ghc-options: -Werror=missing-methods" >> cabal.project
252258
cat >> cabal.project <<EOF
253259
allow-newer: hermes-json:attoparsec-iso8601
254260
EOF
255-
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(aeson|aeson-benchmarks|aeson-examples|attoparsec-iso8601)$/; }' >> cabal.project.local
261+
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(aeson|aeson-benchmarks|aeson-examples|attoparsec-iso8601|text-iso8601)$/; }' >> cabal.project.local
256262
cat cabal.project
257263
cat cabal.project.local
258264
- name: dump install plan
@@ -282,6 +288,7 @@ jobs:
282288
run: |
283289
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_aeson} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 src attoparsec-iso8601/src src-pure) ; fi
284290
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_attoparsec_iso8601} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 src) ; fi
291+
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_text_iso8601} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 src) ; fi
285292
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_aeson_examples} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 src/) ; fi
286293
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_aeson_benchmarks} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 .) ; fi
287294
if [ $((HCNUMVER >= 90200 && HCNUMVER < 90400)) -ne 0 ] ; then (cd ${PKGDIR_aeson_benchmarks} && hlint -h ${GITHUB_WORKSPACE}/source/.hlint.yaml -XHaskell2010 bench examples/src) ; fi

.hlint.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
name: "Use <=<"
1414
within:
1515
- Data.Aeson.Types.FromJSON
16+
- ignore:
17+
name: "Avoid lambda"
18+
within:
19+
- Data.Time.FromText
20+
- ignore:
21+
name: "Use isDigit"
22+
within:
23+
- Data.Time.FromText
1624

1725
# CPP confuses
1826
- ignore:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
lint:
2-
./run-hlint.sh --cpp-include include/ src/ attoparsec-iso8601/ benchmarks/ examples/ src-pure/ tests/
2+
./run-hlint.sh --cpp-include include/ src/ attoparsec-iso8601/ benchmarks/ examples/ src-pure/ tests/ text-iso8601/src text-iso8601/tests

aeson.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ tested-with:
2222
|| ==9.6.2
2323

2424
synopsis: Fast JSON parsing and encoding
25-
cabal-version: >=1.10
25+
cabal-version: 1.12
2626
homepage: https://github.com/haskell/aeson
2727
bug-reports: https://github.com/haskell/aeson/issues
2828
build-type: Simple

attoparsec-iso8601/attoparsec-iso8601.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ copyright:
1212
author: Bryan O'Sullivan <[email protected]>
1313
maintainer: Adam Bergmark <[email protected]>
1414
stability: experimental
15-
cabal-version: >=1.10
15+
cabal-version: 1.12
1616
homepage: https://github.com/haskell/aeson
1717
bug-reports: https://github.com/haskell/aeson/issues
1818
build-type: Simple

attoparsec-iso8601/src/Data/Attoparsec/Time.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ seconds = do
133133

134134
-- | Parse a time zone, and return 'Nothing' if the offset from UTC is
135135
-- zero. (This makes some speedups possible.)
136+
--
137+
-- The accepted formats are @Z@, @+HH@, @+HHMM@, or @+HH:MM@.
138+
--
136139
timeZone :: Parser (Maybe Local.TimeZone)
137140
timeZone = do
138141
ch <- satisfy $ \c -> c == 'Z' || c == '+' || c == '-'
@@ -175,6 +178,7 @@ utcTime = do
175178
in return (UTCTime d tt)
176179
Just tz -> return $! Local.localTimeToUTC tz lt
177180

181+
178182
-- | Parse a date with time zone info. Acceptable formats:
179183
--
180184
-- @YYYY-MM-DD HH:MM Z@

cabal.project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
with-compiler: ghc
22
packages: .
33
packages: attoparsec-iso8601
4+
packages: text-iso8601
45
packages: examples
56
packages: benchmarks
67
tests: true

text-iso8601/LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2023 Oleg Grenrus
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions
7+
are met:
8+
9+
1. Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the author nor the names of his contributors
17+
may be used to endorse or promote products derived from this software
18+
without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
21+
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
24+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
POSSIBILITY OF SUCH DAMAGE.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
module Main (main) where
3+
4+
import Data.Text (Text)
5+
import Test.Tasty.Bench (defaultMain, bench, nf)
6+
7+
import qualified Data.Attoparsec.Text as A
8+
import qualified Data.Attoparsec.Time as A
9+
10+
import Data.Time.FromText (parseUTCTime)
11+
12+
main :: IO ()
13+
main = defaultMain
14+
[ bench "text" $ nf parseUTCTime input1
15+
, bench "atto" $ nf (runAtto A.utcTime) input1
16+
]
17+
18+
input1 :: Text
19+
input1 = "2023-06-09T16:53:55Z"
20+
{-# NOINLINE input1 #-}
21+
22+
runAtto :: A.Parser a -> Text -> Either String a
23+
runAtto p t = A.parseOnly (p <* A.endOfInput) t

text-iso8601/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.1
2+
3+
Initial release

0 commit comments

Comments
 (0)