pretty-relative-time 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+46/−14 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +13/−0
- pretty-relative-time.cabal +3/−3
- src/Text/Time/Pretty/Constants.hs +1/−1
- src/Text/Time/Pretty/TimeAgo.hs +29/−10
ChangeLog.md view
@@ -1,3 +1,16 @@ # Changelog for pretty-relative-time ## Unreleased changes++## [0.2.0.0] - 2020-02-12++### Changed++Fixed a bug like this:++```+ approximateDaysPerMonth :: Integral a => a+-approximateDaysPerMonth = 30++approximateDaysPerMonth = 31+```+
pretty-relative-time.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.0. -- -- see: https://github.com/sol/hpack ----- hash: adf64d540112ae1c5a3643234034c51572f5f251cba6a9c63ba8a48b8285b629+-- hash: 3c3eba99b4fd54cfb105bc62e7caea77caf57513705abac5550c0b645bd43e96 name: pretty-relative-time-version: 0.1.0.0+version: 0.2.0.0 synopsis: Pretty relative time description: Please see the README on Github at <https://github.com/NorfairKing/pretty-relative-time#readme> category: Time
src/Text/Time/Pretty/Constants.hs view
@@ -24,7 +24,7 @@ daysPerWeek = 7 approximateDaysPerMonth :: Integral a => a-approximateDaysPerMonth = 30+approximateDaysPerMonth = 31 approximateDaysPerYear :: Integral a => a approximateDaysPerYear = 365
src/Text/Time/Pretty/TimeAgo.hs view
@@ -32,12 +32,22 @@ [ genericValidate da , check (case daysAgoSign of- EQ -> and [daysAgoDays == 0, daysAgoWeeks == 0, daysAgoMonths == 0, daysAgoYears == 0]- _ -> any (> 0) [daysAgoDays, daysAgoWeeks, daysAgoMonths, daysAgoYears])+ EQ ->+ and+ [ daysAgoDays == 0+ , daysAgoWeeks == 0+ , daysAgoMonths == 0+ , daysAgoYears == 0+ ]+ _ ->+ any+ (> 0)+ [daysAgoDays, daysAgoWeeks, daysAgoMonths, daysAgoYears]) "the sign makes sense" , check (daysAgoYears >= 0) "years are positive" , check- (daysAgoDays + daysPerWeek * daysAgoWeeks + approximateDaysPerMonth * daysAgoMonths <+ (daysAgoDays + daysPerWeek * daysAgoWeeks ++ approximateDaysPerMonth * daysAgoMonths < approximateDaysPerYear) "days, weeks and months do not sum to a year" , check (daysAgoMonths < 12) "months < 12"@@ -59,7 +69,8 @@ daysAgoYears = totalDays `div` approximateDaysPerYear daysLeftAfterYears = totalDays - daysAgoYears * approximateDaysPerYear daysAgoMonths = daysLeftAfterYears `div` approximateDaysPerMonth- daysLeftAfterMonths = daysLeftAfterYears - daysAgoMonths * approximateDaysPerMonth+ daysLeftAfterMonths =+ daysLeftAfterYears - daysAgoMonths * approximateDaysPerMonth daysAgoWeeks = daysLeftAfterMonths `div` daysPerWeek daysLeftAfterWeeks = daysLeftAfterMonths - daysAgoWeeks * daysPerWeek daysAgoDays = daysLeftAfterWeeks@@ -70,7 +81,8 @@ EQ -> const 0 GT -> id LT -> negate) $- daysAgoDays + daysPerWeek * daysAgoWeeks + approximateDaysPerMonth * daysAgoMonths ++ daysAgoDays + daysPerWeek * daysAgoWeeks ++ approximateDaysPerMonth * daysAgoMonths + approximateDaysPerYear * daysAgoYears data TimeAgo =@@ -123,17 +135,23 @@ timeAgo dt = TimeAgo {..} where timeAgoSign = compare dt 0- timeAgoPicoSeconds = totalPicoSecondsAgo - picoSecondsPerSecond * totalSecondsAgo+ timeAgoPicoSeconds =+ totalPicoSecondsAgo - picoSecondsPerSecond * totalSecondsAgo timeAgoSeconds = totalSecondsAgo - secondsPerMinute * totalMinutesAgo timeAgoMinutes = totalMinutesAgo - minutesPerHour * totalHoursAgo timeAgoHours = totalHoursAgo - hoursPerDay * totalDaysAgo timeAgoDaysAgo = daysAgo totalDaysAgo- totalPicoSecondsAgo = floor $ absDt * fromIntegral (picoSecondsPerSecond :: Integer)+ totalPicoSecondsAgo =+ floor $ absDt * fromIntegral (picoSecondsPerSecond :: Integer) totalSecondsAgo = floor absDt :: Integer totalMinutesAgo = floor $ absDt / fromIntegral (secondsPerMinute :: Integer)- totalHoursAgo = floor $ absDt / fromIntegral (minutesPerHour * secondsPerMinute :: Integer)+ totalHoursAgo =+ floor $+ absDt / fromIntegral (minutesPerHour * secondsPerMinute :: Integer) totalDaysAgo =- floor $ absDt / fromIntegral (hoursPerDay * minutesPerHour * secondsPerMinute :: Integer)+ floor $+ absDt /+ fromIntegral (hoursPerDay * minutesPerHour * secondsPerMinute :: Integer) absDt = abs dt timeAgoToDiffTime :: TimeAgo -> NominalDiffTime@@ -149,4 +167,5 @@ (timeAgoSeconds + secondsPerMinute * (timeAgoMinutes +- minutesPerHour * (timeAgoHours + hoursPerDay * (daysAgoToDays timeAgoDaysAgo)))))+ minutesPerHour *+ (timeAgoHours + hoursPerDay * (daysAgoToDays timeAgoDaysAgo)))))