-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Provide duration helper
--   
--   This is a minimal Haskell library to display duration.
--   
--   <pre>
--   let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
--   humanReadableDuration duration
--   -- will return: "2 years 33 days 2 min 3s 2ms"
--   getYears duration
--   -- will return 2
--   getDays duration
--   -- will return 763
--   getMs duration
--   -- will return 65923323002
--   </pre>
@package human-readable-duration
@version 0.2.1.2


-- | This is a minimal Haskell library to display duration.
--   
--   <pre>
--   &gt; let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
--   &gt; humanReadableDuration duration
--   "2 years 33 days 2 min 3s 2ms"
--   &gt; getYears duration
--   2
--   &gt; getDays duration
--   763
--   &gt; getMs duration
--   65923323002
--   
--   </pre>
module Data.Duration

-- | <a>humanReadableDuration</a> take some time in micro-second precision
--   and render a human readable duration.
--   
--   <pre>
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
--   
--   &gt;&gt;&gt; duration
--   65923323.002000
--   
--   &gt;&gt;&gt; humanReadableDuration duration
--   "2 years 33 days 2 min 3s 2ms"
--   </pre>
humanReadableDuration :: Seconds -> String

-- | Wrapper around any <a>Real</a> input, which works for
--   <tt>DiffTime</tt> and <tt>NominalDiffTime</tt> from the time library,
--   or a <a>Double</a> of seconds.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Time.Clock
--   
--   &gt;&gt;&gt; humanReadableDuration' (secondsToDiffTime 10)
--   "10s "
--   </pre>
humanReadableDuration' :: Real a => a -> String

-- | <a>humanReadableDuration</a> take some time in micro-second precision
--   and render a human readable duration.
--   
--   <pre>
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year
--   
--   &gt;&gt;&gt; duration
--   65923323.002000
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "2 years"
--   
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "33 days"
--   
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond + 280 * minute
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "4 hours"
--   
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond + 22 * minute
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "22 min"
--   
--   &gt;&gt;&gt; let duration = 2 * ms + 3 * oneSecond
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "3s"
--   
--   &gt;&gt;&gt; let duration = 12 * ms
--   
--   &gt;&gt;&gt; approximativeDuration duration
--   "12ms"
--   </pre>
approximativeDuration :: Micro -> String
type Seconds = Micro

-- | one millisecond (<tt>0.001</tt>)
--   
--   <pre>
--   &gt;&gt;&gt; ms
--   0.001000
--   
--   &gt;&gt;&gt; 1000 * ms
--   1.000000
--   </pre>
ms :: Seconds

-- | one second (<tt>1</tt>)
--   
--   <pre>
--   &gt;&gt;&gt; oneSecond / ms
--   1000.000000
--   
--   &gt;&gt;&gt; oneSecond
--   1.000000
--   </pre>
oneSecond :: Seconds

-- | number of seconds in one minute
--   
--   <pre>
--   &gt;&gt;&gt; minute / oneSecond
--   60.000000
--   
--   &gt;&gt;&gt; minute / ms
--   60000.000000
--   </pre>
minute :: Seconds

-- | number of seconds in one hour
--   
--   <pre>
--   &gt;&gt;&gt; hour / minute
--   60.000000
--   
--   &gt;&gt;&gt; hour / oneSecond
--   3600.000000
--   </pre>
hour :: Seconds

-- | number of seconds in one day
--   
--   <pre>
--   &gt;&gt;&gt; day / hour
--   24.000000
--   
--   &gt;&gt;&gt; day / oneSecond
--   86400.000000
--   </pre>
day :: Seconds

-- | number of seconds in one year
--   
--   <pre>
--   &gt;&gt;&gt; year / day
--   365.000000
--   </pre>
year :: Seconds

-- | number of milli seconds given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getMs 1
--   1000
--   
--   &gt;&gt;&gt; getMs 1.618033
--   1618
--   </pre>
getMs :: Seconds -> Integer

-- | number of seconds given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getSeconds 1
--   1
--   
--   &gt;&gt;&gt; getSeconds 1.618033
--   1
--   </pre>
getSeconds :: Seconds -> Integer

-- | number of minutes given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getMinutes 60
--   1
--   
--   &gt;&gt;&gt; getMinutes 59
--   0
--   </pre>
getMinutes :: Seconds -> Integer

-- | number of hours given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getHours 3600
--   1
--   
--   &gt;&gt;&gt; getHours (60 * minute)
--   1
--   
--   &gt;&gt;&gt; getHours (2 * day)
--   48
--   </pre>
getHours :: Seconds -> Integer

-- | number of days given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getDays (10 * day)
--   10
--   
--   &gt;&gt;&gt; getDays (240 * hour)
--   10
--   </pre>
getDays :: Seconds -> Integer

-- | number of years given a duration in micro seconds
--   
--   <pre>
--   &gt;&gt;&gt; getYears (720 * day)
--   1
--   
--   &gt;&gt;&gt; getYears (740 * day)
--   2
--   </pre>
getYears :: Seconds -> Integer


-- | Use <tt>human-readable-duration</tt> if you want to replace "1002012
--   seconds left" by the easier to read: "11 days 14 hours 20 min 12s
--   left"
--   
--   But also if you want to manipulate time duration easily by using
--   seconds, minutes, hours and days. Typically if you prefer to write:
--   
--   <pre>
--   x + (5 * oneSecond) + (2 * minute) + (1 * day)
--   </pre>
--   
--   instead of
--   
--   <pre>
--   x + 5 * 2*60 * 1*60*60*24
--   </pre>
module Data.Duration.Tutorial
