Skip to content

Commit

Permalink
update docs, bump v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Dec 22, 2019
1 parent 9eb4280 commit 951a865
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 44 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.2.2] - 2019-12-22

### Added

- Worktime date range [#9]

### Fixed

- Hyphen issue in desc [#12]
Expand Down Expand Up @@ -79,7 +85,8 @@ First release :tada:

- Linux binaries

[unreleased]: https://github.com/unfog-io/unfog-cli/compare/v0.2.1...HEAD
[unreleased]: https://github.com/unfog-io/unfog-cli/compare/v0.2.2...HEAD
[0.2.2]: https://github.com/unfog-io/unfog-cli/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/unfog-io/unfog-cli/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/unfog-io/unfog-cli/compare/v0.1.4...v0.2.0
[0.1.4]: https://github.com/unfog-io/unfog-cli/compare/v0.1.3...v0.1.4
Expand All @@ -94,4 +101,5 @@ First release :tada:
[#5]: https://github.com/unfog-io/unfog-cli/issues/5
[#6]: https://github.com/unfog-io/unfog-cli/issues/6
[#8]: https://github.com/unfog-io/unfog-cli/issues/8
[#9]: https://github.com/unfog-io/unfog-cli/issues/9
[#12]: https://github.com/unfog-io/unfog-cli/issues/12
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,22 @@ unfog context +done
### Worktime

Shows the total worktime spent on tasks belonging to the given context, grouped
by days. An empty context will show the worktime of all your tasks:
by days. An empty context will show the worktime of all your tasks.

You can also filter them with a date range. Min date starts by `[`, and max
date by `]`. The date range should follow the format `DDMMYY:HHMM`, where
almost everything is optional. Default fields are based on the current date.
Here some use cases (given now = `2019/12/22 10:00`):

| Given arg | Result |
| --- | --- |
| `[21` | Starting at 2019/12/21 00:00 |
| `[18:8` | Starting at 2019/12/18 08:00 |
| `]:12` | Ending at 2019/12/22 12:00 |
| `[1010 ]1510` | Between 2019/10/10 00:00 and 2019/10/15 23:59 |

```bash
unfog wtime <+tag1> <+tag2> ...
unfog wtime <+tag1> <+tag2> <[min> <]max> ...
```

![image](https://user-images.githubusercontent.com/10437171/69493775-2ae7f180-0eb3-11ea-88a3-a59eb088830e.png)
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: unfog
version: 0.2.1
version: 0.2.2
github: "unfog-io/unfog-cli"
license: BSD3
author: "Clément DOUIN"
Expand Down
35 changes: 16 additions & 19 deletions src/Parsec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -319,27 +319,24 @@ runParser p s = case readP_to_S p s of
parseArgs :: String -> ArgTree
parseArgs = runParser parser

parseDate :: Int -> Int -> Int -> UTCTime -> ArgTree -> Maybe UTCTime
parseDate defHours defMins defSecs now args = parse <$> _minDate args
parseDate :: UTCTime -> Int -> Int -> Int -> ArgDate -> Maybe UTCTime
parseDate now defHours defMins defSecs (ArgDate 0 0 0 0 0) = Nothing
parseDate now defHours defMins defSecs (ArgDate d mo y h m) = Just
(read $ unwords [dateStr, timeStr] :: UTCTime)
where
parse date =
let
(y, mo, d) = toGregorian $ utctDay now
ArgDate d' mo' y' h' m' = date
mins = if m' > 0 then m' else defMins
hours = if h' > 0 then h' else defHours
days = if d' > 0 then d' else d
months = if mo' > 0 then mo' else mo
years = if y' == 0
then fromInteger y
else if y' < 100 then y' + truncate (realToFrac y / 100) * 100 else y'
dateStr = printf "%.4d-%.2d-%.2d" years months days
timeStr = printf "%.2d:%.2d:%.2d" hours mins defSecs
in
read $ unwords [dateStr, timeStr] :: UTCTime
(y', mo', d') = toGregorian $ utctDay now
mins = if m > 0 then m else defMins
hours = if h > 0 then h else defHours
days = if d > 0 then d else d'
months = if mo > 0 then mo else mo'
years = if y == 0
then fromInteger y'
else if y < 100 then y + truncate (realToFrac y' / 100) * 100 else y
dateStr = printf "%.4d-%.2d-%.2d" years months days
timeStr = printf "%.2d:%.2d:%.2d" hours mins defSecs

parseMinDate :: UTCTime -> ArgTree -> Maybe UTCTime
parseMinDate = parseDate 0 0 0
parseMinDate now args = _minDate args >>= parseDate now 0 0 0

parseMaxDate :: UTCTime -> ArgTree -> Maybe UTCTime
parseMaxDate = parseDate 23 59 99
parseMaxDate now args = _maxDate args >>= parseDate now 23 59 99
10 changes: 7 additions & 3 deletions src/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ execute args state events query = do
let tags = Parsec._tags args `union` _ctx state
let min = Parsec.parseMinDate now args
let max = Parsec.parseMaxDate now args
let ids = map _id $ filterByTags tags $ _tasks state
let tasks = filterByIds ids $ _tasks state
let refs = map _ref $ filterByTags tags $ _tasks state
let tasks = filterByRefs refs $ _tasks state
let wtime = getWtimePerDay now min max tasks
print now
print min
print max
print tasks
let ctx = if null tags then "global" else "for [" ++ unwords tags ++ "]"
printWtime rtype ("unfog: wtime " ++ ctx) wtime

Expand All @@ -100,6 +104,6 @@ execute args state events query = do
putStrLn "unfog <help|h>"
putStrLn "unfog <version|v>"

ShowVersion -> printVersion rtype "0.2.1"
ShowVersion -> printVersion rtype "0.2.2"

Query.Error command message -> printErr rtype $ command ++ ": " ++ message
3 changes: 3 additions & 0 deletions src/Task.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ filterByDone showDone tasks = filteredTasks
filterByIds :: [Id] -> [Task] -> [Task]
filterByIds ids = filter (flip elem ids . _id)

filterByRefs :: [Ref] -> [Task] -> [Task]
filterByRefs refs = filter (flip elem refs . _ref)

filterByTags :: [Tag] -> [Task] -> [Task]
filterByTags tags tasks = filteredTasks
where
Expand Down
36 changes: 18 additions & 18 deletions test/TaskSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,87 @@ spec = parallel $ do
let d16 = read "2019-12-22 16:00:00" :: UTCTime
let d18 = read "2019-12-22 18:00:00" :: UTCTime

it "a" $ do
it "start" $ do
let tasks = [emptyActiveTask { _starts = [d10, d14], _stops = [d12] }]
getWtimePerDay d18 Nothing Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2 + 60 * 60 * 4)]

it "ab" $ do
it "start stop" $ do
let tasks = [emptyTask { _starts = [d10, d14], _stops = [d12, d16] }]
getWtimePerDay d18 Nothing Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 4)]

it "[a" $ do
it "[ start" $ do
let tasks = [emptyActiveTask { _starts = [d16] }]
getWtimePerDay d18 (Just d10) Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "a[" $ do
it "start [" $ do
let tasks = [emptyActiveTask { _starts = [d10] }]
getWtimePerDay d18 (Just d14) Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 4)]

it "[ab" $ do
it "[ start stop" $ do
let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }]
getWtimePerDay d18 (Just d10) Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "a[b" $ do
it "start [ stop" $ do
let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }]
getWtimePerDay d18 (Just d14) Nothing tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "ab[" $ do
it "start stop [" $ do
let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }]
getWtimePerDay d18 (Just d18) Nothing tasks `shouldBe` []

