@@ -30,7 +30,7 @@ using namespace chip::app::Clusters;
30
30
using namespace chip ::app::Clusters::EnergyCalendar;
31
31
using namespace chip ::app::Clusters::EnergyCalendar::Attributes;
32
32
33
- constexpr uint32_t kOneDay = 24 * 60 * 60 ;
33
+ constexpr uint32_t kSecInOneDay = 60 * 60 * 24 ;
34
34
35
35
static void ParceDay (uint32_t date, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, uint8_t & weekDay)
36
36
{
@@ -247,7 +247,7 @@ void chip::app::Clusters::EnergyCalendar::CalendarProviderInstance::ErrorMessage
247
247
DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay (uint32_t date)
248
248
{
249
249
DataModel::Nullable<Structs::DayStruct::Type> result = std::nullopt;
250
- Structs::DateStruct::Type dt;
250
+ uint32_t dt;
251
251
252
252
uint16_t year;
253
253
uint8_t month;
@@ -260,16 +260,11 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
260
260
{
261
261
if (day.date .HasValue ())
262
262
{
263
- dt = day.date .Value ();
264
- if (!dt.year .IsNull () && dt.year .Value () != (uint8_t )(year - 1900 ))
265
- continue ;
266
- if (!dt.month .IsNull () && dt.month .Value () != month)
267
- continue ;
268
- if (!dt.day .IsNull () && dt.day .Value () != dayOfMonth)
269
- continue ;
270
- if (!dt.dayOfWeek .IsNull () && dt.dayOfWeek .Value () != dayOfWeek)
271
- continue ;
272
- return day;
263
+ dt = static_cast <uint32_t >(day.date .Value () - (day.date .Value () % kSecInOneDay ));
264
+ if (dt == date)
265
+ {
266
+ return day;
267
+ }
273
268
}
274
269
}
275
270
@@ -304,7 +299,7 @@ DataModel::Nullable<Structs::DayStruct::Type> CalendarProviderInstance::GetDay(u
304
299
}
305
300
}
306
301
307
- return result;
302
+ return result;
308
303
}
309
304
310
305
void CalendarProviderInstance::JsonToCalendarPeriodStruct (Json::Value & root, Structs::CalendarPeriodStruct::Type & value)
@@ -323,41 +318,12 @@ void CalendarProviderInstance::JsonToCalendarPeriodStruct(Json::Value & root, St
323
318
}
324
319
}
325
320
326
- void CalendarProviderInstance::JsonToDateStruct (Json::Value & root, Structs::DateStruct::Type & value)
327
- {
328
- Json::Value t = root.get (" Year" , Json::Value ());
329
- if (!t.empty () && t.isUInt () && t.asUInt () <= 0xff )
330
- {
331
- value.year .SetNonNull (t.asUInt ());
332
- }
333
-
334
- t = root.get (" Month" , Json::Value ());
335
- if (!t.empty () && t.isUInt () && t.asUInt () >= 1 && t.asUInt () <= 12 )
336
- {
337
- value.month .SetNonNull (t.asUInt ());
338
- }
339
-
340
- t = root.get (" Day" , Json::Value ());
341
- if (!t.empty () && t.isUInt () && t.asUInt () >= 1 && t.asUInt () <= 31 )
342
- {
343
- value.day .SetNonNull (t.asUInt ());
344
- }
345
-
346
- t = root.get (" DayOfWeek" , Json::Value ());
347
- if (!t.empty () && t.isUInt () && t.asUInt () >= 1 && t.asUInt () <= 7 )
348
- {
349
- value.dayOfWeek .SetNonNull (t.asUInt ());
350
- }
351
- }
352
-
353
321
void CalendarProviderInstance::JsonToDayStruct (Json::Value & root, Structs::DayStruct::Type & value)
354
322
{
355
323
Json::Value t = root.get (" Date" , Json::Value ());
356
- if (!t.empty ())
324
+ if (!t.empty () && t. isUInt () )
357
325
{
358
- Structs::DateStruct::Type date;
359
- JsonToDateStruct (t, date);
360
- value.date .SetValue (date);
326
+ value.date .SetValue (t.asUInt ());
361
327
}
362
328
363
329
t = root.get (" DaysOfWeek" , Json::Value ());
0 commit comments