1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "reminder_request_calendar.h"
17
18 #include "reminder_table.h"
19 #include "ans_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Notification {
23 const uint8_t ReminderRequestCalendar::MAX_MONTHS_OF_YEAR = 12;
24 const uint8_t ReminderRequestCalendar::MAX_DAYS_OF_MONTH = 31;
25 const uint8_t ReminderRequestCalendar::JANUARY = 1;
26 const uint8_t ReminderRequestCalendar::DECEMBER = 12;
27 const uint8_t ReminderRequestCalendar::DEFAULT_SNOOZE_TIMES = 3;
28
29 const uint8_t ReminderRequestCalendar::DAY_ARRAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
30 const uint8_t ReminderRequestCalendar::FEBRUARY = 2;
31 const uint8_t ReminderRequestCalendar::LEAP_MONTH = 29;
32 const uint8_t ReminderRequestCalendar::NON_LEAP_MONTH = 28;
33 const uint16_t ReminderRequestCalendar::SOLAR_YEAR = 400;
34 const uint8_t ReminderRequestCalendar::LEAP_PARAM_MIN = 4;
35 const uint8_t ReminderRequestCalendar::LEAP_PARAM_MAX = 100;
36
ReminderRequestCalendar(const tm & dateTime,const std::vector<uint8_t> & repeatMonths,const std::vector<uint8_t> & repeatDays,const std::vector<uint8_t> & daysOfWeek)37 ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, const std::vector<uint8_t> &repeatMonths,
38 const std::vector<uint8_t> &repeatDays, const std::vector<uint8_t> &daysOfWeek)
39 : ReminderRequest(ReminderRequest::ReminderType::CALENDAR)
40 {
41 // 1. record the information which designated by user at first time.
42 firstDesignateYear_ = static_cast<uint16_t>(GetActualTime(TimeTransferType::YEAR, dateTime.tm_year));
43 firstDesignateMonth_ = static_cast<uint8_t>(GetActualTime(TimeTransferType::MONTH, dateTime.tm_mon));
44 firstDesignateDay_ = dateTime.tm_mday;
45 SetRepeatMonths(repeatMonths);
46 SetRepeatDaysOfMonth(repeatDays);
47 SetRepeatDaysOfWeek(true, daysOfWeek);
48 SetSnoozeTimes(DEFAULT_SNOOZE_TIMES);
49
50 // 2. should SetNextTriggerTime() after constructor
51 InitDateTime(dateTime);
52 }
53
ReminderRequestCalendar(const ReminderRequestCalendar & other)54 ReminderRequestCalendar::ReminderRequestCalendar(const ReminderRequestCalendar &other) : ReminderRequest(other)
55 {
56 dateTime_ = other.dateTime_;
57 firstDesignateYear_ = other.firstDesignateYear_;
58 firstDesignateMonth_ = other.firstDesignateMonth_;
59 firstDesignateDay_ = other.firstDesignateDay_;
60 year_ = other.year_;
61 month_ = other.month_;
62 day_ = other.day_;
63 hour_ = other.hour_;
64 minute_ = other.minute_;
65 second_ = other.second_;
66 repeatMonth_ = other.repeatMonth_;
67 repeatDay_ = other.repeatDay_;
68 }
69
SetNextTriggerTime()70 bool ReminderRequestCalendar::SetNextTriggerTime()
71 {
72 hour_ = static_cast<uint8_t>(dateTime_.tm_hour);
73 minute_ = static_cast<uint8_t>(dateTime_.tm_min);
74 uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE;
75 if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) {
76 time_t target = static_cast<time_t>(nextTriggerTime / MILLI_SECONDS);
77 (void)localtime_r(&target, &dateTime_);
78 } else {
79 ANSR_LOGW("Not exist next trigger time, please check the param of ReminderRequestCalendar constructor.");
80 return false;
81 }
82
83 // set the time information (used to transfer to proxy service) which is decided to trigger firstly.
84 year_ = static_cast<uint16_t>(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year));
85 month_ = static_cast<uint8_t>(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon));
86 day_ = static_cast<uint8_t>(dateTime_.tm_mday);
87 second_ = 0;
88 SetTriggerTimeInMilli(nextTriggerTime);
89 return true;
90 }
91
GetDaysOfMonth(const uint16_t & year,const uint8_t & month)92 uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint8_t &month)
93 {
94 uint8_t days;
95 if (month == FEBRUARY) {
96 days = ((((year % LEAP_PARAM_MIN == 0) && (year % LEAP_PARAM_MAX != 0)) || (year % SOLAR_YEAR == 0))
97 ? LEAP_MONTH : NON_LEAP_MONTH);
98 } else {
99 days = DAY_ARRAY[month - 1];
100 }
101 return days;
102 }
103
GetNextDay(const uint16_t & settedYear,const uint8_t & settedMonth,const tm & now,const tm & target) const104 uint8_t ReminderRequestCalendar::GetNextDay(
105 const uint16_t &settedYear, const uint8_t &settedMonth, const tm &now, const tm &target) const
106 {
107 uint32_t repeatDayTmp = repeatDay_;
108 uint8_t daysOfSpecialMonth = GetDaysOfMonth(settedYear, settedMonth);
109 uint8_t setDayTmp = INVALID_U8_VALUE;
110 for (uint8_t i = 1; i <= daysOfSpecialMonth; i++) {
111 if ((repeatDayTmp & (1 << (i - 1))) > 0) {
112 struct tm setTime;
113 setTime.tm_year = GetCTime(TimeTransferType::YEAR, settedYear);
114 setTime.tm_mon = GetCTime(TimeTransferType::MONTH, settedMonth);
115 setTime.tm_mday = static_cast<int>(i);
116 setTime.tm_hour = target.tm_hour;
117 setTime.tm_min = target.tm_min;
118 setTime.tm_sec = target.tm_sec;
119 setTime.tm_isdst = -1;
120
121 struct tm nowTime;
122 nowTime.tm_year = now.tm_year;
123 nowTime.tm_mon = now.tm_mon;
124 nowTime.tm_mday = now.tm_mday;
125 nowTime.tm_hour = now.tm_hour;
126 nowTime.tm_min = now.tm_min;
127 nowTime.tm_sec = now.tm_sec;
128 nowTime.tm_isdst = -1;
129
130 if (mktime(&nowTime) >= mktime(&setTime)) {
131 continue;
132 } else {
133 setDayTmp = i;
134 return setDayTmp;
135 }
136 }
137 }
138 return setDayTmp;
139 }
140
GetNextTriggerTime() const141 uint64_t ReminderRequestCalendar::GetNextTriggerTime() const
142 {
143 uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE;
144 time_t now;
145 (void)time(&now); // unit is seconds.
146 struct tm nowTime;
147 (void)localtime_r(&now, &nowTime);
148 nowTime.tm_sec = 0;
149 struct tm tarTime;
150 tarTime.tm_year = GetCTime(TimeTransferType::YEAR, firstDesignateYear_);
151 tarTime.tm_mon = GetCTime(TimeTransferType::MONTH, firstDesignateMonth_);
152 tarTime.tm_mday = firstDesignateDay_;
153 tarTime.tm_hour = hour_;
154 tarTime.tm_min = minute_;
155 tarTime.tm_sec = 0;
156 tarTime.tm_isdst = -1;
157 const time_t target = mktime(&tarTime);
158 ANSR_LOGD("Now time is: %{public}s", GetDateTimeInfo(now).c_str());
159 if (repeatMonth_ > 0 && repeatDay_ > 0) {
160 triggerTimeInMilli = GetNextTriggerTimeAsRepeatReminder(nowTime, tarTime);
161 } else if (repeatDaysOfWeek_ > 0 && (target <= now)) {
162 nowTime.tm_hour = tarTime.tm_hour;
163 nowTime.tm_min = tarTime.tm_min;
164 nowTime.tm_sec = tarTime.tm_sec;
165 nowTime.tm_isdst = tarTime.tm_isdst;
166 const time_t tar = mktime(&nowTime);
167 triggerTimeInMilli = GetNextDaysOfWeek(now, tar);
168 } else {
169 ANSR_LOGD("tarTime: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d",
170 tarTime.tm_year, tarTime.tm_mon, tarTime.tm_mday, tarTime.tm_hour, tarTime.tm_min, tarTime.tm_sec);
171 if (target == -1) {
172 ANSR_LOGW("mktime return error.");
173 }
174 if (now < target) {
175 triggerTimeInMilli = ReminderRequest::GetDurationSinceEpochInMilli(target);
176 ANSR_LOGD("Next calendar time:%{public}s", GetDateTimeInfo(target).c_str());
177 }
178 }
179 return triggerTimeInMilli;
180 }
181
GetNextTriggerTimeAsRepeatReminder(const tm & nowTime,const tm & tarTime) const182 uint64_t ReminderRequestCalendar::GetNextTriggerTimeAsRepeatReminder(const tm &nowTime, const tm &tarTime) const
183 {
184 uint64_t triggerTimeInMilli = INVALID_LONG_LONG_VALUE;
185 uint16_t setYear = static_cast<uint16_t>(GetActualTime(TimeTransferType::YEAR, nowTime.tm_year));
186 uint8_t setMonth = INVALID_U8_VALUE;
187 uint8_t setDay = INVALID_U8_VALUE;
188 uint8_t beginMonth = static_cast<uint8_t>(GetActualTime(TimeTransferType::MONTH, nowTime.tm_mon));
189 uint8_t count = 1;
190 uint16_t repeatMonthTmp = repeatMonth_;
191 for (uint8_t i = beginMonth; i < (MAX_MONTHS_OF_YEAR + beginMonth + 1); i++) {
192 if ((repeatMonthTmp & (1 << ((i - 1) % MAX_MONTHS_OF_YEAR))) > 0) {
193 setMonth = (i % MAX_MONTHS_OF_YEAR);
194 setMonth = setMonth == 0 ? DECEMBER : setMonth;
195 if (count != 1) {
196 setYear = setMonth <= beginMonth ? setYear + 1 : setYear;
197 }
198 setDay = GetNextDay(setYear, setMonth, nowTime, tarTime);
199 }
200 if (setDay != INVALID_U8_VALUE) {
201 break;
202 }
203 count++;
204 }
205 if ((triggerTimeInMilli = GetTimeInstantMilli(setYear, setMonth, setDay, hour_, minute_, second_))
206 != INVALID_LONG_LONG_VALUE) {
207 ANSR_LOGD("Next calendar time:%{public}hu/%{public}hhu/%{public}hhu %{public}hhu:%{public}hhu:%{public}hhu",
208 setYear, setMonth, setDay, hour_, minute_, second_);
209 }
210 return triggerTimeInMilli;
211 }
212
GetTimeInstantMilli(uint16_t year,uint8_t month,uint8_t day,uint8_t hour,uint8_t minute,uint8_t second) const213 uint64_t ReminderRequestCalendar::GetTimeInstantMilli(
214 uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) const
215 {
216 struct tm tar;
217 tar.tm_year = GetCTime(TimeTransferType::YEAR, year);
218 tar.tm_mon = GetCTime(TimeTransferType::MONTH, month);
219 tar.tm_mday = static_cast<int>(day);
220 tar.tm_hour = static_cast<int>(hour);
221 tar.tm_min = static_cast<int>(minute);
222 tar.tm_sec = static_cast<int>(second);
223 tar.tm_isdst = -1;
224
225 ANSR_LOGD("tar: %{public}d-%{public}d-%{public}d %{public}d:%{public}d:%{public}d",
226 tar.tm_year, tar.tm_mon, tar.tm_mday, tar.tm_hour, tar.tm_min, tar.tm_sec);
227 const time_t target = mktime(&tar);
228 if (target == -1) {
229 ANSR_LOGW("mktime return error.");
230 return INVALID_LONG_LONG_VALUE;
231 }
232 return ReminderRequest::GetDurationSinceEpochInMilli(target);
233 }
234
InitDateTime()235 void ReminderRequestCalendar::InitDateTime()
236 {
237 dateTime_.tm_year = GetCTime(TimeTransferType::YEAR, year_);
238 dateTime_.tm_mon = GetCTime(TimeTransferType::MONTH, month_);
239 dateTime_.tm_mday = static_cast<int>(day_);
240 dateTime_.tm_hour = static_cast<int>(hour_);
241 dateTime_.tm_min = static_cast<int>(minute_);
242 dateTime_.tm_sec = static_cast<int>(second_);
243 dateTime_.tm_isdst = -1;
244 }
245
InitDateTime(const tm & dateTime)246 void ReminderRequestCalendar::InitDateTime(const tm &dateTime)
247 {
248 dateTime_.tm_year = dateTime.tm_year;
249 dateTime_.tm_mon = dateTime.tm_mon;
250 dateTime_.tm_mday = dateTime.tm_mday;
251 dateTime_.tm_hour = dateTime.tm_hour;
252 dateTime_.tm_min = dateTime.tm_min;
253 dateTime_.tm_sec = dateTime.tm_sec;
254 dateTime_.tm_isdst = -1;
255 }
256
IsRepeatReminder() const257 bool ReminderRequestCalendar::IsRepeatReminder() const
258 {
259 return (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0)
260 || (GetTimeInterval() > 0 && GetSnoozeTimes() > 0);
261 }
262
263
IsRepeatMonth(uint8_t month) const264 bool ReminderRequestCalendar::IsRepeatMonth(uint8_t month) const
265 {
266 if (month > MAX_MONTHS_OF_YEAR) {
267 return false;
268 }
269 return (repeatMonth_ & (1 << (month - 1))) > 0;
270 }
271
IsRepeatDay(uint8_t day) const272 bool ReminderRequestCalendar::IsRepeatDay(uint8_t day) const
273 {
274 if (day > MAX_DAYS_OF_MONTH) {
275 return false;
276 }
277 return (repeatDay_ & (1 << (day - 1))) > 0;
278 }
279
SetDay(const uint8_t & day,const bool & isSet)280 void ReminderRequestCalendar::SetDay(const uint8_t &day, const bool &isSet)
281 {
282 if (day < 1 || day > MAX_DAYS_OF_MONTH) {
283 return;
284 }
285 if (isSet) {
286 repeatDay_ |= 1 << (day - 1);
287 } else {
288 repeatDay_ &= ~(1 << (day - 1));
289 }
290 }
291
SetMonth(const uint8_t & month,const bool & isSet)292 void ReminderRequestCalendar::SetMonth(const uint8_t &month, const bool &isSet)
293 {
294 if (month < JANUARY || month > DECEMBER) {
295 return;
296 }
297 if (isSet) {
298 repeatMonth_ |= 1 << (month - 1);
299 } else {
300 repeatMonth_ &= ~ (1 << (month - 1));
301 }
302 }
303
SetRepeatMonths(const std::vector<uint8_t> & repeatMonths)304 void ReminderRequestCalendar::SetRepeatMonths(const std::vector<uint8_t> &repeatMonths)
305 {
306 if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) {
307 ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR);
308 return;
309 }
310 repeatMonth_ = 0;
311 for (auto it = repeatMonths.begin(); it != repeatMonths.end(); ++it) {
312 SetMonth((*it), true);
313 }
314 }
315
SetRepeatDaysOfMonth(const std::vector<uint8_t> & repeatDays)316 void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector<uint8_t> &repeatDays)
317 {
318 if (repeatDays.size() > MAX_DAYS_OF_MONTH) {
319 ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH);
320 return;
321 }
322 repeatDay_ = 0;
323 for (auto it = repeatDays.begin(); it != repeatDays.end(); ++it) {
324 SetDay((*it), true);
325 }
326 }
327
GetRepeatMonths() const328 std::vector<uint8_t> ReminderRequestCalendar::GetRepeatMonths() const
329 {
330 std::vector<uint8_t> repeatMonths;
331 for (int32_t i = 0; i < MAX_MONTHS_OF_YEAR; i++) {
332 if (IsRepeatMonth(i + 1)) {
333 repeatMonths.push_back(i + 1);
334 }
335 }
336 return repeatMonths;
337 }
338
GetRepeatDays() const339 std::vector<uint8_t> ReminderRequestCalendar::GetRepeatDays() const
340 {
341 std::vector<uint8_t> repeatDays;
342 for (int32_t i = 0; i < MAX_DAYS_OF_MONTH; i++) {
343 if (IsRepeatDay(i + 1)) {
344 repeatDays.push_back(i + 1);
345 }
346 }
347 return repeatDays;
348 }
349
UpdateNextReminder()350 bool ReminderRequestCalendar::UpdateNextReminder()
351 {
352 ANSR_LOGD("UpdateNextReminder calendar time");
353 if (!IsRepeatReminder()) {
354 ANSR_LOGI("No need to update next trigger time as it is an one-time reminder.");
355 SetSnoozeTimesDynamic(GetSnoozeTimes());
356 SetExpired(true);
357 return false;
358 }
359 uint8_t leftSnoozeTimes = GetSnoozeTimesDynamic();
360 if (leftSnoozeTimes > 0 && (GetTimeInterval() > 0)) {
361 ANSR_LOGI("Left snooze times: %{public}d, update next triggerTime", leftSnoozeTimes);
362 SetTriggerTimeInMilli(GetTriggerTimeInMilli() + GetTimeInterval() * MILLI_SECONDS);
363 SetSnoozeTimesDynamic(--leftSnoozeTimes);
364 } else {
365 SetSnoozeTimesDynamic(GetSnoozeTimes());
366 if ((repeatMonth_ == 0 || repeatDay_ == 0) && (repeatDaysOfWeek_ == 0)) {
367 ANSR_LOGI("Not a day repeat reminder, no need to update to next trigger time.");
368 SetExpired(true);
369 return false;
370 } else {
371 uint64_t nextTriggerTime = GetNextTriggerTime();
372 if (nextTriggerTime != INVALID_LONG_LONG_VALUE) {
373 ANSR_LOGI("Set next trigger time successful, reset dynamic snoozeTimes");
374 SetTriggerTimeInMilli(nextTriggerTime);
375 } else {
376 ANSR_LOGW("Set next trigger time invalidate");
377 SetExpired(true);
378 return false;
379 }
380 }
381 }
382 return true;
383 }
384
PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat,bool forceToGetNext) const385 uint64_t ReminderRequestCalendar::PreGetNextTriggerTimeIgnoreSnooze(bool ignoreRepeat, bool forceToGetNext) const
386 {
387 if (ignoreRepeat || (repeatMonth_ > 0 && repeatDay_ > 0) || (repeatDaysOfWeek_ > 0)) {
388 return GetNextTriggerTime();
389 } else {
390 return INVALID_LONG_LONG_VALUE;
391 }
392 }
393
Marshalling(Parcel & parcel) const394 bool ReminderRequestCalendar::Marshalling(Parcel &parcel) const
395 {
396 if (ReminderRequest::Marshalling(parcel)) {
397 // write int
398 WRITE_UINT16_RETURN_FALSE_LOG(parcel, year_, "year");
399 WRITE_UINT8_RETURN_FALSE_LOG(parcel, month_, "month");
400 WRITE_UINT8_RETURN_FALSE_LOG(parcel, day_, "day");
401 WRITE_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour");
402 WRITE_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute");
403 WRITE_UINT8_RETURN_FALSE_LOG(parcel, second_, "second");
404 WRITE_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth");
405 WRITE_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay");
406 WRITE_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear");
407 WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth");
408 WRITE_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay");
409 return true;
410 }
411 return false;
412 }
413
Unmarshalling(Parcel & parcel)414 ReminderRequestCalendar *ReminderRequestCalendar::Unmarshalling(Parcel &parcel)
415 {
416 ANSR_LOGD("New calendar");
417 auto objptr = new (std::nothrow) ReminderRequestCalendar();
418 if (objptr == nullptr) {
419 ANS_LOGE("Failed to create reminder calendar due to no memory.");
420 return objptr;
421 }
422 if (!objptr->ReadFromParcel(parcel)) {
423 delete objptr;
424 objptr = nullptr;
425 }
426 return objptr;
427 }
428
ReadFromParcel(Parcel & parcel)429 bool ReminderRequestCalendar::ReadFromParcel(Parcel &parcel)
430 {
431 if (ReminderRequest::ReadFromParcel(parcel)) {
432 // read int
433 READ_UINT16_RETURN_FALSE_LOG(parcel, year_, "year");
434 READ_UINT8_RETURN_FALSE_LOG(parcel, month_, "month");
435 READ_UINT8_RETURN_FALSE_LOG(parcel, day_, "day");
436 READ_UINT8_RETURN_FALSE_LOG(parcel, hour_, "hour");
437 READ_UINT8_RETURN_FALSE_LOG(parcel, minute_, "minute");
438 READ_UINT8_RETURN_FALSE_LOG(parcel, second_, "second");
439 READ_UINT16_RETURN_FALSE_LOG(parcel, repeatMonth_, "repeatMonth");
440 READ_UINT32_RETURN_FALSE_LOG(parcel, repeatDay_, "repeatDay");
441
442 InitDateTime();
443
444 READ_UINT16_RETURN_FALSE_LOG(parcel, firstDesignateYear_, "firstDesignateYear");
445 READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateMonth_, "firstDesignateMonth");
446 READ_UINT8_RETURN_FALSE_LOG(parcel, firstDesignateDay_, "firstDesignateDay");
447
448 return true;
449 }
450 return false;
451 }
452
RecoverFromDb(const std::shared_ptr<NativeRdb::ResultSet> & resultSet)453 void ReminderRequestCalendar::RecoverFromDb(const std::shared_ptr<NativeRdb::ResultSet> &resultSet)
454 {
455 ReminderRequest::RecoverFromDb(resultSet);
456
457 // repeatDay
458 repeatDay_ = static_cast<uint32_t>(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_DAYS,
459 DbRecoveryType::INT));
460
461 // repeatMonth
462 repeatMonth_ =
463 static_cast<uint16_t>(RecoverInt64FromDb(resultSet, ReminderTable::REPEAT_MONTHS,
464 DbRecoveryType::INT));
465
466 // firstDesignateYear
467 firstDesignateYear_ =
468 static_cast<uint16_t>(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_YEAR,
469 DbRecoveryType::INT));
470
471 // firstDesignateMonth
472 firstDesignateMonth_ =
473 static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_MONTH,
474 DbRecoveryType::INT));
475
476 // firstDesignateDay
477 firstDesignateDay_ =
478 static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::FIRST_DESIGNATE_DAY,
479 DbRecoveryType::INT));
480
481 // year
482 year_ = static_cast<uint16_t>(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_YEAR,
483 DbRecoveryType::INT));
484
485 // month
486 month_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MONTH,
487 DbRecoveryType::INT));
488
489 // day
490 day_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_DAY,
491 DbRecoveryType::INT));
492
493 // hour
494 hour_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_HOUR,
495 DbRecoveryType::INT));
496
497 // minute
498 minute_ = static_cast<uint8_t>(RecoverInt64FromDb(resultSet, ReminderTable::CALENDAR_MINUTE,
499 DbRecoveryType::INT));
500 }
501
AppendValuesBucket(const sptr<ReminderRequest> & reminder,const sptr<NotificationBundleOption> & bundleOption,NativeRdb::ValuesBucket & values)502 void ReminderRequestCalendar::AppendValuesBucket(const sptr<ReminderRequest> &reminder,
503 const sptr<NotificationBundleOption> &bundleOption, NativeRdb::ValuesBucket &values)
504 {
505 uint32_t repeatDay = 0;
506 uint16_t repeatMonth = 0;
507 uint16_t firstDesignateYear = 0;
508 uint8_t firstDesignateMonth = 0;
509 uint8_t firstDesignateDay = 0;
510 uint16_t year = 0;
511 uint8_t month = 0;
512 uint8_t day = 0;
513 uint8_t hour = 0;
514 uint8_t minute = 0;
515 if (reminder->GetReminderType() == ReminderRequest::ReminderType::CALENDAR) {
516 ReminderRequestCalendar* calendar = static_cast<ReminderRequestCalendar*>(reminder.GetRefPtr());
517 if (calendar != nullptr) {
518 repeatDay = calendar->GetRepeatDay();
519 repeatMonth = calendar->GetRepeatMonth();
520 firstDesignateYear = calendar->GetFirstDesignateYear();
521 firstDesignateMonth = calendar->GetFirstDesignageMonth();
522 firstDesignateDay = calendar->GetFirstDesignateDay();
523 year = calendar->GetYear();
524 month = calendar->GetMonth();
525 day = calendar->GetDay();
526 hour = calendar->GetHour();
527 minute = calendar->GetMinute();
528 }
529 }
530 values.PutInt(ReminderTable::REPEAT_DAYS, repeatDay);
531 values.PutInt(ReminderTable::REPEAT_MONTHS, repeatMonth);
532 values.PutInt(ReminderTable::FIRST_DESIGNATE_YEAR, firstDesignateYear);
533 values.PutInt(ReminderTable::FIRST_DESIGNATE_MONTH, firstDesignateMonth);
534 values.PutInt(ReminderTable::FIRST_DESIGNATE_DAY, firstDesignateDay);
535 values.PutInt(ReminderTable::CALENDAR_YEAR, year);
536 values.PutInt(ReminderTable::CALENDAR_MONTH, month);
537 values.PutInt(ReminderTable::CALENDAR_DAY, day);
538 values.PutInt(ReminderTable::CALENDAR_HOUR, hour);
539 values.PutInt(ReminderTable::CALENDAR_MINUTE, minute);
540 }
541
542 }
543 }
544