gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

timezone offset in calnote_get_alarm()


From: Dan Oetting
Subject: timezone offset in calnote_get_alarm()
Date: Thu, 12 Jan 2006 10:24:07 -0700

The line in nokia-decoding.c:252
t_alarm += timezone;
gives a warning on my system because timezone is a function pointer instead of a global int. Looking closer at the procedure. I don't understand why this line is there in the first place. The procedure is simply producing a time that is offset from the original time by the value in alarmdiff. This should not require the explicit use of the timezone offset if mktime() and localtime() work as documented.

Since the function mktime() will normalize the input time there is no need for the call to localtime(). Simply set
tm_alarm->tm_sec = -alarmdiff; 
before calling mktime() and the offset alarm time will be included in the normalized tm_time.

Finally, there is a potential glitch in the hours around the change to and from Daylight Savings Time. This could be avoided by using timegm() instead of mktime() which also eliminates the need for calling tzset().

I don't have a phone to test the calendar functions so someone else is going to have to test if it's producing the correct results. Preferably someone that is not in time zone 0.

-- Dan Oetting

Index: nokia-decoding.c
===================================================================
RCS file: /sources/gnokii/gnokii/common/nokia-decoding.c,v
retrieving revision 1.23
diff -d -p -r1.23 nokia-decoding.c
*** nokia-decoding.c 8 May 2005 21:40:13 -0000 1.23
--- nokia-decoding.c 12 Jan 2006 17:20:28 -0000
*************** gn_error phonebook_decode(unsigned char 
*** 234,241 ****

  

  static gn_error calnote_get_alarm(int alarmdiff, gn_timestamp *time, gn_timestamp *alarm)
  {
! time_t t_alarm;
! struct tm tm_time, *tm_alarm;

  

  if (!time || !alarm) return GN_ERR_INTERNALERROR;

  

--- 234,240 ----

  

  static gn_error calnote_get_alarm(int alarmdiff, gn_timestamp *time, gn_timestamp *alarm)
  {
! struct tm tm_time;

  

  if (!time || !alarm) return GN_ERR_INTERNALERROR;

  

*************** static gn_error calnote_get_alarm(int al
*** 245,264 ****
  tm_time.tm_mday = time->day;
  tm_time.tm_hour = time->hour;
  tm_time.tm_min = time->minute;

  

! tzset();
! t_alarm = mktime(&tm_time);
! t_alarm -= alarmdiff;
! t_alarm += timezone;
! 
! tm_alarm = localtime(&t_alarm);

  

! alarm->year = tm_alarm->tm_year + 1900;
! alarm->month = tm_alarm->tm_mon + 1;
! alarm->day = tm_alarm->tm_mday;
! alarm->hour = tm_alarm->tm_hour;
! alarm->minute = tm_alarm->tm_min;
! alarm->second = tm_alarm->tm_sec;

  

  return GN_ERR_NONE;
  }
--- 244,262 ----
  tm_time.tm_mday = time->day;
  tm_time.tm_hour = time->hour;
  tm_time.tm_min = time->minute;
+ 
+ /* The alarm time is an offset in seconds before the given timestamp */
+ tm_time.tm_sec = -alarmdiff;

  

! /* normalize the time structure */
! (void) timegm(&tm_time);

  

! alarm->year = tm_time.tm_year + 1900;
! alarm->month = tm_time.tm_mon + 1;
! alarm->day = tm_time.tm_mday;
! alarm->hour = tm_time.tm_hour;
! alarm->minute = tm_time.tm_min;
! alarm->second = tm_time.tm_sec;

  

  return GN_ERR_NONE;
  }


reply via email to

[Prev in Thread] Current Thread [Next in Thread]