<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 5, 2022 at 10:03 PM Cyril Hrubis <<a href="mailto:chrubis@suse.cz">chrubis@suse.cz</a>> wrote:<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + * To handle the normal and special situations:<br>
> + * 1#<br>
> + * set_tm: 2022-04-28 13:00:50<br>
> + * read_tm: 2022-04-28 13:00:50<br>
> + * 2#<br>
> + * set_tm: 2022-04-28 13:00:50<br>
> + * read_tm: 2022-04-28 13:00:51<br>
> + * 3#<br>
> + * set_tm: 2022-04-28 13:00:59<br>
> + * read_tm: 2022-04-28 13:01:00<br>
> + * 4#<br>
> + * set_tm: 2022-04-28 13:59:59<br>
> + * read_tm: 2022-04-28 14:00:00<br>
> + *<br>
> + * Note: as we have avoided testing around the zero<br>
> + * clock, so it's impossible to hit situation 5#<br>
> + * set_tm: 2022-04-28 23:59:59<br>
> + * read_tm: 2022-04-29 00:00:00<br>
> + */<br>
> +<br>
> + /* 1~3 */<br>
> + if (set_tm->tm_hour == read_tm->tm_hour) {<br>
> + if (set_tm->tm_min == read_tm->tm_min - 1)<br>
> + delta += 60;<br>
> + else if (set_tm->tm_min != read_tm->tm_min)<br>
> + return 1;<br>
> + }<br>
> +<br>
> + /* 4 */<br>
> + if ((set_tm->tm_hour == read_tm->tm_hour - 1) &&<br>
> + (set_tm->tm_min == read_tm->tm_min + 59))<br>
> + delta += 60;<br>
> + else if ((set_tm->tm_hour != read_tm->tm_hour))<br>
> + return 1;<br>
> +<br>
> + if (delta < 0 || delta > 3)<br>
> + return 1;<br>
> +<br>
> + return !((set_tm->tm_mday == read_tm->tm_mday)<br>
> && (set_tm->tm_mon == read_tm->tm_mon)<br>
> && (set_tm->tm_year == read_tm->tm_year));<br>
<br>
Wouldn't it be easier to convert both dates into a 64bit timestamp and<br>
compare the timestamps?<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">Yeah, this is a good thought. And we don't even need to convert all dates</div><div class="gmail_default" style="font-size:small">because we have avoided the zero clock setting. IOW, just take the </div><div class="gmail_default" style="font-size:small">hours/min/sec to be compared should be enough.</div><div class="gmail_default" style="font-size:small"></div><div class="gmail_default" style="font-size:small">Update process:</div><div class="gmail_default" style="font-size:small"> patch1/3: drop this one until we find a good way to detect hardware support.</div><div class="gmail_default" style="font-size:small"> patch2/3: pushed.</div><div class="gmail_default" style="font-size:small"> patch3/3: will send a V2.</div></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>