Re: [PATCH] SMPP validity

Vibhu Mohindra <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
If the issue is solely with locatime_r(), but using localtime() and
the returned struct's tm_gmtoff is alright then let's do that rather
than re-implementing a (non-trivial?) algorithm. The struct returned
by localtime() is in a global area, but if that's alright then let's go
for it.

>  gmtime = gw_gmtime(time(NULL));
>  localtime = gw_localtime(time(NULL));
>  gwqdiff = ((localtime.tm_hour - gmtime.tm_hour) * 4)
>                   + ((localtime.tm_min - gmtime.tm_min) / 15);
> +gwqdiff = gwqdiff>12?gwqdiff-24:gwqdiff;

I'm actually +6 UTC. However early in the morning it detected me as
-18 UTC. Not +18, so the algorithm given won't work in this case, or
for other cases east of Greenwich. Also it doesn't take into account
daylight savings (I admit I don't know much about daylight savings, not
living in a country where they apply). You get all this for free with
tm_gmtoff. Of course if the tm_gmtoff member of the struct itself is only
present on some platforms and is non-portable then we should definitely
re-implement the algorithm. Could you let me know if this is so.

In that case the calculation to get the difference in minutes may be
more like

(local_tm.tm_year - gmt_tm.tm_year) * 365*24*60 +
(local_tm.tm_yday - gmt_tm.tm_yday) * 24*60 +
(local_tm.tm_hour - gmt_tm.tm_hour) * 60 +
(local_tm.tm_min  - gmt_tm.tm_min );

but this has a problem with leap years. Maybe it's simpler with your
approach. Something to normalise the time like

  gmtime = gw_gmtime(time(NULL));
  localtime = gw_localtime(time(NULL));
  gwqdiff = ((localtime.tm_hour - gmtime.tm_hour) * 4)
                   + ((localtime.tm_min - gmtime.tm_min) / 15);
 +gwqdiff = gwqdiff>12?gwqdiff-24:gwqdiff;
 +gwqdiff = gwqdiff<12?gwqdiff+24:gwqdiff;

Is this error free?

Vibhu
signature.asc (application/pgp-signature, 232 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9ZNLjvgqsqbNQjqcRApHzAJ97XlmRxXRzp0NbH0AGcEGMHbBbigCfd9Cy
m19W5u5gcv4uByh4GV5vGg0=
=KIOu
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.