Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
875c30e5
Commit
875c30e5
authored
Mar 02, 2018
by
Mael NICOLAS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add lose precision
parent
57da5f95
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
11 deletions
+41
-11
gargantext.cabal
gargantext.cabal
+7
-0
Date.hs
src-test/Parsers/Date.hs
+10
-4
Types.hs
src-test/Parsers/Types.hs
+21
-2
Date.hs
src/Gargantext/Parsers/Date.hs
+3
-5
No files found.
gargantext.cabal
View file @
875c30e5
...
@@ -40,6 +40,7 @@ library
...
@@ -40,6 +40,7 @@ library
, extra
, extra
, filepath
, filepath
, http-conduit
, http-conduit
, hxt
, ini
, ini
, lens
, lens
, logging-effect
, logging-effect
...
@@ -162,16 +163,22 @@ test-suite garg-test
...
@@ -162,16 +163,22 @@ test-suite garg-test
build-depends:
build-depends:
QuickCheck
QuickCheck
, base
, base
, duckling
, extra
, extra
, gargantext
, gargantext
, hspec
, hspec
, parsec
, quickcheck-instances
, text
, text
, time
other-modules:
other-modules:
Ngrams.Lang
Ngrams.Lang
Ngrams.Lang.En
Ngrams.Lang.En
Ngrams.Lang.Fr
Ngrams.Lang.Fr
Ngrams.Lang.Occurrences
Ngrams.Lang.Occurrences
Ngrams.Metrics
Ngrams.Metrics
Parsers.Date
Parsers.Types
Parsers.WOS
Parsers.WOS
Paths_gargantext
Paths_gargantext
default-language: Haskell2010
default-language: Haskell2010
src-test/Parsers/Date.hs
View file @
875c30e5
...
@@ -8,6 +8,8 @@ import Test.Hspec
...
@@ -8,6 +8,8 @@ import Test.Hspec
import
Test.QuickCheck
import
Test.QuickCheck
import
Parsers.Types
import
Parsers.Types
import
Control.Applicative
((
<*>
))
import
Data.Tuple
(
uncurry
)
import
Data.Either
(
Either
(
..
))
import
Data.Either
(
Either
(
..
))
import
Data.Time
(
ZonedTime
(
..
))
import
Data.Time
(
ZonedTime
(
..
))
import
Data.Text
(
pack
,
Text
)
import
Data.Text
(
pack
,
Text
)
...
@@ -18,11 +20,15 @@ import Gargantext.Parsers.Date (fromRFC3339)
...
@@ -18,11 +20,15 @@ import Gargantext.Parsers.Date (fromRFC3339)
fromRFC3339Inv
::
Either
ParseError
ZonedTime
->
Text
fromRFC3339Inv
::
Either
ParseError
ZonedTime
->
Text
fromRFC3339Inv
(
Right
z
)
=
toRFC3339
z
fromRFC3339Inv
(
Right
z
)
=
toRFC3339
z
fromRFC3339Inv
(
Left
pe
)
=
pack
$
show
pe
fromRFC3339Inv
(
Left
pe
)
=
pa
nic
.
pa
ck
$
show
pe
{-
testFromRFC3339 :: IO ()
testFromRFC3339
::
IO
()
testFromRFC3339
=
hspec
$
do
testFromRFC3339
=
hspec
$
do
describe
"Test fromRFC3339: "
$
do
describe
"Test fromRFC3339: "
$
do
it
"is the inverse of Duckling's toRFC3339"
$
property
$
it
"is the inverse of Duckling's toRFC3339"
$
property
$
\x -> (fromRFC3339 . fromRFC3339Inv) x == (x :: Either ParseError ZonedTime)
((
==
)
<*>
(
fromRFC3339
.
fromRFC3339Inv
))
.
Right
.
looseZonedTimePrecision
--}
-- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
-- \x -> let e = Right x :: Either ParseError ZonedTime
-- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)
src-test/Parsers/Types.hs
View file @
875c30e5
...
@@ -4,16 +4,35 @@
...
@@ -4,16 +4,35 @@
module
Parsers.Types
where
module
Parsers.Types
where
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Prelude
(
floor
,
fromIntegral
)
import
Test.QuickCheck
import
Test.QuickCheck
import
Test.QuickCheck.Instances
()
import
Test.QuickCheck.Instances
()
import
Text.Parsec.Pos
import
Text.Parsec.Pos
import
Text.Parsec.Error
(
ParseError
,
Message
(
..
),
newErrorMessage
)
import
Text.Parsec.Error
(
ParseError
,
Message
(
..
),
newErrorMessage
)
import
Data.Time.LocalTime
(
ZonedTime
(
..
))
import
Data.Time.LocalTime
(
ZonedTime
(
..
)
,
TimeZone
(
..
),
TimeOfDay
(
..
),
LocalTime
(
..
)
)
import
Data.Eq
(
Eq
(
..
))
import
Data.Eq
(
Eq
(
..
))
import
Data.Either
(
Either
(
..
))
deriving
instance
Eq
ZonedTime
deriving
instance
Eq
ZonedTime
looseTimeOfDayPrecision
::
TimeOfDay
->
TimeOfDay
looseTimeOfDayPrecision
(
TimeOfDay
h
m
s
)
=
TimeOfDay
h
m
0
looseLocalTimePrecision
::
LocalTime
->
LocalTime
looseLocalTimePrecision
(
LocalTime
ld
ltd
)
=
LocalTime
ld
$
looseTimeOfDayPrecision
ltd
looseTimeZonePrecision
::
TimeZone
->
TimeZone
looseTimeZonePrecision
(
TimeZone
zm
_
_
)
=
TimeZone
zm
False
"CET"
looseZonedTimePrecision
::
ZonedTime
->
ZonedTime
looseZonedTimePrecision
(
ZonedTime
lt
tz
)
=
ZonedTime
(
looseLocalTimePrecision
lt
)
$
looseTimeZonePrecision
tz
loosePrecisionEitherPEZT
::
Either
ParseError
ZonedTime
->
Either
ParseError
ZonedTime
loosePrecisionEitherPEZT
(
Right
zt
)
=
Right
$
looseZonedTimePrecision
zt
loosePrecisionEitherPEZT
pe
=
pe
instance
Arbitrary
Message
where
instance
Arbitrary
Message
where
arbitrary
=
do
arbitrary
=
do
msgContent
<-
arbitrary
msgContent
<-
arbitrary
...
...
src/Gargantext/Parsers/Date.hs
View file @
875c30e5
...
@@ -36,7 +36,7 @@ import Duckling.Types (jsonValue, Entity)
...
@@ -36,7 +36,7 @@ import Duckling.Types (jsonValue, Entity)
import
Duckling.Api
(
analyze
,
parse
)
import
Duckling.Api
(
analyze
,
parse
)
import
qualified
Data.HashSet
as
HashSet
import
qualified
Data.HashSet
as
HashSet
import
qualified
Data.Aeson
as
Json
import
qualified
Data.Aeson
as
Json
import
Data.Time
(
ZonedTime
(
..
),
LocalTime
(
..
),
TimeZone
(
..
),
TimeOfDay
(
..
)
,
getCurrentTimeZone
)
import
Data.Time
(
ZonedTime
(
..
),
LocalTime
(
..
),
TimeZone
(
..
),
TimeOfDay
(
..
))
import
Data.Time.Calendar
(
Day
,
fromGregorian
)
import
Data.Time.Calendar
(
Day
,
fromGregorian
)
import
Data.Fixed
(
Fixed
(
MkFixed
))
import
Data.Fixed
(
Fixed
(
MkFixed
))
import
Data.Foldable
(
length
)
import
Data.Foldable
(
length
)
...
@@ -52,7 +52,6 @@ import Data.Text (Text, unpack)
...
@@ -52,7 +52,6 @@ import Data.Text (Text, unpack)
import
Duckling.Types
(
ResolvedToken
)
import
Duckling.Types
(
ResolvedToken
)
import
Safe
(
headMay
)
import
Safe
(
headMay
)
import
System.IO.Unsafe
(
unsafePerformIO
)
import
Text.Parsec.Error
(
ParseError
)
import
Text.Parsec.Error
(
ParseError
)
import
Text.Parsec.String
(
Parser
)
import
Text.Parsec.String
(
Parser
)
...
@@ -144,7 +143,7 @@ parseTimeOfDay = do
...
@@ -144,7 +143,7 @@ parseTimeOfDay = do
_
<-
char
'.'
_
<-
char
'.'
dec
<-
many1NoneOf
[
'+'
,
'-'
]
dec
<-
many1NoneOf
[
'+'
,
'-'
]
let
(
nb
,
l
)
=
(
decimalStringToInt
$
r
++
dec
,
length
dec
)
let
(
nb
,
l
)
=
(
decimalStringToInt
$
r
++
dec
,
length
dec
)
seconds
=
nb
*
10
^
(
12
-
l
)
seconds
=
nb
*
10
^
(
12
-
l
)
return
$
TimeOfDay
h
m
(
MkFixed
.
toInteger
$
seconds
)
return
$
TimeOfDay
h
m
(
MkFixed
.
toInteger
$
seconds
)
...
@@ -155,9 +154,8 @@ parseTimeZone = do
...
@@ -155,9 +154,8 @@ parseTimeZone = do
h
<-
wrapDST
=<<
many1NoneOf
[
':'
]
h
<-
wrapDST
=<<
many1NoneOf
[
':'
]
_
<-
char
':'
_
<-
char
':'
m
<-
wrapDST
=<<
(
many1
$
anyChar
)
m
<-
wrapDST
=<<
(
many1
$
anyChar
)
let
(
TimeZone
_
s
n
)
=
unsafePerformIO
getCurrentTimeZone
let
timeInMinute
=
if
sign
==
'+'
then
h
*
60
+
m
else
-
h
*
60
-
m
let
timeInMinute
=
if
sign
==
'+'
then
h
*
60
+
m
else
-
h
*
60
-
m
in
return
$
TimeZone
timeInMinute
s
n
in
return
$
TimeZone
timeInMinute
False
"CET"
-- | Parser which use parseGregorian, parseTimeOfDay and parseTimeZone to create a ZonedTime
-- | Parser which use parseGregorian, parseTimeOfDay and parseTimeZone to create a ZonedTime
parseZonedTime
::
Parser
ZonedTime
parseZonedTime
::
Parser
ZonedTime
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment