force DateSpans to line-wrap better in debug output

This commit is contained in:
Simon Michael 2014-04-03 15:19:45 -07:00
parent a8122405bf
commit f409f72899
2 changed files with 11 additions and 6 deletions

View File

@ -77,6 +77,11 @@ import Text.Printf
import Hledger.Data.Types
import Hledger.Utils
-- Help ppShow parse and line-wrap DateSpans better in debug output.
instance Show DateSpan where
show (DateSpan s1 s2) = "DateSpan \"" ++ show s1 ++ "\" \"" ++ show s2 ++ "\""
showDate :: Day -> String
showDate = formatTime defaultTimeLocale "%0C%y/%m/%d"
@ -672,11 +677,11 @@ tests_Hledger_Data_Dates = TestList
,"period expressions" ~: do
let todaysdate = parsedate "2008/11/26"
let str `gives` result = show (parsewith (periodexpr todaysdate) str) `is` ("Right " ++ result)
"from aug to oct" `gives` "(NoInterval,DateSpan (Just 2008-08-01) (Just 2008-10-01))"
"aug to oct" `gives` "(NoInterval,DateSpan (Just 2008-08-01) (Just 2008-10-01))"
"every 3 days in aug" `gives` "(Days 3,DateSpan (Just 2008-08-01) (Just 2008-09-01))"
"daily from aug" `gives` "(Days 1,DateSpan (Just 2008-08-01) Nothing)"
"every week to 2009" `gives` "(Weeks 1,DateSpan Nothing (Just 2009-01-01))"
"from aug to oct" `gives` "(NoInterval,DateSpan \"Just 2008-08-01\" \"Just 2008-10-01\")"
"aug to oct" `gives` "(NoInterval,DateSpan \"Just 2008-08-01\" \"Just 2008-10-01\")"
"every 3 days in aug" `gives` "(Days 3,DateSpan \"Just 2008-08-01\" \"Just 2008-09-01\")"
"daily from aug" `gives` "(Days 1,DateSpan \"Just 2008-08-01\" \"Nothing\")"
"every week to 2009" `gives` "(Weeks 1,DateSpan \"Nothing\" \"Just 2009-01-01\")"
,"splitSpan" ~: do
let gives (interval, span) = (splitSpan interval span `is`)

View File

@ -31,7 +31,7 @@ type SmartDate = (String,String,String)
data WhichDate = PrimaryDate | SecondaryDate deriving (Eq,Show)
data DateSpan = DateSpan (Maybe Day) (Maybe Day) deriving (Eq,Show,Ord,Data,Typeable)
data DateSpan = DateSpan (Maybe Day) (Maybe Day) deriving (Eq,Ord,Data,Typeable)
data Interval = NoInterval
| Days Int | Weeks Int | Months Int | Quarters Int | Years Int