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

wrong times for events after DST change #142

Open
arekfu opened this issue Oct 11, 2018 · 9 comments
Open

wrong times for events after DST change #142

arekfu opened this issue Oct 11, 2018 · 9 comments

Comments

@arekfu
Copy link

arekfu commented Oct 11, 2018

I am in the CEST (UTC+2) time zone. We are on Daylight Saving Time until the last Sunday in October, when we will switch to CET (UTC+1). (Google) Calendar events planned after the time switch are shown in CEST time; so, for instance, I have a meeting at 2:00 PM on 5th November which calendar.vim shows at 3:00 PM. I think the event time should rather appear in the time zone which will be in use on that day.

@itchyny
Copy link
Owner

itchyny commented Oct 11, 2018

This is same as #95 and is a known issue. But I'm not planning to support DST switch in the near future, sorry.

@arekfu
Copy link
Author

arekfu commented Oct 12, 2018

Would you accept a PR about this feature?

@rtega
Copy link

rtega commented Jan 17, 2023

The solution to this problem is probably rather simple. You can define timezone as a +/- hour:minute or as "Europe/Amsterdam". The first definition is fixed and doesn't keep track of DST. If you use the second definition google calendar automatically takes care of DST.

As a proof of concept, you can verify with calendar.vim that this works by changing the definition of set_timezone here

function! s:set_timezone(calendarId, obj) abort
to the following:

function! s:set_timezone(calendarId, obj) abort
  let a:obj.timeZone = 'Europe/Brussels'
endfunction

Now all changes and additions are done according to DST. This doesn't take care of how the hours in the calendar are shown though. Somewhere (I couldn't find where) this must be changed to the +/-hour:minute-suffix format. As far as I know, google calendar returns the time according to the timezone set in the calendar.

@rtega
Copy link

rtega commented Jan 18, 2023

Found where the time is corrected. You could change this line and make timezone (defined +/- hour:minute) dependent one the date and time to be converted:

let time_zone = calendar#time#time_zone()

From vim v8.1.2326 there is the strptime function that can be used for this:
let time_zone = strftime("%z",strptime("%Y-%m-%dT%H:%M%z",a:str))

@rtega
Copy link

rtega commented Jan 18, 2023

In short, with this fix you'll probably want to remove this line:

let s:t = strftime('%z')

and each time calendar#setting#get('time_zone') is invoked check whether it is set. If it's not run time_zone = strftime("%z",strptime("%Y-%m-%dT%H:%M%z",time_string)) or equivalent to check the correct offset according to DST.

@rtega
Copy link

rtega commented Jan 19, 2023

Basically not that terribly difficult. You need two changes:

One here:

function! calendar#time#time_zone() abort

change the first two lines in this function

function! calendar#time#time_zone(str) abort
  let time_zone = strftime("%z",strptime("%Y-%m-%dT%H:%M:%S%z",a:str))

and add code to pass the original string from the datetime function. I've attached the changed file. You would probably also have to add code to check that a:str is in the correct format to be read by strptime.

And a oneliner here:

let timezone = calendar#setting#get('time_zone')

into

let timezone = has_key(a:obj,'dateTime') ? strftime("%z",strptime("%Y-%m-%dT%H:%M:%S",a:obj.dateTime)) : has_key(a:obj,'date') ? strftime("%z",strptime("%Y-%m-%d",a:obj.date)) : ''

I would propose that you check first whether calendar#setting#get('time_zone') returns something, if not do the strftime/strptime thing with the passed string.
time.vim.gz

@rtega
Copy link

rtega commented Feb 17, 2023

Been using this solutions for a month now. It seems to work without any problems.

@rionda
Copy link

rionda commented Feb 23, 2023

It would be very cool if we could get this in.

@rionda
Copy link

rionda commented Feb 23, 2023

The problem seems more serious than just a matter of display.

I added today (well before DST change) an event in late March (after the DST change for where I am) by pressing i and writing 3/27 10:00-17:00, but the event was added to google as being between 11:00 and 18:00. This seems quite confusing, and certainly would lead to errors...

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

No branches or pull requests

4 participants