事象
例えば下記のfunctionをトリガー実行すると予期せぬエラーが起こる。
function hogehoge(offsetDays = -1) {
Logger.log(offsetDays)
const baseDate = new Date();
baseDate.setDate(baseDate.getDate() + offsetDays); // offsetDaysを適用
console.log(baseDate)
}
トリガー実行時の結果の例
{month=2.0, hour=14.0, day-of-week=4.0, timezone=UTC, week-of-year=6.0, day-of-month=6.0, year=2025.0, authMode=FULL, second=5.0, minute=5.0, triggerUid=~~~~~~~}
解決策
function hogehoge() {
offsetDays = -1 // ★ここに入れる
Logger.log(offsetDays)
const baseDate = new Date();
baseDate.setDate(baseDate.getDate() + offsetDays); // offsetDaysを適用
console.log(baseDate)
}
結論
トリガー実行するときは無名関数にしておいた方が安全で