Improve: Web remote desktop two-finger gesture recognition

This commit is contained in:
yuanyuanxiang
2026-04-20 23:56:39 +02:00
parent ef4d316492
commit 80f95a41b2
3 changed files with 134 additions and 36 deletions

View File

@@ -13,6 +13,7 @@
#include <gtest/gtest.h>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <map>
#include <chrono>
#include <cmath>
@@ -88,16 +89,19 @@ private:
int daysBetweenDates(const tm& date1, const tm& date2)
{
auto timeToTimePoint = [](const tm& tmTime) {
std::time_t tt = mktime(const_cast<tm*>(&tmTime));
return std::chrono::system_clock::from_time_t(tt);
// Use Julian Day Number to avoid DST issues
// Formula: https://en.wikipedia.org/wiki/Julian_day
auto toJulianDay = [](int year, int month, int day) {
int a = (14 - month) / 12;
int y = year + 4800 - a;
int m = month + 12 * a - 3;
return day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
};
auto tp1 = timeToTimePoint(date1);
auto tp2 = timeToTimePoint(date2);
int jd1 = toJulianDay(date1.tm_year + 1900, date1.tm_mon + 1, date1.tm_mday);
int jd2 = toJulianDay(date2.tm_year + 1900, date2.tm_mon + 1, date2.tm_mday);
auto duration = tp1 > tp2 ? tp1 - tp2 : tp2 - tp1;
return static_cast<int>(std::chrono::duration_cast<std::chrono::hours>(duration).count() / 24);
return std::abs(jd1 - jd2);
}
tm getCurrentDate()