GothenburgBitFactory / timewarrior

Timewarrior - Commandline Time Tracking and Reporting
https://timewarrior.net
MIT License
1.27k stars 96 forks source link

Datetime range ignores +/-hh:mm timezone ISO format specification #638

Open d2718nis opened 1 month ago

d2718nis commented 1 month ago

Summary

When adding time entries to Timewarrior, the +/-hh:mm timezone ISO format specification seems to be ignored, even though it is mentioned as a valid method in both man 7 timew-dates and the online documentation.

Details

There is no difference in behavior between adding a time entry with a timezone set to +00:00 (UTC):

$ timew track 2024-10-23T13:02:10+00:00 - 2024-10-23T13:32:10+00:00 'Some task'                           
Recorded "Some task"                                                                                                                                        
  Started 2024-10-23T13:02:10                                                                                                                               
  Ended                 32:10                                                                                                                               
  Total               0:30:00

$ timew summary :ids                                                                                                               

Wk  Date       Day ID Tags                                                                     Start      End    Time   Total                               
W43 2024-10-23 Wed @1 Some task                                                             13:02:10 13:32:10 0:30:00

 $ timew @1 export
[
{"id":1,"start":"20241023T090210Z","end":"20241023T093210Z","tags":["Some task"]}
]

Or like this, with the timezone set to +04:00 (Asia/Tbilisi):

$ timew track 2024-10-23T13:02:10+04:00 - 2024-10-23T13:32:10+04:00 'Some task'
Recorded "Some task"
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

$ timew summary :ids

Wk  Date       Day ID Tags                                                                     Start      End    Time   Total
W43 2024-10-23 Wed @1 Some task                                                             13:02:10 13:32:10 0:30:00

$ timew @1 export
[
{"id":1,"start":"20241023T090210Z","end":"20241023T093210Z","tags":["Some task"]}
]

Expected behavior

Setting a datetime range with a valid timezone format should result in a correct datetime database entry, including the specified timezone if provided.

Environment

$ timew --version
1.7.1

$ python --version
Python 3.12.7

$ uname -a
Linux host 6.11.4-arch2-1 #1 SMP PREEMPT_DYNAMIC Sun, 20 Oct 2024 18:20:12 +0000 x86_64 GNU/Linux

$ timedatectl
               Local time: Wed 2024-10-23 20:36:51 +04
           Universal time: Wed 2024-10-23 16:36:51 UTC
                 RTC time: Wed 2024-10-23 16:36:51
                Time zone: Asia/Tbilisi (+04, +0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
smemsh commented 1 month ago

They are different for me:

 $ t=(2024-10-23T13:{02,32}:10+0{0,4}:00)

 $ echo ${times[@]} | fmt -1
2024-10-23T13:02:10+00:00
2024-10-23T13:02:10+04:00
2024-10-23T13:32:10+00:00
2024-10-23T13:32:10+04:00

 $ timew track ${t[0]} - ${t[2]} :yes
Recorded 
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

 $ timew track ${t[1]} - ${t[3]} 
Recorded 
  Started 2024-10-23T02:02:10
  Ended                 32:10
  Total               0:30:00

 $ timew export
[
{"id":2,"start":"20241023T090210Z","end":"20241023T093210Z"},
{"id":1,"start":"20241023T200210Z","end":"20241023T203210Z"}
]

I'm using timewarrior build from d389bba7

smemsh commented 1 month ago

Come to think of it, the exported zulu timestrings seem to be wrong anyways, but for a different reason: they should only differ by 4 hours (+00:00 vs +04:00), but they differ by 11 hours?!? :thinking:

smemsh commented 1 month ago

they are determined correctly by libshared:

 $ for off in 0 4
> do TZ=UTC task3 calc 2024-10-23T13:02:10+0$off:00; done
2024-10-23T13:02:10
2024-10-23T09:02:10

feels like I'm missing something, but not sure what.

d2718nis commented 1 month ago

Built it from sources (https://github.com/GothenburgBitFactory/timewarrior/commit/d389bba72cc38edf142efc481bfe6645c0b9610b and https://github.com/GothenburgBitFactory/libshared/commit/a63fa350413f598b3b55355a6460b7fd2efb2e69), here are the results:

$ ./src/timew --version
1.7.1-dev

$ t=(2024-10-23T13:{02,32}:10+0{0,4}:00)

$ ./src/timew track ${t[0]} - ${t[2]} :yes
Recorded 
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

$ ./src/timew track ${t[1]} - ${t[3]}
You cannot overlap intervals. Correct the start/end time, or specify the :adjust hint.

$ ./src/timew export
[
{"id":1,"start":"20241023T090210Z","end":"20241023T093210Z"}
]

But then using +1hr:

$ ./src/timew track 2024-10-23T14:02:10+04:00 - 2024-10-23T14:32:10+04:00
Recorded 
  Started 2024-10-23T14:02:10
  Ended                 32:10
  Total               0:30:00

$ ./src/timew export
[
{"id":2,"start":"20241023T090210Z","end":"20241023T093210Z"},
{"id":1,"start":"20241023T100210Z","end":"20241023T103210Z"}
]

This is also calculated correctly for me:

$ for off in 0 4; do TZ=UTC task calc 2024-10-23T13:02:10+0$off:00; done
2024-10-23T13:02:10
2024-10-23T09:02:10

I feel like it is related to TZ env var not being set on my system, should it though? Here's an example:

$ env | grep TZ

$ TZ=UTC ./src/timew track ${t[0]} - ${t[2]} :yes
Recorded 
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

$ TZ=UTC ./src/timew track ${t[1]} - ${t[3]} :yes
Recorded 
  Started 2024-10-23T09:02:10
  Ended                 32:10
  Total               0:30:00

 $ ./src/timew export
[
{"id":2,"start":"20241023T090210Z","end":"20241023T093210Z"},
{"id":1,"start":"20241023T130210Z","end":"20241023T133210Z"}
]
smemsh commented 1 month ago

TZ=UTC was only because task calc would print in the localized time (ie your /etc/localtime), and for the purposes of display here I wanted to show what timezone was being used for output. Setting the time zone should make no difference for timew track if you are specifying the time zone of the input using the + syntax, which should be an absolute time. If it does, that seems like a bug.

Indeed it does:

 $ t=(2024-10-23T13:{02,32}:10+0{0,4}:00)

 $ TZ=Asia/Tbilisi timew track ${t[0]} - ${t[2]} :yes
Recorded 
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

 $ TZ=Asia/Tbilisi timew track ${t[1]} - ${t[3]}
You cannot overlap intervals. Correct the start/end time, or specify the :adjust hint.

 $ rm -rf .local/share/timewarrior

 $ TZ=US/Pacific timew track ${t[0]} - ${t[2]} :yes
Recorded 
  Started 2024-10-23T13:02:10
  Ended                 32:10
  Total               0:30:00

 $ TZ=US/Pacific timew track ${t[1]} - ${t[3]}
Recorded 
  Started 2024-10-23T02:02:10
  Ended                 32:10
  Total               0:30:00

I think it is definitely a bug. The local timezone should only be used when we aren't providing the timezone of the input date in the date itself.