Logo Search packages:      
Sourcecode: libical version File versions

static void format_utc_offset ( int  utc_offset,
char *  buffer 
) [static]

This formats a UTC offset as "+HHMM" or "+HHMMSS". buffer should have space for 8 characters.

Definition at line 1896 of file icaltimezone.c.

Referenced by icaltimezone_dump_changes().

{
  const char *sign = "+";
  int hours, minutes, seconds;

  if (utc_offset < 0) {
    utc_offset = -utc_offset;
    sign = "-";
  }

  hours = utc_offset / 3600;
  minutes = (utc_offset % 3600) / 60;
  seconds = utc_offset % 60;

  /* Sanity check. Standard timezone offsets shouldn't be much more than 12
     hours, and daylight saving shouldn't change it by more than a few hours.
     (The maximum offset is 15 hours 56 minutes at present.) */
  if (hours < 0 || hours >= 24 || minutes < 0 || minutes >= 60
      || seconds < 0 || seconds >= 60) {
    fprintf (stderr, "Warning: Strange timezone offset: H:%i M:%i S:%i\n",
           hours, minutes, seconds);
  }

  if (seconds == 0)
    snprintf (buffer, sizeof(buffer), "%s%02i%02i", sign, hours, minutes);
  else
    snprintf (buffer, sizeof(buffer), "%s%02i%02i%02i", sign, hours, minutes, seconds);
}


Generated by  Doxygen 1.6.0   Back to index