From b0f8922056f985d9a01bdbadea0d40d41ff67d53 Mon Sep 17 00:00:00 2001 From: Adrian Freund Date: Sun, 6 Jul 2025 00:00:39 +0200 Subject: [PATCH] Mark ESPTime comparison operators as const (#9335) --- esphome/core/time.cpp | 10 +++++----- esphome/core/time.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/esphome/core/time.cpp b/esphome/core/time.cpp index 672f5b98bf..f9652b5329 100644 --- a/esphome/core/time.cpp +++ b/esphome/core/time.cpp @@ -226,11 +226,11 @@ int32_t ESPTime::timezone_offset() { return offset; } -bool ESPTime::operator<(ESPTime other) { return this->timestamp < other.timestamp; } -bool ESPTime::operator<=(ESPTime other) { return this->timestamp <= other.timestamp; } -bool ESPTime::operator==(ESPTime other) { return this->timestamp == other.timestamp; } -bool ESPTime::operator>=(ESPTime other) { return this->timestamp >= other.timestamp; } -bool ESPTime::operator>(ESPTime other) { return this->timestamp > other.timestamp; } +bool ESPTime::operator<(const ESPTime &other) const { return this->timestamp < other.timestamp; } +bool ESPTime::operator<=(const ESPTime &other) const { return this->timestamp <= other.timestamp; } +bool ESPTime::operator==(const ESPTime &other) const { return this->timestamp == other.timestamp; } +bool ESPTime::operator>=(const ESPTime &other) const { return this->timestamp >= other.timestamp; } +bool ESPTime::operator>(const ESPTime &other) const { return this->timestamp > other.timestamp; } template bool increment_time_value(T ¤t, uint16_t begin, uint16_t end) { current++; diff --git a/esphome/core/time.h b/esphome/core/time.h index 5cbd9369fb..a53fca2346 100644 --- a/esphome/core/time.h +++ b/esphome/core/time.h @@ -109,10 +109,10 @@ struct ESPTime { void increment_second(); /// Increment this clock instance by one day. void increment_day(); - bool operator<(ESPTime other); - bool operator<=(ESPTime other); - bool operator==(ESPTime other); - bool operator>=(ESPTime other); - bool operator>(ESPTime other); + bool operator<(const ESPTime &other) const; + bool operator<=(const ESPTime &other) const; + bool operator==(const ESPTime &other) const; + bool operator>=(const ESPTime &other) const; + bool operator>(const ESPTime &other) const; }; } // namespace esphome