Timewarrior - Commandline Time Tracking and Reporting timewarrior.net https://timewarrior.net
Find a file
Scott Mcdermott 251c5b332a Make week number parsing conform to ISO8601 when Datetime::weekstart == 1
This is a duplicate of the changes from commit with same subject line in
GothenburgBitFactory/libshared#81 and also duplicates the commit
message below.  Timewarrior has copies of many functions from
libshared's Datetime class in its own DatetimeParser class, and until
such time as these classes are integrated, we have to maintain copies of
these functions here, and the changes need to be duplicated.  See
discussion in aforementioned PR.

The one difference with the patch over there is, this one is using the
public Datetime::dayOfWeek() and Datetime::daysInYear() methods from
libshared, rather than its own implementation.  The copy in Timewarrior
already was doing this before, but it's worth noting it's the only
difference with the corresponding patch in libshared PR 81, and only
amounts to a change in the namespace qualifier.

Copied commit message from libshared follows.

                           *     *    *

This patch makes the parsing of week numbers in dates ISO-8601 compliant
in the case that Datetime::weekstart == 1, while the existing behavior
remains available if Datetime::weekstart == 0.

The previous code parsed week numbers (given as "yyyy-Www") into dates
starting on Sunday.  Although the code had a "Datetime::weekstart"
variable, and this value was initialized to 1 (which is Monday) in
libshared, nonetheless week specifications would be parsed into calendar
days starting on Sunday.

Furthermore, week days in such given weeks ('d' in "yyyy-Www-d") used 0-6
for Sunday-Monday, while ISO8601 specifies 1-7 Monday-Sunday.
Therefore, yyyy-Www-0 was treated as valid (and should not be), while
yyyy-Www-7 was invalid (and should be valid).

Note that neither Taskwarrior nor Timewarrior ever set the value of
Datetime::weekstart.  Taskwarrior has an rc.weekstart, but this is only
used for "task calendar" output, not for parsing dates.

The patch does the following:

- Initialize "Datetime" instances with a weekday value from
  Datetime::weekstart.  This helps the case when weekday is not
  supplied, it won't default to zero and fail validation (when
  weekstart is '1').  Note that mktime() is usually used in the code
  to convert populated "struct tm" broken-down times into epoch-times,
  and this operation does not use tm.tm_wday for input, only as an
  output field, recomputed as a normalized value, so it appears to be
  safe to initialize it with a 1 (which we might wonder about since
  .tm_wday is supposed to be 0-6 Sunday based).

- Use the already-existing Datetime::parse_weekday() to parse the
  'ww' in "yyyy-Www" input dates (the function was not used by any
  caller previously; guessing it may have been intended for eventual
  use in order to respect weekstart(?))

- Teach parse_weekday() about weekstart.  Previously this assumed
  1-7, which is the reason I'm guessing this was intended to be used
  for ISO weeks eventually.  Now it can also use 0-6 if weekstart 0.

- Teach Datetime::validate to respect Datetime::weekstart also.
  Previously only 0-6 Sunday-Monday was considered valid.

- Default the weekday to Datetime::weekstart if not supplied, ie for
  "yyyy-Www-X" if the "-X" is not supplied, as recognized when
  Datetime::standaloneDateEnabled = true, which is the case for (1)
  tests, (2) timewarrior, but NOT for taskwarrior at this time
  (both the standalone 'calc' and 'task calc' (ie Context.cpp) set
  this to false).

- Implement the complete ISO week calculation algorithm in
  Datetime::resolve() if weekstart is '1', and keeps the existing
  algorithm if weekstart is '0'.  This will allow Taskwarrior and
  Timewarrior to offer the option of the old behavior for those
  who want to use Sunday-based weeks and ignore ISO week calculations
  (such as 2023-01-01 being in ISO week 2022-W52).

