みかづきブログ その3

本ブログは更新を終了しました。通算140万ユーザーの方に観覧頂くことができました。長い間、ありがとうございました。

👆

引越し先はこちらです!

Googleカレンダーに予定を登録するリンクをつくる

http://www.google.com/calendar/event?action=TEMPLATE&text={タイトル}&details={説明}&location={場所}&dates={開始時間/終了時間}

という形でGoogleカレンダーに予定を登録するURLを作成できるようです。

datesの形式は、

{yyyy}{mm}{dd}T{hh}{mm}/{yyyy}{mm}{dd}00T{hh}{mm}00

yyyy: 4桁の西暦
mm: 2桁の月
dd: 2桁の日
hh: 2桁の時間(24時間表記)
mm: 2桁の分

という感じで、例えば 2015年3月6日18:00 から 2015年3月6日18:30 までの予定であれば、

20150306T180000/20150306T183000

となります。

上記予定が「会議室」で行われる「それなりに重要な会議」であれば、

http://www.google.com/calendar/event?action=TEMPLATE&text=それなりに重要な会議&details=それなりに重要ですよ。&location=会議室&dates=20150306T180000/20150306T183000

となります。

リンクにすると、

<a href="http://www.google.com/calendar/event?action=TEMPLATE&text=それなりに重要な会議&details=それなりに重要ですよ。&location=会議室&dates=20150306T180000/20150306T183000">それなりに重要な会議にそれなりに参加する</a>

という感じになります。

そして実際につくってみたものが、こちらです。

それなりに重要な会議にそれなりに参加する

※ 本当は横着せずに日本語のところをエンコードすべきなんですが、モックなのでさくっとつくってみました。

これを応用して、明日8時に起きるという予定を登録するためだけのページをつくってみました。

DEMO


JavaScript

(function(win, doc) {

    "use strict";
    
    var tomorrow = new Date(Date.now() + 24 * 60 * 60 * 1000),
        param = {
            text : "おきる",
            details : "頑張って起きる",
            location : "ふとん",
            dates : {
                start : tomorrow.getFullYear() + "" +  ("0" + (tomorrow.getMonth() + 1)).slice(-2) + ("0" + tomorrow.getDate()).slice(-2) + "T080000",
                end : tomorrow.getFullYear() + "" + ("0" + (tomorrow.getMonth() + 1)).slice(-2) + ("0" + tomorrow.getDate()).slice(-2) + "T080500"
            }
        },
        btn = doc.getElementById("btn"),
        link = "http://www.google.com/calendar/event?action=TEMPLATE";
    
    link += "&text=" + param.text;
    link += "&details=" + param.details;
    link += "&location=" + param.location;
    link += "&dates=" + param.dates.start + "/" +  param.dates.end;
    
    btn.addEventListener("click", function() {
        win.open(link);
    }, false);
    
})(this, document);

なにかに活用できるようなできないようなですね。