UTC and local time

As IPFM runs 24 hours a day 365 days a year and dumps data at fixed times, it has to handel the daylight saving time problematic some sort of way.

Until now, this was done prety simple: IPFM works in UTC, ignores local time and the user has to cope with it.

This is not 100% true however, as there is a possibility to convert the output in local time strings (filename, text in the files). This leads to data loss:

  • when a user clears its data every day but dumps it every hour (see the wiki:FAQ, "Why does IPFM loose data ?"
  • every day that has 25 hours, the logfiles saved at 2A:xx are overwritten by the logfiles saved at 2B:xx

How does it work in IPFM ?

Internaly, IPFM only works with UTC time.
It knows when next dump occurs, and how many times it still has to dump before to clear.

DUMP

To configure the time of next dump, you use the DUMP configuration:

DUMP every 20 minutes after 4 minutes and 12 seconds

This will dump at x:24:12, x:44:12, x+1:04:12 and so on.

If the after offset is bigger than the dump interval, IPFM will reduce it to fit in the dump interval. I could have written after 24 minutes and 12 seconds here, IPFM would have done the same.

CLEAR

CLEAR is converted in a number of dump intervals, the clear time and offset MUST be a multiple of the DUMP interval. DUMP and CLEAR offsets are added.

CLEAR every 2 hours after 40 minutes

This will clear every 2 hours, at 0:44:12, 2:44:12, 4:44:12, 6:44:12 and so on.

UTC and Local time

All of this works well until you begin to want to dump every day at 1:00. As most people think in their local time, 1:00 should be local time. This is a problem because in most countries, daylight saving time is in use. So one day a year has 23 hours, and another one has 25 hours.

This does not fit in IPFM schema of intervals (how do I know if I have to dump 1, 2, 3,... x times more or less at a perticular point of time ?)

Back then, after looking for solutions, I did not find something that would work well and decided that IPFM will only work in UTC, and gave an option to have the output (filenames, text in the files) in local time. This does cause much trouble, so I'm looking for an improvement.

Possible improvements

  • allow local time in the configuration for clear and dump (after offset). This could be better for the user (he would not have to calculate his midnight time anymore) [EASY to implement at the time of the configuration, hard if you want it to work in the summer and in the winter]
  • find a library that fits for IPFM needs and works with all daylight savings around the world... [good luck!] I think we have to cope with the functionality of libc.
  • local time output should differentiate between first and second hour 02:00: 02A:00 and 02B:00. For this, use %Z, which prints the zone nqme (CET, CEST for my zone)
  • change IPFM way of calculating time of dump/clear to fit local time [daylight saving library needed]

libc6

libc6 does handle local time, daylight saving and UTC. Here are the functions I could find:

struct tm {
  int     tm_sec;         /* seconds */
  int     tm_min;         /* minutes */
  int     tm_hour;        /* hours */
  int     tm_mday;        /* day of the month */
  int     tm_mon;         /* month */
  int     tm_year;        /* year */
  int     tm_wday;        /* day of the week */
  int     tm_yday;        /* day in the year */
  int     tm_isdst;       /* daylight saving time: <0 if unknown, >0 daylight saving time in effect at the time described, 0 not in effect */
/* BSD qnd GNU extensions */
  long int tm_gmtoff      /* delta to UTC */
  const char *tm_zone     /* name of timezone */
};

#include <time.h>
extern char *tzname[2];   /* timezone name without[0] and with[1] DST */
extern long timezone;     /* seconds West of GMT (does not depend on DST) */
extern int daylight;      /* 0 if this time zone does not have any DST rules,
                             nonzero if there is a time during the year when DST applies */

time_t mktime(struct tm *tm); /* convert local time in seconds since epoch (UTC);
                                 tm_wday and tm_yday are ignored; tm_isdst can be set to -1*/

links