Module: sip-router
Branch: janakj/postgres
Commit: d79af6c63a8386f8d50b5dc41e045e754a70a587
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d79af6c…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Mon Apr 14 18:52:47 2003 +0000
- fixed daylight saving bug previously found in mysql module
- struct tm structure properly initialized
- gmtime changed to localtime because mktime expects local time later
---
modules/db_postgres/db_val.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/modules/db_postgres/db_val.c b/modules/db_postgres/db_val.c
index 6c91a7d..9af7d9e 100644
--- a/modules/db_postgres/db_val.c
+++ b/modules/db_postgres/db_val.c
@@ -33,6 +33,9 @@
* History
* -------
* 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
+ * 2003-04-14 gmtime changed to localtime because mktime later
+ * expects localtime, changed daylight saving bug
+ * previously found in mysql module (janakj)
*
*/
@@ -94,7 +97,15 @@ static inline int str2time(const char* _s, time_t* _v)
}
#endif
+ memset(&t, '\0', sizeof(struct tm));
strptime(_s,"%Y-%m-%d %H:%M:%S %z",&t);
+
+ /* Daylight saving information got lost in the database
+ * so let mktime to guess it. This eliminates the bug when
+ * contacts reloaded from the database have different time
+ * of expiration by one hour when daylight saving is used
+ */
+ t.tm_isdst = -1;
*_v = mktime(&t);
return 0;
@@ -147,7 +158,7 @@ static inline int time2str(time_t _v, char* _s, int* _l)
}
#endif
- t = gmtime(&_v);
+ t = localtime(&_v);
if((bl=strftime(_s,(size_t)(*_l)-1,"'%Y-%m-%d %H:%M:%S %z'",t))>0)
*_l = bl;