aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src/vcpkg.cpp
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2018-10-17 19:05:24 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2018-10-17 19:43:15 -0700
commitf19df646a09d68856c5c4575174831f0d0a295e1 (patch)
treea9cfcdbe50a6973f39a76f3a793d99523ebe833a /toolsrc/src/vcpkg.cpp
parentcf199dba42735eac4065586dac0701fdfc6fd53d (diff)
downloadvcpkg-f19df646a09d68856c5c4575174831f0d0a295e1.tar.gz
vcpkg-f19df646a09d68856c5c4575174831f0d0a295e1.zip
Survey times. Refactor Chrono stuff. All times UTC, unless explicitly mentioned
Survey is set to be every 6 months, but you also get one in the first 10 days.
Diffstat (limited to 'toolsrc/src/vcpkg.cpp')
-rw-r--r--toolsrc/src/vcpkg.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index bcce8ceb2..3589881a7 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -33,6 +33,12 @@
using namespace vcpkg;
+// 24 hours/day * 30 days/month * 6 months
+static constexpr int SURVEY_INTERVAL_IN_HOURS = 24 * 30 * 6;
+
+// Initial survey appears after 10 days. Therefore, subtract 24 hours/day * 10 days
+static constexpr int SURVEY_INITIAL_OFFSET_IN_HOURS = SURVEY_INTERVAL_IN_HOURS - 24 * 10;
+
void invalid_command(const std::string& cmd)
{
System::println(System::Color::error, "invalid command: %s", cmd);
@@ -120,12 +126,12 @@ static void inner(const VcpkgCmdArguments& args)
auto maybe_surveydate = Chrono::CTime::parse(surveydate);
if (auto p_surveydate = maybe_surveydate.get())
{
- auto delta = std::chrono::system_clock::now() - p_surveydate->to_time_point();
- // 24 hours/day * 30 days/month
- if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > 24 * 30)
+ const auto now = Chrono::CTime::get_current_date_time().value_or_exit(VCPKG_LINE_INFO);
+ const auto delta = now.to_time_point() - p_surveydate->to_time_point();
+ if (std::chrono::duration_cast<std::chrono::hours>(delta).count() > SURVEY_INTERVAL_IN_HOURS)
{
std::default_random_engine generator(
- static_cast<unsigned int>(std::chrono::system_clock::now().time_since_epoch().count()));
+ static_cast<unsigned int>(now.to_time_point().time_since_epoch().count()));
std::uniform_int_distribution<int> distribution(1, 4);
if (distribution(generator) == 1)
@@ -214,7 +220,9 @@ static void load_config()
if (config.last_completed_survey.empty())
{
- config.last_completed_survey = config.user_time;
+ const auto now = Chrono::CTime::parse(config.user_time).value_or_exit(VCPKG_LINE_INFO);
+ const Chrono::CTime offset = now.add_hours(-SURVEY_INITIAL_OFFSET_IN_HOURS);
+ config.last_completed_survey = offset.to_string();
}
GlobalState::g_surveydate.lock()->assign(config.last_completed_survey);