Skip to content

Commit

Permalink
List PROJECT column with worktime --more (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
razcore-rad authored Dec 13, 2022
1 parent efacf65 commit d118e0e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.5] - 2022-12-13

- Also list PROJECT column with `worktime --more`

## [1.0.4] - 2021-07-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/Unfog/Procedure/Handler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Unfog.Response
import qualified Unfog.State as State

showVersion :: Arg.JsonOpt -> IO ()
showVersion jsonOpt = send rtype $ VersionResponse "1.0.4"
showVersion jsonOpt = send rtype $ VersionResponse "1.0.5"
where
rtype = parseResponseType jsonOpt

Expand Down
3 changes: 2 additions & 1 deletion lib/Unfog/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ showDailyWtimeText _ dwtimes = render $ head : body ++ foot
showFullDailyWtimeText :: UTCTime -> [DailyWorktime] -> String
showFullDailyWtimeText _ dwtimes = render $ head : body ++ foot
where
head = map (underline . bold . cell) ["DATE", "ID", "DESC", "WORKTIME"]
head = map (underline . bold . cell) ["DATE", "ID", "PROJECT", "DESC", "WORKTIME"]
body = concatMap rows dwtimes

rows dwtime = map rows' (snd dwtime) ++ subtotal
Expand All @@ -189,6 +189,7 @@ showFullDailyWtimeText _ dwtimes = render $ head : body ++ foot
rows' wtime =
[ cell $ fst dwtime,
red $ cell $ getWtimeId wtime,
blue $ cell $ fromMaybe "" $ getWtimeProj wtime,
cell $ getWtimeDesc wtime,
yellow $ cell $ showFullDuration $ getWtimeDuration wtime
]
Expand Down
15 changes: 8 additions & 7 deletions lib/Unfog/Worktime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Unfog.Task

data Worktime = Worktime
{ getWtimeId :: Id,
getWtimeProj :: Project,
getWtimeDesc :: Desc,
getWtimeDuration :: Duration
}
Expand All @@ -32,14 +33,14 @@ buildWtimePerDay now idLength from to = sortOn fst . foldl buildWtimePerDay' []
where
buildWtimePerDay' wtimes task = filter (\(_, wtimes) -> sum (map getWtimeDuration wtimes) > 0) $ mergeDailyWtimes wtimes $ concatMap (wtimePerDay wtime) $ zip starts' stops'
where
wtime = Worktime (shortenId idLength $ getId task) (getDesc task) 0
wtime = Worktime (shortenId idLength $ getId task) (getProject task) (getDesc task) 0
starts' = map (clampTime from to) $ getStarts task
stops' = map (clampTime from to) $ getStops task ++ [now | isJust $ getActive task]

wtimePerDay :: Worktime -> (UTCTime, UTCTime) -> [DailyWorktime]
wtimePerDay (Worktime id desc _) (start, stop)
| stop < endOfDay = [(day, [Worktime id desc $ realToFrac $ diffUTCTime stop start])]
| otherwise = (day, [Worktime id desc $ realToFrac $ diffUTCTime endOfDay start]) : wtimePerDay (Worktime id desc 0) (nextDay, stop)
wtimePerDay (Worktime id project desc _) (start, stop)
| stop < endOfDay = [(day, [Worktime id project desc $ realToFrac $ diffUTCTime stop start])]
| otherwise = (day, [Worktime id project desc $ realToFrac $ diffUTCTime endOfDay start]) : wtimePerDay (Worktime id project desc 0) (nextDay, stop)
where
day = show currDay
currDay = utctDay start
Expand All @@ -55,9 +56,9 @@ mergeDailyWtimes = foldl mergeWtimes'
(bday, foldl mergeWtimes avals bvals) : filter ((/=) bday . fst) a

mergeWtimes :: [Worktime] -> Worktime -> [Worktime]
mergeWtimes xvals (Worktime yid ydesc ywtime) =
mergeWtimes xvals (Worktime yid yproject ydesc ywtime) =
case find ((==) yid . getWtimeId) xvals of
Nothing -> Worktime yid ydesc ywtime : xvals
Just aval -> Worktime yid ydesc (getWtimeDuration aval + ywtime) : without yid xvals
Nothing -> Worktime yid yproject ydesc ywtime : xvals
Just aval -> Worktime yid yproject ydesc (getWtimeDuration aval + ywtime) : without yid xvals
where
without val = filter ((/=) val . getWtimeId)

0 comments on commit d118e0e

Please sign in to comment.