当添加到基于时区的日历时,ICS会调整日期 [英] ICS will adjust date when add to calendar base on timezone

查看:91
本文介绍了当添加到基于时区的日历时,ICS会调整日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经下载了一个PHP脚本,该脚本可以让我为预定的网络研讨会生成可下载的ICS.日期和时间设置为WP ACF发布.此外,WordPress时区设置为America/Los_Angeles.但是我的时区位于PH的马尼拉.

I've downloaded a PHP script that allow me to generate downloadable ICS for a scheduled webinar. Date & time is set to WP ACF post. Also, WordPress timezone was set to America/Los_Angeles. But my timezone is based in Manila, PH.

这是代码.

// ACF Date
$wdate = get_sub_field('date'); // Tuesday, June 16, 2020
$stime = get_sub_field('start_time'); // 11:00 am
$etime = get_sub_field('end_time'); // 11:30 am

// Prepare Date using date_i18n()
// Starting DateTime
$st_gmt = $wdate.' '.$stime;
$st = get_date_from_gmt($st_gmt, 'Y-m-d H:i:s');
$date_start = date_i18n(get_option('date_format').' '.get_option('time_format'), strtotime($st));
// Output: June 16, 2020 11:00 AM

// Ending DateTime
$et_gmt = $wdate.' '.$etime;
$et = get_date_from_gmt($et_gmt, 'Y-m-d H:i:s');
$date_end = date_i18n(get_option('date_format').' '.get_option('time_format'), strtotime($et));
// Output: June 16, 2020 11:30 AM

每当我测试下载.ics日历文件时,该文件应为 2020年6月17日2:00 AM&2020年6月17日凌晨2:30 ,但输出始终设置为 2020年6月16日7:00 PM&2020年6月16日下午7:30 ,因为我来自PH的马尼拉,而活动却定于洛杉矶.

Whenever I test downloading the .ics calendar file, which it should be June 17, 2020 2:00 AM & June 17, 2020 2:30 AM but the output is always set to June 16, 2020 7:00 PM & June 16, 2020 7:30 PM since I am based from Manila, PH while the event was set to Los Angeles.

这是实际ICS文件的输出.

Here's the output from actual ICS file.

BEGIN:VCALENDAR
VERSION:2.0
X-WR-TIMEZONE:America/Los_Angeles
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
CALSCALE:GREGORIAN
BEGIN:VTIMEZONE
TZID:America/Los_Angeles
END:VTIMEZONE
BEGIN:VEVENT
LOCATION:Webinar Zoom
DESCRIPTION:This is my description
DTSTART:20200616T110000Z
DTEND:20200616T113000Z
SUMMARY:This is my summary
URL;VALUE=URI:
DTSTAMP:20200603T051015Z
UID:5ed6c0375fbf6
END:VEVENT
END:VCALENDAR

问题:当用户下载ics文件并将其添加到他们的日历时,如何输出该文件以匹配用户所在的时区?

Question: How can I output the ics file to match users timezone when they download the file and add to their calendar?

推荐答案

我假设您尚未明确询问的问题是时间如何关联.

I assume the question that you have not yet explicitly asked is how the times relate.

首先请注意,ics VTIMEZONE用于时区定义,即,当实际的夏时制发生变化时,它并不表示该事件是在LA时间中进行的.如果DST与该时区相关,则IT实际上应该包含一系列夏令时.参见 https://icalendar.org/iCalendar-RFC-5545/3-6-5-time-zone-component.html

Note first that an ics VTIMEZONE is intended for a timezone definition ie when the actual daylight saving changes are, it is not used to say that the event is in LA time. IT should actually contain a series of daylight saving dates IF DST is relevant in that timezone. See https://icalendar.org/iCalendar-RFC-5545/3-6-5-time-zone-component.html

VTIMEZONE对VEVENTS的开始和结束时间一无所知.

A VTIMEZONE says nothing about the VEVENTS start and end times.

在此文件中,事件DTSTART是在上午11点的UTC时间(参见Z?)中定义的.这相当于洛杉矶时间凌晨4点和马尼拉下午7点.请参阅DATETIME的表格2: https://icalendar.org/iCalendar-RFC-5545/3-3-5-date-time.html
和这里的时差

In this file the event DTSTART is defined in UTC time (see the Z?) of 11 am This is the equivalent of LA at 4am and Manila at 7pm. See Form 2 of DATETIME: https://icalendar.org/iCalendar-RFC-5545/3-3-5-date-time.html
and here for time differences https://www.timeanddate.com/worldclock/meetingdetails.html?year=2020&month=6&day=16&hour=11&min=0&sec=0&p1=137&p2=145

时间在应用程序中的显示方式取决于用户和应用程序的时区.应用程序应将ics事件时间转换为用户时区.

How the times appear in an application depend then on the timezone of the user and application. The application should convert the ics event time to the users timezone.

这篇关于当添加到基于时区的日历时,ICS会调整日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