@@ -32,11 +32,8 @@ using namespace chip::app::Clusters::EnergyCalendar::Attributes;
32
32
33
33
constexpr uint32_t kOneDay = 24 * 60 * 60 ;
34
34
35
- static TransitionDayOfWeekBitmap GetDayOfWeek (uint32_t date)
35
+ static void ParceDay (uint32_t date, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & weekDay )
36
36
{
37
- uint16_t year;
38
- uint8_t month;
39
- uint8_t dayOfMonth;
40
37
uint8_t hour;
41
38
uint8_t minute;
42
39
uint8_t second;
@@ -45,9 +42,7 @@ static TransitionDayOfWeekBitmap GetDayOfWeek(uint32_t date)
45
42
ChipEpochToCalendarTime (date, year, month, dayOfMonth, hour, minute, second);
46
43
uint8_t weekDayOffeset = FirstWeekdayOfYear (year);
47
44
CalendarDateToOrdinalDate (year, month, dayOfMonth, dayOfYear);
48
- uint8_t weekDay = static_cast <uint8_t >((dayOfYear -1 + weekDayOffeset) % kDaysPerWeek );
49
-
50
- return static_cast <TransitionDayOfWeekBitmap>(1 << weekDay);
45
+ weekDay = static_cast <uint8_t >((dayOfYear -1 + weekDayOffeset) % kDaysPerWeek );
51
46
}
52
47
53
48
#if 0
@@ -235,6 +230,9 @@ void chip::app::Clusters::EnergyCalendar::CalendarProviderInstance::ErrorMessage
235
230
va_end (v);
236
231
}
237
232
233
+ //
234
+ #define EQUAL_BYTE (a, offset, expected ) (((a)>>(offset) & 0xFF ) == (uint8_t )(expected))
235
+
238
236
DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay (uint32_t date)
239
237
{
240
238
DataModel::Nullable<Structs::DayStruct::Type> result = std::nullopt;
@@ -243,21 +241,22 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
243
241
uint16_t year;
244
242
uint8_t month;
245
243
uint8_t dayOfMonth;
246
- uint8_t hour;
247
- uint8_t minute;
248
- uint8_t second;
249
- ChipEpochToCalendarTime (date, year, month, dayOfMonth, hour, minute, second);
244
+ uint8_t weekDay;
245
+
246
+ ParceDay (date, year, month, dayOfMonth, weekDay);
250
247
251
248
for (auto & day : mSpecialDays )
252
249
{
253
250
if (day.date .HasValue ())
254
251
{
255
252
dt = day.date .Value ();
256
- if (((dt & 0xFF )!=0xFF ) && ((dt & 0xFF ) != (uint8_t )(year - 1900 )))
253
+ if (!EQUAL_BYTE (dt, 0 , 0xFF ) && !EQUAL_BYTE (dt, 0 , year - 1900 ))
254
+ continue ;
255
+ if (!EQUAL_BYTE (dt, 8 , 0 ) && !EQUAL_BYTE (dt, 8 , month))
257
256
continue ;
258
- if (((dt >> 8 ) & 0xFF ) != month )
257
+ if (! EQUAL_BYTE (dt, 16 , 0 ) && ! EQUAL_BYTE (dt, 16 , dayOfMonth) )
259
258
continue ;
260
- if (((dt >> 16 ) & 0xFF ) != dayOfMonth )
259
+ if (! EQUAL_BYTE (dt, 24 , 0 ) && ! EQUAL_BYTE (dt, 24 , weekDay) )
261
260
continue ;
262
261
return day;
263
262
}
@@ -268,7 +267,6 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
268
267
return result;
269
268
}
270
269
271
- TransitionDayOfWeekBitmap week_day = GetDayOfWeek (date);
272
270
273
271
for (auto & period : mCalendarPeriods )
274
272
{
@@ -282,7 +280,7 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
282
280
{
283
281
for (auto & day : period.days )
284
282
{
285
- if (day.daysOfWeek .ValueOr (0 ).Has (week_day ))
283
+ if (day.daysOfWeek .ValueOr (0 ).Has (static_cast <TransitionDayOfWeekBitmap>( 1 << weekDay) ))
286
284
{
287
285
result = day;
288
286
break ;
0 commit comments