Commit graph

2821 commits

Author SHA1 Message Date
Christian Rösch
3def4b10c4 Refactor code as suggested and add tests. 2020-07-01 16:16:58 +02:00
Christian Rösch
f3280966e0 Allow continue by tag. 2020-07-01 16:16:58 +02:00
Thomas Lauf
6db29f1df5 Move overlap resolution from CmdContinue to function autoAdjust
- Only an open interval can truncate another open interval.
  Otherwise the `:adjust` hint has to be applied

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-07-01 08:12:04 +02:00
Thomas Lauf
c6598b9ac8 Convert to early return
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-30 21:17:51 +02:00
Thomas Lauf
07a6dfe313 Use functions is_started() and is_ended() instead of querying start/end directly
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-29 22:09:00 +02:00
Thomas Lauf
4637cd3d4e Do not manipulate filter in getTracked
- Filter shall be taken as is, not changed
- If there is a problem, the functions consuming the filter have to be adapted, not the filter

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-29 22:07:35 +02:00
Thomas Lauf
63f230013a Detect whether a date is meant as range
- Add DatetimeParser::parse_range: If a date contains no time, it is assumed to be a fixed range, else an open range starting at given datetime
- Add tests for summary with named dates 'yesterday' and 'today'
- Remove closing of filter in CmdSummary.cpp
- Closes #333

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-28 20:52:43 +02:00
Thomas Lauf
2906f36830 Add test for command summary with :all hint
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-22 22:21:27 +02:00
George Buckingham
90081afb97 Update docs links from taskwarrior.org to timewarrior.net
Signed-off-by: George Buckingham <george.buckingham@gmail.com>
2020-06-14 15:12:57 +02:00
Shaun Ruffell
59d0f1263f Mask signals while updating database
In order to keep the database consistent, we really want all the
AtomicFiles to be finalized as a group. This will prevent an inopportune
signal from interrupting this process.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-06-03 21:31:01 +02:00
Thomas Lauf
83ec55cdc6 Remove unused filter
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 18:44:36 +02:00
Thomas Lauf
c9eec956e4 Add hint :all
- Closes #206

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 18:44:36 +02:00
Thomas Lauf
6117ce1a84 Introduce default range parameter when requesting filter from CLI
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-06-03 17:47:14 +02:00
Thomas Lauf
7e11fde992 Remove template.t from test folder
- This file was development only, now any other test file can serve as template for new tests
- Closes #303

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-22 09:16:08 +02:00
Thomas Lauf
c71eeb6dfd Add DOM-query for ids
- Closes #126

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
2169e8e928 Add/update descriptive comments
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
a508dd21ea Get and use filter from CLI when processing DOM references
- Closes #188

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
13f1de2c49 Identify DOM references by their prefix ('dom.<...>') and mark them as such when analyzing the command line
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
9ae3ace109 Make getFilter(cli) a method of CLI 2020-05-10 21:44:30 +02:00
Thomas Lauf
547bda5ef8 Extract filter so it can be injected
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
6e5236d472 Add DOM query dom.tracked.tags
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
5c234c95f9 Move test setup to the test methods
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Thomas Lauf
422e49bacb Extract function getDomReferences and move it to CLI
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-05-10 21:44:30 +02:00
Shaun Ruffell
29cc9e8a0a Fix another place where json::parse() result was leaked
Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:33:31 +02:00
Shaun Ruffell
42ede4104c Remove naked pointer in initializeTagDatabase
The json::object pointer was allocated in the parse function but never
freed.

The way timwarrior is used currently, this leak does not cause any
problems, but...

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:33:31 +02:00
Shaun Ruffell
85d991704b Speed up deserialization of Intervals
When the Lexer breaks a line into tokens, it also wants to return the
type of the token. This information isn't used by the IntervalFactory
and it slows down the operation since dates end up being parsed at least
twice, once by the Lexer to determine that the string is a date, then
again in the IntervalFactory to actually construct the Date.