it "]a" $ do
it "] start" $ do
let tasks = [emptyActiveTask { _starts = [d14] }]
getWtimePerDay d18 Nothing (Just d10) tasks `shouldBe` []

it "a]" $ do
it "start ]" $ do
let tasks = [emptyActiveTask { _starts = [d10] }]
getWtimePerDay d18 Nothing (Just d12) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "]ab" $ do
it "] start stop" $ do
let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }]
getWtimePerDay d18 Nothing (Just d10) tasks `shouldBe` []

it "a]b" $ do
it "start ] stop" $ do
let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }]
getWtimePerDay d18 Nothing (Just d14) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "ab]" $ do
it "start stop ]" $ do
let tasks = [emptyActiveTask { _starts = [d14], _stops = [d16] }]
getWtimePerDay d18 Nothing (Just d18) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "[ab]" $ do
it "[ start stop ]" $ do
let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }]
getWtimePerDay d18 (Just d10) (Just d18) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 4)]

it "a[b]" $ do
it "start [ stop ]" $ do
let tasks = [emptyActiveTask { _starts = [d12], _stops = [d16] }]
getWtimePerDay d18 (Just d14) (Just d18) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

it "[a]b" $ do
it "[ start ] stop" $ do
let tasks = [emptyActiveTask { _starts = [d12], _stops = [d18] }]
getWtimePerDay d18 (Just d10) (Just d16) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 4)]

it "ab[]" $ do
it "start stop []" $ do
let tasks = [emptyActiveTask { _starts = [d10], _stops = [d14] }]
getWtimePerDay d18 (Just d16) (Just d18) tasks `shouldBe` []

it "[]ab" $ do
it "[] start stop" $ do
let tasks = [emptyActiveTask { _starts = [d16], _stops = [d18] }]
getWtimePerDay d18 (Just d10) (Just d12) tasks `shouldBe` []

it "a[]b" $ do
it "start [] stop" $ do
let tasks = [emptyActiveTask { _starts = [d10], _stops = [d18] }]
getWtimePerDay d18 (Just d14) (Just d16) tasks
`shouldBe` [("2019-12-22", 60 * 60 * 2)]

0 comments on commit 951a865

Please sign in to comment.