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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Timezone.pmod:33:   //! saving rules. Most of them historic.   //!   //! The timezone information comes from   //! <a href=ftp://elsie.nci.nih.gov/pub/>ftp://elsie.nci.nih.gov/pub/</a>   //! and are not made up from scratch. Timezone bugs may be reported   //! to the timezone mailing list,   //! <a href=mailto:tz@elsie.nci.nih.gov>tz@elsie.nci.nih.gov</a>,   //! preferable with a <tt>cc</tt> to   //! <a href=mailto:mirar@mirar.org>mirar@mirar.org</a>. /Mirar   //! - //! see also: TZnames, Ruleset.Timezone + //! see also: TZnames    - //! constant Ruleset.Timezone locale + //! constant Rule.Timezone locale   //! This contains the local timezone, found from   //! various parts of the system, if possible.    - //! constant Ruleset.Timezone localtime + //! constant Rule.Timezone localtime   //! This is a special timezone, that uses <ref>localtime</ref>()   //! and <ref>tzname</ref>   //! to find out what current offset and timezone string to use.   //!   //! <ref>locale</ref> uses this if there is no other   //! way of finding a better timezone to use.   //!   //! This timezone is limited by <ref>localtime</ref> and   //! libc to the range of <tt>time_t</tt>,   //! which is a MAXINT on most systems - 13 Dec 1901 20:45:52   //! to 19 Jan 2038 3:14:07, UTC.      #pike __REAL_VERSION__    - import "."; -  +    // ----------------------------------------------------------------   // static    - Ruleset.Timezone UTC=Ruleset()->Timezone(0,"UTC"); + .Rule.Timezone UTC=.Rule.Timezone(0,"UTC");      // ----------------------------------------------------------------   // from the system    - Ruleset.Timezone locale=0; + .Rule.Timezone locale=0;    - static function(:Ruleset.Timezone) _locale() + static function(:.Rule.Timezone) _locale()   { -  Ruleset.Timezone tz; +  .Rule.Timezone tz;      // try to get the real local time settings      #if 1    string s;       if ( (s=getenv("TZ")) )    {    tz=`[](s);    if (tz) return tz;
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:107:   #endif       // 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, + static .Rule.Timezone timezone_expert_rec(.Rule.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);    }
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:134:    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, + static .Rule.Timezone timezone_select(.Rule.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;
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:158:    return `[](tree[0]);   }      static array timezone_collect(string|mapping|array tree)   {    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) + static object expert_cal, expert_tzn; +  + .Rule.Timezone expert(.Rule.Timezone try)   { -  object cal=master()->resolv("Calendar")["ISO_UTC"]; -  return timezone_expert_rec(try,TZnames.timezone_expert_tree,cal); +  if(!expert_cal) +  expert_cal=master()->resolv("Calendar")["ISO_UTC"]; +  if(!expert_tzn) +  expert_tzn=master()->resolv("Calendar")["TZnames"]; +  return timezone_expert_rec(try, expert_tzn->timezone_expert_tree, +  expert_cal);   }      // ----------------------------------------------------------------      class localtime   {    constant is_timezone=1;    constant is_dst_timezone=1;      #if constant(tzname)
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:212:    string _sprintf(int t) { return (t=='O')?"Timezone.localtime()":0; }       int raw_utc_offset(); // N/A but needed for interface   }      // ----------------------------------------------------------------   // magic timezones      class Timezone_Encapsule   { -  Ruleset.Timezone what; +  .Rule.Timezone what;       constant is_timezone=1;    constant is_dst_timezone=1; // ask me       static string extra_name;    static int extra_offset;    string name;    -  static void create(Ruleset.Timezone enc,string name,int off) +  static void create(.Rule.Timezone enc,string name,int off)    {    what=enc;    extra_name=name;    extra_offset=off;    name=enc->name+extra_name;    }       array(int) tz_ux(int unixtime)    {    array z=what->tz_ux(unixtime);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:249:    }       string _sprintf(int t)    {    return (t=='O')?sprintf("%O%s",what,extra_name):0;    }       int raw_utc_offset() { return what->raw_utc_offset()+extra_offset; }   }    - static private Ruleset.Timezone _make_new_timezone_i(string tz,int plusminus) + static private .Rule.Timezone _make_new_timezone_i(string tz,int plusminus)   { -  object(Ruleset.Timezone) z=`[](tz); +  .Rule.Timezone z=`[](tz);    if (!z) return UNDEFINED;    return make_new_timezone(z,plusminus);   }      // internal, don't use this outside calendar module - Ruleset.Timezone make_new_timezone(Ruleset.Timezone z,int plusminus) + .Rule.Timezone make_new_timezone(.Rule.Timezone z,int plusminus)   {    if (plusminus>14*3600 || plusminus<-14*3600)    error("difference out of range -14..14 h\n");    if (plusminus==0)    return z;    string s;    if (plusminus%60)    s=sprintf("%+d:%02d:%02d",plusminus/3600,plusminus/60%60,plusminus%60);    else if (plusminus/60%60)    s=sprintf("%+d:%02d",plusminus/3600,plusminus/60%60);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:303:       if (sscanf(w,"%d:%d:%d",a,b,c)==3)    return neg*(a*3600+b*60+c);    else if (sscanf(w,"%d:%d",a,b,c)==2)    return neg*(a*3600+b*60);    sscanf(w,"%d%s",a,s);    if (s!="") { sscanf(w,"%f",f); if (f!=(float)a) return neg*(int)(f*3600); }    return neg*a*3600; // ignore litter   }    - static private Ruleset.Timezone _magic_timezone(string tz) + static private .Rule.Timezone _magic_timezone(string tz)   {    string z,w;       if (!runtime_timezone_compiler)    runtime_timezone_compiler=Runtime_timezone_compiler();      // int t=time(1);   // float t1=time(t);   // runtime_timezone_compiler->find_rule("EU");    object p=runtime_timezone_compiler->find_zone(tz);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:340:    case 4: return _magic_timezone("UTC"+a+b[..1]+":"+b[2..]);    case 6:    return _magic_timezone("UTC"+a+b[..1]+":"+b[2..3]+":"+b[4..]);    }    }    else if (a=="+-") return _magic_timezone("-0"+b);       return ::`[](replace(tz,"-/+"/1,"__p"/1));   }    - Ruleset.Timezone `[](string tz) + .Rule.Timezone `[](string tz)   {    mixed p=::`[](tz);    if (!p && tz=="locale") return locale=_locale();       if ((<"make_new_timezone","decode_timeskew">)[tz]) return p;       if (!p) p=_magic_timezone(tz);    if (programp(p) || functionp(p)) return p();    return p;   }
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:860:    else if (sscanf(a[1],"%d:%d:%d",h,m,s)==3) roff=h*3600+m*60+s;    else if (sscanf(a[1],"-%d:%d",h,m)==2) roff=h*3600+m*60;    else if (sscanf(a[1],"%d:%d",h,m)==2) roff=h*3600+m*60;       if (roff==-17) // based on DST rule    return sprintf(    "TZrules.%s(%d,%O)",    FIXID(a[1]),-a[0],a[2]);    else // simple timezone    return sprintf( -  "Ruleset.Timezone(%d,%O)", +  "Rules.Timezone(%d,%O)",    -(roff+a[0]),a[2]);    }       string rule_shift(array a)    {    if (a[3]=="" || a[3][0]=='#') return "forever";       string in=a[3];    sscanf(in,"until %s",in);    sscanf(in,"%s#",in);
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:948:    }       mapping rname=([]);    int n=1;       foreach (rules,array a)    if (rname[a[4]]) a[6]=rname[a[4]];    else a[6]=rname[a[4]]="tz"+n++;       res+=({ "inherit TZHistory;\n" -  "Ruleset.Timezone ", +  "Rules.Timezone ",    sort(values(rname))*",",";\n" -  "Ruleset.Timezone whatrule(int ux)\n" +  "Rules.Timezone whatrule(int ux)\n"    "{\n" });       foreach (rules,array a)    {    if (!a[5]) a[5]=rule_shift(a);       string s="";    sscanf(a[3],"%s#%*[ \t]%s",a[3],s);    a[3]="from "+reverse(array_sscanf(reverse(a[3]),"%*[ \t]%s")[0]);    a[7]=s;
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:999:    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",    sprintf(    "string _sprintf(int t) { return (t=='O')?"    "%O:0; }\n" -  "string zoneid=%O;\n","Timezone("+id+")",id)}); +  "string zoneid=%O;\n","Rule.Timezone("+id+")",id)});       return res*"";    }    }       string base_path=combine_path(__FILE__,"../tzdata/");    array files=    ({    "africa",    "antarctica",
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1050:       object compile_handler = class {    mapping(string:mixed) get_default_module() {    return constants;    }       mapping constants = all_constants() +    (["TZrules":Dummymodule(find_rule),    "TZRules":TZRules,    "TZHistory":TZHistory, -  "Ruleset":Ruleset, +  "Rules":.Rule,    "ZEROSHIFT":({0,0,0,""})    ]);       }();      // #define RTTZC_DEBUG   // #define RTTZC_TIMING       object find_zone(string s)    {
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1134: Inside #if defined(RTTZC_DEBUG)
  #ifdef RTTZC_DEBUG    werror("%s\n",c);   #endif       program p;    mixed err=catch { p=compile_string(c, 0, compile_handler); };    if (err)    {    int i=0;    foreach (c/"\n",string line) write("%2d: %s\n",++i,line); -  throw(err); +  error(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:1329:    array b=a[i+1];    if (jd<b[0]-1) break;    if (jd<b[0]+1 &&    ux<(b[0]-2440588)*86400+b[1]) break;    i++;    }       return ({offset_to_utc-a[i][2],tzformat(a[i][3])});    }    -  string _sprintf(int t) { return (t=='O')?"Timezone("+name+")":0; } +  string _sprintf(int t) { return (t=='O')?"Rule.Timezone("+name+")":0; }       int raw_utc_offset() { return offset_to_utc; }    }       class TZHistory    {    constant is_timezone=1;    constant is_dst_timezone=1;      // figure out what timezone to use -  Ruleset.Timezone whatrule(int ux); +  .Rule.Timezone whatrule(int ux);       string name=sprintf("%O",object_program(this_object()));       array(int) tz_ux(int ux)    {    // werror("tz_ux %O\n",ux);    // object z=whatrule(ux);    // werror("%O %O\n",z->offset_to_utc,z->name);    // return z->tz_ux(ux);    return whatrule(ux)->tz_ux(ux);