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

Li Wang liwang@redhat.com
Wed May 11 03:54:18 CEST 2022


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20220511/85a63f28/attachment-0001.htm>


More information about the ltp mailing list