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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Timezone.pmod:64:   // ----------------------------------------------------------------   // static      Calendar.Rule.Timezone UTC=Calendar.Rule.Timezone(0,"UTC");      // ----------------------------------------------------------------   // from the system      Calendar.Rule.Timezone locale=0;    - static function(:Calendar.Rule.Timezone) _locale() + protected function(:Calendar.Rule.Timezone) _locale()   {    Calendar.Rule.Timezone tz;      // try to get the real local time settings      #if 1    string s;       if ( (s=getenv("TZ")) )    {
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:153:       array validzones = `&(@values(expert_tzn->abbr2zones & mkmultiset(zoneabbr)));    if(sizeof(validzones) == 1)    return `[](validzones[0]);   }         // ----------------------------------------------------------------   // expert system to pick out the correct timezone    - static Calendar.Rule.Timezone timezone_expert_rec(Calendar.Rule.Timezone try, + protected Calendar.Rule.Timezone timezone_expert_rec(Calendar.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:180:    if (mappingp(tree))    return timezone_expert_rec(try,tree,cal);       if (arrayp(tree))    return timezone_select(try,tree,cal);      // stringp    return `[](tree);   }    - static Calendar.Rule.Timezone timezone_select(Calendar.Rule.Timezone try, + protected Calendar.Rule.Timezone timezone_select(Calendar.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;    tree=res;   #endif   // pick one    return `[](tree[0]);   }    - static array timezone_collect(string|mapping|array tree) + protected 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));   }    - static object expert_cal, expert_tzn; + protected object expert_cal, expert_tzn;      Calendar.Rule.Timezone expert(Calendar.Rule.Timezone try)   {    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) -  static array(string) names=tzname(); +  protected array(string) names=tzname();   #endif       string name="local";      // is (midnight) this julian day dst?    array tz_jd(int jd)    {    return tz_ux((jd-2440588)*86400);    }       // Workaround for predef::localtime() on WIN32 and others    // throwing errors for times before 1970. This interferes    // with the timezone expert system. -  static mapping(string:int) paranoia_localtime(int ux) +  protected mapping(string:int) paranoia_localtime(int ux)    {    if (ux<-0x80000000 || ux>0x7fffffff)    error("Time is out of range for Timezone.localtime()\n");    mixed err = catch { return predef::localtime(ux); };    if ((ux < 0) && (ux > -86400*2)) {    // Try post-adjustment...    // The code below actually handles up to 30 days, but...    mapping(string:int) res = predef::localtime(0);    if ((res->sec += ux) < 0) {    int delta = res->sec/60;
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:306:   // ----------------------------------------------------------------   // magic timezones      class Timezone_Encapsule   {    Calendar.Rule.Timezone what;       constant is_timezone=1;    constant is_dst_timezone=1; // ask me    -  static string extra_name; -  static int extra_offset; +  protected string extra_name; +  protected int extra_offset;    string name;    -  static void create(Calendar.Rule.Timezone enc,string name,int off) +  protected void create(Calendar.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:338:    }       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 Calendar.Rule.Timezone _make_new_timezone_i(string tz, + protected private Calendar.Rule.Timezone _make_new_timezone_i(string tz,    int plusminus)   {    Calendar.Rule.Timezone z=`[](tz);    if (!z) return UNDEFINED;    return make_new_timezone(z,plusminus);   }      // internal, don't use this outside calendar module   Calendar.Rule.Timezone make_new_timezone(Calendar.Rule.Timezone z,int plusminus)   {
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:364:    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);    else    s=sprintf("%+d",plusminus/3600);       return Timezone_Encapsule(z,s,-plusminus);   }    - static private constant _military_tz= + protected private constant _military_tz=   ([ "Y":"UTC-12", "X":"UTC-11", "W":"UTC-10", "V":"UTC-9", "U":"UTC-8",    "T":"UTC-7", "S":"UTC-6", "R":"UTC-5", "Q":"UTC-4", "P":"UTC-3",    "O":"UTC-2", "N":"UTC-1", "Z":"UTC", "A":"UTC+1", "B":"UTC+2",    "C":"UTC+3", "D":"UTC+4", "E":"UTC+5", "F":"UTC+6", "G":"UTC+7",    "H":"UTC+8", "I":"UTC+9", "K":"UTC+10", "L":"UTC+11", "M":"UTC+12",    "J":"locale" ]);    - static object runtime_timezone_compiler=0; + protected object runtime_timezone_compiler=0;      // internal, don't use this outside calendar module   int decode_timeskew(string w)   {    float f;    int a,b,c;    string s="";    int neg=1;       if (sscanf(w,"-%s",w)) neg=-1;       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)==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 Calendar.Rule.Timezone _magic_timezone(string tz) + protected private Calendar.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:1232:    "europe",    "northamerica",    "southamerica",    "pacificnew",    "systemv",    });       mapping zone_cache;    mapping rule_cache;    string all_rules; -  static mapping(string:Zone) zones = ([]); -  static mapping(string:Rule) rules = ([]); +  protected mapping(string:Zone) zones = ([]); +  protected mapping(string:Rule) rules = ([]);       string get_all_rules()    {    return    map(files,    lambda(string fn)    {    return (master()->master_read_file(base_path+fn) ||    (error("Failed to open file %O\n",base_path+fn), "")) - "\r";    })*"\n";
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1390:   // ----------------------------------------------------------------      // ----------------------------------------------------------------   // Base "Timezone with rules" class   // ----------------------------------------------------------------       class TZRules    {    constant is_timezone=1;    constant is_dst_timezone=1; -  static int offset_to_utc; +  protected int offset_to_utc;    string name;    -  static function(string:string) tzformat; -  static array names; +  protected function(string:string) tzformat; +  protected array names;         // ----------------------------------------------------------------   // all rules are based on the gregorian calendar, so   // this is the needed gregorian rule:   // ----------------------------------------------------------------    -  static array gregorian_yjd(int jd) +  protected array gregorian_yjd(int jd)    {    int d=jd-1721426;       int century=(4*d+3)/146097;    int century_jd=(century*146097)/4;    int century_day=d-century_jd;    int century_year=(100*century_day+75)/36525;       int y=century*100+century_year+1;       return    ({    y,    1721426+century_year*365+century_year/4+century_jd,    (!(((y)%4) || (!((y)%100) && ((y)%400))))    });    }    -  static void create(int offset,string _name) +  protected void create(int offset,string _name)    {    offset_to_utc=offset;    name=_name;    if (has_value(name, "/"))    {    names=name/"/";    tzformat=lambda(string s)    {    if (s=="") return names[0]; else return names[1];    };    }    else    tzformat=lambda(string s) { return sprintf(name,s); };    }      // the Rule:   // which julian day does dst start and end this year? -  static array(array(string|int)) jd_year_periods(int jd); +  protected array(array(string|int)) jd_year_periods(int jd);      // is (midnight) this julian day dst?    array tz_jd(int jd)    {    array(array(string|int)) a=jd_year_periods(jd);       int i=0,n=sizeof(a)-1;    while (i<n)    {    array b=a[i+1];