forked from pixop/video-compare
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_notes.cpp
More file actions
61 lines (49 loc) · 2.04 KB
/
runtime_notes.cpp
File metadata and controls
61 lines (49 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "runtime_notes.h"
#include <cstdlib>
#include <ctime>
#include <iostream>
namespace {
struct SpecialWindow {
int year;
int start_month;
int start_day;
int end_month;
int end_day;
};
constexpr SpecialWindow SPECIAL_WINDOWS[] = {{2026, 4, 3, 4, 6}, {2027, 3, 26, 3, 29}, {2028, 4, 14, 4, 17}, {2029, 3, 30, 4, 2}, {2030, 4, 19, 4, 22},
{2031, 4, 11, 4, 14}, {2032, 3, 26, 3, 29}, {2033, 4, 15, 4, 18}, {2034, 4, 7, 4, 10}, {2035, 3, 23, 3, 26}};
bool is_special_period(const int year, const int month, const int day) {
constexpr int first_year = SPECIAL_WINDOWS[0].year;
constexpr size_t window_count = sizeof(SPECIAL_WINDOWS) / sizeof(SPECIAL_WINDOWS[0]);
constexpr int last_year = first_year + static_cast<int>(window_count) - 1;
if (year < first_year || year > last_year) {
return false;
}
const size_t idx = static_cast<size_t>(year - first_year);
const auto& window = SPECIAL_WINDOWS[idx];
const bool after_start = month > window.start_month || (month == window.start_month && day >= window.start_day);
const bool before_end = month < window.end_month || (month == window.end_month && day <= window.end_day);
return after_start && before_end;
}
} // namespace
void maybe_log_runtime_note() {
const std::time_t now = std::time(nullptr);
const std::tm* local_time = std::localtime(&now);
if (!local_time) {
return;
}
const int year = local_time->tm_year + 1900;
const int month = local_time->tm_mon + 1;
const int day = local_time->tm_mday;
if (!is_special_period(year, month, day)) {
return;
}
// 2% chance to print a note
std::srand(static_cast<unsigned int>(now));
if ((std::rand() % 100) >= 2) {
return;
}
static const char* const notes[] = {"comparison is an illusion...", "perception is biased", "perfect sync is a myth", "the truth is somewhere between...", "you are comparing yourself..."};
const size_t note_count = sizeof(notes) / sizeof(notes[0]);
std::cout << "Parallax: " << notes[std::rand() % note_count] << std::endl;
}