Signed-off-by: Scott Mcdermott <scott@smemsh.net>
2024-09-13 14:27:50 +02:00
.github Bump docker/build-push-action from 6.5.0 to 6.7.0 2024-08-17 11:10:43 +02:00
cmake Update project to C++17 2023-06-17 08:41:07 +02:00
completion Adding zsh completion 2024-06-17 23:04:52 +02:00
doc Remove custom linkstyle 2024-05-27 10:05:44 +02:00
docker Add workflow for Timewarrior Docker image 2023-01-05 23:20:00 +01:00
ext Update task-timewarrior-hook script to 87a3426d8153f92aaee2edf36b2de62e48c4de0e 2023-12-22 23:13:13 +01:00
src Make week number parsing conform to ISO8601 when Datetime::weekstart == 1 2024-09-13 14:27:50 +02:00
test Jettison centos7 and centos8 in favor of centos-stream9 2024-06-05 20:26:22 +02:00
.gitignore Clean up .gitignore files 2019-04-10 12:08:42 +02:00
.gitmodules Changed URL for libshared 2018-02-18 11:16:38 +01:00
.pre-commit-config.yaml Add empty '.pre-commit-config.yaml' 2024-08-17 10:33:25 +02:00
AUTHORS Update ChangeLog & AUTHORS 2024-06-17 23:10:27 +02:00
ChangeLog Update ChangeLog & AUTHORS 2024-06-17 23:10:27 +02:00
cmake.h.in Remove reference to 'TIMEW_RCDIR' 2023-06-17 14:19:02 +02:00
CMakeLists.txt Enter commit hash for release 1.7.1 2024-01-16 21:26:51 +01:00
commit.h.in Framework: Added program framework and UTF8 code 2015-12-10 09:31:48 -05:00
CONTRIBUTING.md Fix grammar and spelling 2023-06-17 14:19:02 +02:00
DCO Fix spelling 2023-01-07 18:58:42 +01:00
docker-compose.yml Jettison centos7 and centos8 in favor of centos-stream9 2024-06-05 20:26:22 +02:00
INSTALL Improve configurability of CMake install directories 2023-08-11 15:30:26 +02:00
LICENSE Update copyrights 2023-04-04 22:44:44 +02:00
README.md Release 1.7.1 2024-01-16 13:35:02 +01:00

Timewarrior logo

Tests Release Release date Commits since release
Twitter

Timewarrior

macOS downloads GitHub downloads Linux downloads

Thank you for taking a look at Timewarrior!

Timewarrior is a time tracking utility that offers simple stopwatch features as well as sophisticated calendar-based backfill, along with flexible reporting. It is a portable, well-supported and very active Open Source project.

Please visit timewarrior.net for extensive documentation, downloads, news and more.

Installing

Arch Linux Debian Fedora Homebrew Ubuntu

From Package

Thanks to the community, there are binary packages available here.

Building Timewarrior

Building Timewarrior yourself requires

  • Git
  • CMake (>= 3.8)
  • Make
  • C++ compiler with full C++17 support, currently GCC 8+ or Clang 5+
  • Python 3 (for running the testsuite)
  • Asciidoctor (for creating documentation)

There are two ways to retrieve the Timewarrior sources:

  • Clone the repository from GitHub and update required submodules,
    git clone --recurse-submodules https://github.com/GothenburgBitFactory/timewarrior
    cd timewarrior
    
  • Or download the tarball with curl,
    curl -O https://github.com/GothenburgBitFactory/timewarrior/releases/download/v1.7.1/timew-1.7.1.tar.gz
    
    and expand the tarball
    tar xzf timew-1.7.1.tar.gz
    cd timew-1.7.1
    

Build Timewarrior, optionally run the test suite, and install it.

cmake -DCMAKE_BUILD_TYPE=release .
make
[make test]
sudo make install

This copies files into the right place (default under /usr/local), and installs man pages.

Add the optional parameter -DCMAKE_INSTALL_PREFIX=/path/to/your/install/location to the cmake command if you want to install Timewarrior at a location other than /usr/local. The make install command may not require sudo depending on your choice of install location.

Community

Twitter Reddit Libera.chat Discord GitHub discussions

Timewarrior has a lively community on many places on the internet. The project has its own Twitter account, and shares community spaces on IRC and Discord with Taskwarrior.

Best place to ask questions is our discussions forum on GitHub. For other support options, take a look at timewarrior.net/support

Contributing

Contributors Milestone progress Good first issues

Contributions are greatly appreciated. Whether in the form of code patches, ideas, discussion, bug reports, encouragement or criticism, we need you!

For support options, take a look at CONTRIBUTING.md or visit timewarior.net.

Visit GitHub and participate in the future of Timewarrior.

License

Timewarrior is released under the MIT license. For details check the LICENSE file.