Before are the before and after results when exporting a database with
100 lines. The number of instructions executed went from roughly 31,552,467 to
12,952,372 on debug builds. Release builds saw a change from around 14K
to 7K instructions.

Before:

  $ rm -fr ~/.timewarrior; src/timew :yes >/dev/null; for x in {100..1}; do src/timew start ${x}sec ago proj_${x} >/dev/null; done;
  $ sudo chrt -f 99 valgrind --tool=callgrind --callgrind-out-file=callgrind.out src/timew export >/dev/null
  ==20888== Callgrind, a call-graph generating cache profiler
  ==20888== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
  ==20888== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==20888== Command: src/timew export
  ==20888==
  ==20888== For interactive control, run 'callgrind_control -h'.
  ==20888==
  ==20888== Events    : Ir
  ==20888== Collected : 31552467
  ==20888==
  ==20888== I   refs:      31,552,467

After:

  $ sudo chrt -f 99 valgrind --tool=callgrind --callgrind-out-file=callgrind.out src/timew export >/dev/null
  ==24088== Callgrind, a call-graph generating cache profiler
  ==24088== Copyright (C) 2002-2017, and GNU GPL'd, by Josef Weidendorfer et al.
  ==24088== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
  ==24088== Command: src/timew export
  ==24088==
  ==24088== For interactive control, run 'callgrind_control -h'.
  ==24088==
  ==24088== Events    : Ir
  ==24088== Collected : 12952372
  ==24088==
  ==24088== I   refs:      12,952,372

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-05-10 21:16:08 +02:00
Thomas Lauf
3de53d7599 Bump project version to 1.3.0
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 17:38:40 +02:00
Thomas Lauf
d2ea71cd90 Prepare for release 1.3.0
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 15:40:07 +02:00
Thomas Lauf
2c7259aa41 Update ChangeLog
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 15:23:43 +02:00
Thomas Lauf
d4015bbeae Update NEWS
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 15:23:12 +02:00
Thomas Lauf
ad58309159 Update Copyright
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-19 12:41:23 +02:00
Thomas Lauf
d73143b6cb remove unnecessary line breaks
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-14 10:11:39 +02:00
Thomas Lauf
94cbcab195 set consistent minimum versions for gcc and clang
- we require full C++11 support, so gcc 4.8.1 and clang 3.3 it is
- closes #268

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-13 18:36:22 +02:00
Thomas Lauf
f3396f7193 Update ChangeLog, AUTHORS
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-13 16:59:10 +02:00
Thomas Lauf
dd8f2ab2b5 Update bash completion
- Closes #298

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-04-13 16:59:10 +02:00
Daniel
0e5e3316ca DOC: Added documentation about :fortnight in ChangeLog. 2020-03-06 21:58:28 +01:00
Daniel
13fb0ad8e3 ENH: Add new interval hint :fortnight (sopw - eow). 2020-03-06 21:56:43 +01:00
Thomas Lauf
41c50e009c Add test for export with tag filter
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-06 16:13:00 +01:00
Shaun Ruffell
42872f5168 test: Add test for filtering non-contiguous intervals
Related to #293

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-06 16:10:19 +01:00
Shaun Ruffell
0b39a83a92 Filtering with tags should preserve the interval IDs.
This fixes the bug where, when filtering by tags, the interval IDs are not
preserved when not using any tags in the filter. Notice below how when
filtering with tag1, the two intervals are @4 and @5 instead of @1 and @5 like
they should be:

  $ timew summ :ids

  Wk Date       Day ID Tags    Start      End    Time   Total
  W9 2020-02-29 Sat @5 tag1 15:28:31 15:28:33 0:00:02
                    @4 tag2 15:28:33 15:28:35 0:00:02
                    @3 tag3 15:28:35 15:28:36 0:00:01
                    @2 tag4 15:28:36 15:28:48 0:00:12
                    @1 tag1 15:28:48        - 0:02:25 0:02:42

                                                      0:02:42

  $ timew summ tag1 :ids

  Wk Date       Day ID Tags    Start      End    Time   Total
  W9 2020-02-29 Sat @5 tag1 15:28:31 15:28:33 0:00:02
                    @4 tag1 15:28:48        - 0:02:28 0:02:30

                                                      0:02:30

