extension/src/goSurvey: fix a bug in HaTS survey prompting
Once a month, the extension picks the date to prompt if the
user is chosen for HaTS survery. The extension then arranges
setTimeout to prompt after the picked date.
The picked date is stored in `dateToPromptThisMonth` (memento)
so we can continue the timer even when vscode restarts.
However, there was a bug that miscompute the wait time for
setTimeout. If `dateToPromptThisMonth` has already passed,
it waited for now-dateToPromptThisMonth, which was unintended
and unnecessary. Fix it.
It's posible that this can increase # of HaTS survey
responders slightly.
Change-Id: I305c1070b673915426bcd619642df13b6aea66ce
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/593821
Auto-Submit: Hyang-Ah Hana Kim <hyangah@gmail.com>
Commit-Queue: Hyang-Ah Hana Kim <hyangah@gmail.com>
kokoro-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/extension/src/goSurvey.ts b/extension/src/goSurvey.ts
index 8e99659..3aa7dbd 100644
--- a/extension/src/goSurvey.ts
+++ b/extension/src/goSurvey.ts
@@ -79,8 +79,12 @@
flushSurveyConfig(goplsSurveyConfig, cfg);
}
};
- const ms = msBetween(now, cfg.dateToPromptThisMonth);
- setTimeout(callback, ms);
+
+ // 0 if we passed the computed dateToPromptThisMonth past.
+ // If the prompt date was computed a while ago (dateComputedPromptThisMonth),
+ // shouldPromptForSurvey should've made a new decision before we get here.
+ const delayMs = Math.max(cfg.dateToPromptThisMonth.getTime() - now.getTime(), 0);
+ setTimeout(callback, delayMs);
}
export function shouldPromptForSurvey(now: Date, cfg: GoplsSurveyConfig): GoplsSurveyConfig | undefined {