[icinga-checkins] icinga.org: icinga-core/rbartels/cgi-current: fix for DST when choosing a time periode.

git at icinga.org git at icinga.org
Tue Apr 12 22:29:56 CEST 2011


Module: icinga-core
Branch: rbartels/cgi-current
Commit: c9f9dfa972d234ec572bd0cf4a0f9cc5de313b61
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=c9f9dfa972d234ec572bd0cf4a0f9cc5de313b61

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Tue Apr 12 22:05:54 2011 +0200

fix for DST when choosing a time periode.

refs #1269

---

 cgi/cgiutils.c     |   26 +++++++++++++++++++++++---
 include/cgiutils.h |    2 ++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/cgi/cgiutils.c b/cgi/cgiutils.c
index 6b92724..a8802f6 100644
--- a/cgi/cgiutils.c
+++ b/cgi/cgiutils.c
@@ -2562,6 +2562,12 @@ int my_fdcopy(char *source, char *dest, int dest_fd){
 	return OK;
 }
 
+/* Checks if the given time is in daylight time saving period */
+int is_dlst_time(time_t *time) {
+	struct tm *bt = localtime(time);
+	return bt->tm_isdst;
+}
+
 /* convert timeperiodes to timestamps */
 void convert_timeperiod_to_times(int type, time_t *ts_start, time_t *ts_end){
 	time_t current_time;
@@ -2629,8 +2635,7 @@ void convert_timeperiod_to_times(int type, time_t *ts_start, time_t *ts_end){
 			if(t->tm_mon==0){
 				t->tm_mon=11;
 				t->tm_year--;
-				}
-			else
+			} else
 				t->tm_mon--;
 			*ts_start=mktime(t);
 			break;
@@ -2663,12 +2668,27 @@ void convert_timeperiod_to_times(int type, time_t *ts_start, time_t *ts_end){
 			break;
 		case TIMEPERIOD_NEXTPROBLEM:
 			/* Time period will be defined later */
-			/* oly used in trends.cgi */
+			/* only used in trends.cgi */
 			break;
 		default:
 			break;
 	}
 
+	/* check if interval is across dlst change and adjust timestamps with compensation */
+	if (is_dlst_time(ts_start) != is_dlst_time(ts_end)) {
+		t=localtime(&current_time);
+		/* in DST */
+		if (t->tm_isdst==1) {
+			/* if end is also in DST */
+			if (is_dlst_time(ts_end)==1)
+				*ts_start=*ts_start+3600;
+		} else {
+			if (is_dlst_time(ts_end)==0)
+				*ts_start=*ts_start-3600;
+		}
+
+	}
+
 	return;
 }
 
diff --git a/include/cgiutils.h b/include/cgiutils.h
index 3fd39d8..3ece28d 100644
--- a/include/cgiutils.h
+++ b/include/cgiutils.h
@@ -610,6 +610,8 @@ int my_fdcopy(char *, char *, int);				/* copies a named source to an already op
 void convert_timeperiod_to_times(int, time_t *, time_t *);	/* converts time period to start and end unix timestamps */
 int string_to_time(char *, time_t *);				/* converts a defined formated string to unix timestamp */
 
+int is_dlst_time(time_t *);
+
 /******************************** MULTIURL PATCH *******************************/
 
 #ifndef DISABLE_MULTIURL





More information about the icinga-checkins mailing list