pike.git / lib / modules / Calendar.pmod / Timezone.pmod

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Timezone.pmod:118: Inside #if 1 and #if constant(tzname)
     #if constant(tzname)    mapping l=predef::localtime(time());    array(string) tzn=tzname();       tz=::`[](tzn[0]);    if (tz && l->timezone==tz->raw_utc_offset()) return tz;   #endif   #endif    -  return localtime(); // default - use localtime +  // run an expert system try on the localtime() rules, +  // default to localtime() +  return expert(localtime());   };    -  + // ---------------------------------------------------------------- + // expert system to pick out the correct timezone +  + static Ruleset.Timezone timezone_expert_rec(Ruleset.Timezone try, +  mapping|array|string tree, +  object cal) + { +  int t=tree->test,uo; +  if (t<0) +  { +  if (catch { uo=cal->Second(t)->set_timezone(try) +  ->utc_offset(); }) +  return timezone_select(try,timezone_collect(tree),cal); +  } +  else +  uo=cal->Second(t)->set_timezone(try)->utc_offset(); +  +  if (!(tree=tree[uo])) +  return try; +  +  if (mappingp(tree)) +  return timezone_expert_rec(try,tree,cal); +  +  if (arrayp(tree)) +  return timezone_select(try,tree,cal); +  + // stringp +  return `[](tree); + } +  + static Ruleset.Timezone timezone_select(Ruleset.Timezone try, +  array tree, +  object cal) + { + #if constant(tzname) +  array res=({}); +  multiset names=mkmultiset(tzname()); +  function f=cal->Second(970416317)->set_timezone; +  foreach (tree,string tzn) +  if (names[f(tzn)->tzname()]) res+=({tzn}); +  if (!sizeof(res)) return try; +  tree=res; + #endif + // pick one +  return `[](tree[0]); + } +  + static array timezone_collect(string|mapping|array tree) + { +  werror("bop\n"); +  if (arrayp(tree)) return tree; +  else if (stringp(tree)) return ({tree}); +  else return `+(@map(values(tree-({"test"})),timezone_collect)); + } +  + Ruleset.Timezone expert(Ruleset.Timezone try) + { +  object cal=master()->resolv("Calendar")["ISO_UTC"]; +  return timezone_expert_rec(try,TZnames.timezone_expert_tree,cal); + } +  + // ---------------------------------------------------------------- +    class localtime   {    constant is_timezone=1;    constant is_dst_timezone=1;      #if constant(tzname)    static array(string) names=tzname();   #endif       string name="local";
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:868:    tzname[sprintf(a[2],s)]=1;    }       res+=({"array(string) zone_s=({"+    map((array)tzname,    lambda(string s) { return sprintf("%O",s); })*",",    "});\n",    "array(int) shifts=({"});    foreach (rules[..sizeof(rules)-2],array a)    res+=({a[5]+","}); -  res+=({"});\n"}); +  res+=({"});\n", +  sprintf( +  "string _sprintf(int t) { return (t=='O')?" +  "%O:0; }\n" +  "string zoneid=%O;\n","Timezone("+id+")",id)});       return res*"";    }    }       string base_path=combine_path(__FILE__,"../tzdata/");    array files=    ({    "africa",    "antarctica",
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:993: Inside #if defined(RTTZC_TIMING)
   werror("dump %O: %O\n",s,td-t2);    float td=time(t);   #endif      #ifdef RTTZC_DEBUG    werror("%s\n",c);   #endif       add_constant("__Calendar_mkzone",mkzonemod);    -  program p=compile_string(c); +  program p; +  mixed err=catch { p=compile_string(c); }; +  if (err) +  { +  int i=0; +  foreach (c/"\n",string line) write("%2d: %s\n",++i,line); +  throw(err); +  }    object zo=p();    if (zo->thezone) zo=zo->thezone;      #ifdef RTTZC_TIMING    float t3=time(t);    werror("compile %O: %O\n",s,t3-td);   #endif       return zone_cache[s]=zo;    }
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1222:       array(int) tz_jd(int jd)    {    // werror("tz_jd %O\n",jd);    // object z=whatrule((jd-2440588)*86400-86400/2);    // werror("%O %O\n",z->offset_to_utc,z->name);    // return z->tz_jd(jd);    return whatrule((jd-2440588)*86400-86400/2)->tz_jd(jd);    }    -  string _sprintf(int t) { return (t=='O')?"Timezone("+name+")":0; } -  +     int raw_utc_offset();    }      // ----------------------------------------------------------------------       string TZrules_init=   #"   // useful macros   #define FIXED(D) (yjd+((D)-1))   #define FIX_L(D) (yjd+leap+((D)-1))   #define LDAY(D,W) (yjd+((D)-1)-( (yjd+((D)+(8-W)-1)) % 7))   #define LDAYL(D,W) (yjd+((D)-1)+leap-( (yjd+leap+((D)+(8-W)-1)) % 7))   #define UO offset_to_utc   ";      // ----------------------------------------------------------------------      }