This fixes a bug introduced in 86bb1465e8.

Closes issue #293 (thanks sskras)

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-06 16:10:19 +01:00
Shaun Ruffell
b62b7b3435 Interval: We can return a const reference to tags.
Interval is already marked as a constant object here and we can eliminate
creating unnecessary copies when filtering large databases.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-06 16:10:19 +01:00
Shaun Ruffell
c1f3d8be72 Check serialization before writing to database
Ensure that the IntervalFactory can parse the string returned by
Interval::serialize before writing to database.

If a user attempts to add a non-parseable date, you will get an error like:

  $ TZ="GMT" timew track 7h before 1970-01-01T00:00:00 test
  Note: 'test' is a new tag.
  Internal error. Failed encode / decode check.

Or if the user attempts to add a tag that is not supported:

  $ timew start 1970-01-01T00:00:00 '\"TEST\"'
  Note: '"\\"TEST\\""' is a new tag.
  Internal error. Failed encode / decode check.

On #159, the serializer / deserializer should be able to handle the escaped
quotes, but it is another example where we do not want any entry written into
the database that cannot be properly parsed. This change will also add more
verbose debugging information if the :debug flag is passed, like:

  $ timew start 1970-01-01T00:00:00 '\"TEST\"' :debug
  CLI Parser
    _original_args
      timew start 1970-01-01T00:00:00 \"TEST\" :debug
    _args
      word basename='timew' raw='timew' BINARY
      word canonical='start' raw='start' ORIGINAL CMD
      date raw='1970-01-01T00:00:00' ORIGINAL FILTER
      word raw='\"TEST\"' ORIGINAL FILTER TAG
      word canonical=':debug' raw=':debug' ORIGINAL HINT FILTER

  >> 2020-02.data: 0 intervals
  >> 1970-01.data: 0 intervals
  >> 1969-12.data: 0 intervals
  >> Loaded 0 tracked intervals
  Note: '"\\"TEST\\""' is a new tag.
  >> Datafile::addInterval() failed.
  >> Encode / decode check failed:
  >>   inc 19700101T060000Z # "\\"TEST\\""
  >> is not equal to:
  >>   inc 19700101T060000Z # "TEST\\\"\"" \
  Internal error. Failed encode / decode check.
  >> Timer timew 0.002137 sec

Closes #290
Related to #159

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-04 07:44:05 +01:00
Shaun Ruffell
fda978c8cc Support multiline debug log messages
With this change, if there are debug messages that are multiple lines, each line
will be prefaced with the '>>' marker.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-04 07:44:05 +01:00
Shaun Ruffell
1b968e8aa3 Interval: Add operators == and !=
Can be used to check the database format before committing.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
2020-03-04 07:44:05 +01:00
Thomas Lauf
bf87509329 Handle case of empty interval, fix tests
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-03 22:24:45 +01:00
Johannes Hertenstein
da27fdcdf0 285: Pass interval id to extensions 2020-03-03 22:23:21 +01:00
Thomas Lauf
e8511c5efd Extract function CLI::getDuration ()
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-03 07:58:04 +01:00
Thomas Lauf
0c1d7291e2 Use <..> instead of ".." for #include statements
Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-03 07:57:33 +01:00
Thomas Lauf
368d033ce5 Rename atomic to AtomicFileTest
- Avoid possible clash with lib atomic on macOS, e.g. in /Library/Developer/CommandLineTools/usr/include/c++/v1/memory:668

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-02 21:42:53 +01:00
Thomas Lauf
551964eb15 Fix check for libfiu usage
- on macOS, use "otool -L" instead of "ldd"

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
2020-03-01 21:08:32 +01:00