Re: [LTP] [PATCH v2] rtc02: loosen the compare precision with few seconds

Li Wang
2022-05-11T01:54:48Z

[-- Attachment #1.1: Type: text/plain, Size: 971 bytes --]

Cyril Hrubis <chrubis@suse.cz> wrote:

>
> I would have done this a bit differently, first chek for day, mon, year
> then do the calculation as:
>
> if (set_tm->tm_year != read_tm->tm_year)
> return 1;
>
> if (set_tm->tm_mon != read_tm->tm_mon)
> return 1;
>
> if (set_tm->tm_mday != read_tm->tm_mday)
> return 1;
>
>
I slightly want to keep rtc_time comparison before converting
into seconds here, because the time change rarely happens,
we don't need to use seconds every time.

+ if ((set_tm->tm_sec != read_tm->tm_sec)
+ || (set_tm->tm_min != read_tm->tm_min)
+ || (set_tm->tm_hour != read_tm->tm_hour)) {

> seconds1 = ....
> seconds2 = ....
> delta = ...
>
> if (delta < 0 || delta > 3)
> return 1;
>

+ }

>
> return 0;
>
>
> I find this a bit clearer to read.
>

Fair enough!

--
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 2363 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]