创建链接以将事件添加到yahoo calandar

问题描述 投票:0回答:1

我想生成一个链接,以将事件添加到yahoo日历。我正在关注此documentation。我的脚本看起来像这样。

  var MS_IN_MINUTES = 60 * 1000;

  var formatTime = function (date) {
     return date.toISOString().replace(/-|:|\.\d+/g, '');
  };

  var calculateEndTime = function (event) {
      return event.end ?
             formatTime(event.end) :
             formatTime(new Date(event.start.getTime() + (event.duration * MS_IN_MINUTES)));
        };

  var yHDuration = (Number(Duration.split(':')[0]) * 60 + Number(Duration.split(':')[1]));

  var event = {
      title: 'Get on the front page of HN',     // Event title
      start: new Date(MeetingTime),   // Event start date
      duration: yHDuration,                            // Event duration (IN MINUTES)
      // If an end time is set, this will take precedence over duration
      address: 'The internet',
      description: 'Get on the front page of HN, then prepare for world domination.',
  }

  var eventDuration = event.end ?
      ((event.end.getTime() - event.start.getTime()) / MS_IN_MINUTES) :event.duration;

  // Yahoo dates are crazy, we need to convert the duration from minutes to hh:mm
  var yahooHourDuration = eventDuration < 600 ?
      '0' + Math.floor((eventDuration / 60)) :
      Math.floor((eventDuration / 60)) + '';

  var yahooMinuteDuration = eventDuration % 60 < 10 ?
      '0' + eventDuration % 60 :
      eventDuration % 60 + '';

   var yahooEventDuration = yahooHourDuration + yahooMinuteDuration;

      // Remove timezone from event time
      var st = formatTime(new Date(event.start - (event.start.getTimezoneOffset() *
      MS_IN_MINUTES))) || '';

   var href = encodeURI([
       'http://calendar.yahoo.com/?v=60&view=d&type=20',
       '&title=' + (event.title || ''),
       '&st=' + '20200611225200',
       '&dur=' + (yahooEventDuration || ''),
       '&desc=' + (event.description || ''),
       '&in_loc=' + (event.address || ''),
        '&invitees=' + (InviteesArr || ''),
    ].join(''));

   var link = '<a class="icon-yahoo" target="_blank" href="' +
       href + '">Yahoo! Calendar</a>';

   console.log(link);

[我的开始时间看起来像是6/12/2020 11:06:00 AM。生成link is like this。持续时间是正确的。但是开始时间不正确。我对

感到困惑
st

参数和使用时区。

javascript yahoo
1个回答
0
投票

我想您需要的是,因为当您已经将正确的开始日期存储在变量&st=中时,会将字符串传递给st查询参数:

var href = encodeURI([
       'http://calendar.yahoo.com/?v=60&view=d&type=20',
       '&title=' + (event.title || ''),
       '&st=' + (st || ''),
       '&dur=' + (yahooEventDuration || ''),
       '&desc=' + (event.description || ''),
       '&in_loc=' + (event.address || ''),
        '&invitees=' + (InviteesArr || ''),
    ].join(''));

并回答您有关st的问题。如果您查看本文-Date.prototype.getTimezoneOffset(),则表示该方法将时区差(以分钟为单位)从当前语言环境(主机系统设置)返回到UTC。

如果您将日期与Parse date without timezone javascript 一起返回的分钟数乘以getTimeOffset()中存储的毫秒数,然后检查了该帖子MS_IN_MINUTES的第二个答案,则对于所有用户而言,您的日期必须在全球范围内正常工作。

© www.soinside.com 2019 - 2024. All rights reserved.