Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
d2718nis opened this issue Oct 23, 2024 · 5 comments
Open

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

d2718nis opened this issue Oct 23, 2024 · 5 comments

Comments

@d2718nis
Copy link

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
Copy link
Contributor

smemsh commented Oct 23, 2024

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 d389bba

@smemsh
Copy link
Contributor

smemsh commented Oct 23, 2024

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?!? 🤔

@smemsh
Copy link
Contributor

smemsh commented Oct 23, 2024

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
Copy link
Author

Built it from sources (d389bba and GothenburgBitFactory/libshared@a63fa35), 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
Copy link
Contributor

smemsh commented Oct 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants