Blob Blame History Raw
From fdd19cb2f65413aacb32f1eca04c2997a892f62d Mon Sep 17 00:00:00 2001
From: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
Date: Wed, 30 Mar 2016 14:07:16 +0530
Subject: [PATCH] ID:437 - sel: Fix "sel time set <time>"

Presently 'sel time set' doesn't account 'minute' difference between timezone.
So depending on host timezone it may set time to +/-30 mins. This patch adds
minute difference to delta_hour caluclation so that it sets time properly.

output without patch:
  # ./ipmitool sel time get
  03/24/2016 12:34:03
  # ./ipmitool sel time set "03/24/2016 12:34:03"
  03/24/2016 12:04:03
  # ./ipmitool sel time get
  03/24/2016 12:06:09

output with patch:

  # ./ipmitool sel time get
  03/30/2016 08:49:47
  # ./ipmitool sel time set "03/30/2016 08:09:47"
  03/30/2016 08:09:47
  # ./ipmitool sel get
  03/30/2016 08:09:57

Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 lib/ipmi_sel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lib/ipmi_sel.c b/lib/ipmi_sel.c
index affaed8..243f268 100644
--- a/lib/ipmi_sel.c
+++ b/lib/ipmi_sel.c
@@ -2726,24 +2726,26 @@ ipmi_sel_set_time(struct ipmi_intf * intf, const char * time_string)
 	{
 		//modify UTC time to local time expressed in number of seconds from 1/1/70 0:0:0 1970 GMT
 		struct tm * tm_tmp = {0};
-		int gt_year,gt_yday,gt_hour,lt_year,lt_yday,lt_hour;
+		int gt_year,gt_yday,gt_hour,gt_min,lt_year,lt_yday,lt_hour,lt_min;
 		int delta_hour;
 		tm_tmp=gmtime(&t);
 		gt_year=tm_tmp->tm_year;
 		gt_yday=tm_tmp->tm_yday;
 		gt_hour=tm_tmp->tm_hour;
+		gt_min=tm_tmp->tm_min;
 		memset(&*tm_tmp, 0, sizeof(struct tm));
 		tm_tmp=localtime(&t);
 		lt_year=tm_tmp->tm_year;
 		lt_yday=tm_tmp->tm_yday;
 		lt_hour=tm_tmp->tm_hour;
+		lt_min=tm_tmp->tm_min;
 		delta_hour=lt_hour - gt_hour;
 		if ( (lt_year > gt_year) || ((lt_year == gt_year) && (lt_yday > gt_yday)) )
 			delta_hour += 24;
 		if ( (lt_year < gt_year) || ((lt_year == gt_year) && (lt_yday < gt_yday)) )
 			delta_hour -= 24;
 
-		t += (delta_hour * 60 * 60);
+		t += (delta_hour * 60 * 60) + (lt_min - gt_min) * 60;
 	}
 
 	timei = (uint32_t)t;
-- 
2.5.5