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

Put all-day events into the right timezone #104

Closed
nmlorg opened this issue Jul 18, 2024 · 1 comment
Closed

Put all-day events into the right timezone #104

nmlorg opened this issue Jul 18, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@nmlorg
Copy link
Owner

nmlorg commented Jul 18, 2024

Someone just added an event to their calendar for someone's birthday (on Sat, Jul 20), and it's being treated as a 24-hour event from 5 p.m. tomorrow (Fri, Jul 19) until 5 p.m. the next day because the API returns:

items:
- created: '2024-07-18T15:44:44.000Z'
  description: ...
  end:
    date: '2024-07-21'
  eventType: default
  kind: calendar#event
  reminders:
    useDefault: false
  sequence: 0
  start:
    date: '2024-07-20'
  status: confirmed
  summary: ...
  transparency: transparent
  updated: '2024-07-18T15:44:56.837Z'
kind: calendar#events
timeZone: America/Los_Angeles
updated: '2024-07-18T15:44:56.837Z'

and m.c.google.Calendar.datetime_proto_to_local just passes '2024-07-20' through:

def totimestamp(isoformat):
"""Convert a string like YYYY-MM-DDTHH:MM:SS+HH:MM to the number of seconds since 1970-01-01."""
year, month, day, _, hour, minute, second, fraction, _, utchour, utcminute = re.match(
r'(\d{4})-?(\d{1,2})-?(\d{1,2})'
r'(T(\d{1,2}):?(\d{1,2}):?(\d{1,2})'
r'([.]\d+)?'
r'(([-+]\d{1,2}):?(\d{1,2})|Z)?'
r')?$', isoformat).groups()
dtime = datetime.datetime(int(year), int(month), int(day), int(hour or 0), int(minute or 0),
int(second or 0), int(1000000 * float(fraction or 0)))
if utchour and utcminute:
tzinfo = _TimeZone(int(utchour) + float(utcminute) / 60)
else:
tzinfo = _UTC
return (dtime.replace(tzinfo=tzinfo) - _EPOCH).total_seconds()

which correctly (if naively) gives midnight UTC on 2024-07-20 (which is 5 p.m. the day before in America/Los_Angeles).

Somewhat weirdly, non-all-day events include time zone information in both the date spec and a separate timeZone field:

  end:
    dateTime: '2024-07-20T19:30:00-07:00'
    timeZone: America/Los_Angeles
  start:
    dateTime: '2024-07-20T14:30:00-07:00'
    timeZone: America/Los_Angeles

and m.c.google just relies on m.u.iso8601 extracting the '-07:00' to adjust things correctly. However, while all-day events don't include any time zone information at all, service.events().list() still returns the calendar's default time zone, so theoretically that could be extracted and bundled in (though that would mean m.u.iso8601 would either need to switch entirely over to using pytz, or use two entirely different approaches for doing time zone calculations).


It is possible for a calendar to have one default time zone and a Telegram group to configure the bot to present events in a different time zone, in which case even with the above the events will still not run midnight to midnight.

Alternatively, the all-day nature of the event could be preserved all the way out to m.u.eventutil.format_event, but I'm leaning toward ignoring this until I see it actually happening. (All-day events in general are pretty rare in practice.)

@nmlorg nmlorg added the bug Something isn't working label Jul 18, 2024
@nmlorg nmlorg self-assigned this Jul 18, 2024
nmlorg added a commit to nmlorg/metabot.calendars.google that referenced this issue Jul 19, 2024
nmlorg added a commit that referenced this issue Jul 19, 2024
nmlorg added a commit to nmlorg/metabot.calendars.google that referenced this issue Jul 19, 2024
nmlorg added a commit to nmlorg/metabot.calendars.google that referenced this issue Jul 19, 2024
…midnight to midnight in that time zone, rather than UTC.

See nmlorg/metabot#104.

Release as 0.2.1.
@nmlorg
Copy link
Owner Author

nmlorg commented Jul 19, 2024

Updated:
XXX’s Birthday was moved back to Sat 20ᵗʰ, 12ᵃᵐ (from Fri 19ᵗʰ, 5ᵖᵐ; same duration).

@nmlorg nmlorg closed this as completed Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant