Branch: Tag:

2007-05-14

2007-05-14 06:01:42 by Martin Bähr <mbaehr@email.archlab.tuwien.ac.at>

add code to pull out possible timezones from /etc/localtime
this feels rather hackish. not sure how to improve it though

Rev: lib/modules/Calendar.pmod/Timezone.pmod:1.36

86: Inside #if 1
   if (tz) return tz;    }    +  if(s = Stdio.read_bytes("/etc/localtime")) +  { +  tz=tz_from_tzfile(s); +  if (tz) return tz; +  } +    // Linux RedHat    if (Stdio.is_dir("/etc/sysconfig/.") &&    (s = Stdio.read_bytes("/etc/sysconfig/clock")) )
110:    return expert(localtime());   };    + .Rule.Timezone tz_from_tzfile(string tzfile) + { +  array header = array_sscanf(tzfile, "%4s%16s%4c%4c%4c%4c%4c%4c"); +  array zoneabbr = tzfile[44+header[5]*4+header[5]+header[6]*6..44+header[5]*4+header[5]+header[6]*6+header[7]-1]/"\0"; +  if(!expert_tzn) +  expert_tzn=master()->resolv("Calendar")["TZnames"]; +  +  array validzones = `&(@values(expert_tzn->abbr2zones & mkmultiset(zoneabbr))); +  if(sizeof(validzones) == 1) +  return `[](validzones[0]); + } +  +    // ----------------------------------------------------------------   // expert system to pick out the correct timezone