using System; namespace UtopiaCanteenSystem.Helpers; /// /// Helper for scan session rules: limit one scan per minute (1-minute session). /// public static class ScanSessionHelper { /// /// Checks if a new scan is allowed: no other scan in the same minute (UTC). /// /// Last scan time in UTC; null if none. /// Current time in UTC. /// True if a new scan is allowed. public static bool IsNewScanAllowed(DateTime? lastScanTimeUtc, DateTime nowUtc) { if (lastScanTimeUtc == null) return true; // Same minute (year, month, day, hour, minute) = not allowed var last = lastScanTimeUtc.Value; if (last.Year == nowUtc.Year && last.Month == nowUtc.Month && last.Day == nowUtc.Day && last.Hour == nowUtc.Hour && last.Minute == nowUtc.Minute) return false; return true; } /// /// Truncates the given UTC time to the start of its minute (session window). /// public static DateTime TruncateToMinute(DateTime utc) { return new DateTime(utc.Year, utc.Month, utc.Day, utc.Hour, utc.Minute, 0, DateTimeKind.Utc); } }