0

イベントの 1 週間前に通知をスケジュールますevent.date。ここに 3 つの例を示します。上位 2 つは機能するが望ましくないもので、3 つ目は私が望んでいたことに対する非機能的な試みです。

notify.js:

SyncedCron.add({
    name: id,
    schedule: function(parser) {

        // 1) This works as expected (but not what I want)
        // Returns notification at 00:00 same date as event.

        return parser.recur().on(event.date).fullDate();


        // 2) This works as expected (but not what I want)
        // Returns notification at 06:00 today.

        return parser.recur().on(6).hour().before(event.date).fullDate();


        // 2) This, and other permutations tried, does not work
        // returns error: "Exception while invoking method 
        // 'scheduleNotification' TypeError: Cannot call method 
        // 'getTime' of undefined"

        return parser.recur().hour(6).before(event.date).fullDate();
    },
    job: function() {
        notify();
    }
});

日付オブジェクトの前に特定の時間に通知を設定する方法を誰かが提案できますか? ありがとう!

4

1 に答える 1

0

最終的に、後で特別なプロパティを呼び出すのではなく、標準の JavaScript 関数を使用して event.date を変更しました。

    schedule: function(parser) {
        var notificationDate = event.date;
        notificationDate.setDate(event.date.getDate() - 7);
        notificationDate.setHours(19);
        return parser.recur().on(eventDate).fullDate();
            .and()
            .on(event.date).fullDate();
    },

したがってnotificationDate、特定のイベント日付に対して相対的に設定されます。

于 2015-08-26T21:26:34.993 に答える