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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Timezone.pmod:57:   //! 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__      // ----------------------------------------------------------------   // static    - .Rule.Timezone UTC=.Rule.Timezone(0,"UTC"); + Calendar.Rule.Timezone UTC=Calendar.Rule.Timezone(0,"UTC");      // ----------------------------------------------------------------   // from the system    - .Rule.Timezone locale=0; + Calendar.Rule.Timezone locale=0;    - static function(:.Rule.Timezone) _locale() + static function(:Calendar.Rule.Timezone) _locale()   { -  .Rule.Timezone tz; +  Calendar.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:136: Inside #if 1 and #if constant(tzname)
   tz=::`[](tzn[0]);    if (tz && l->timezone==tz->raw_utc_offset()) return tz;   #endif   #endif       // run an expert system try on the localtime() rules,    // default to localtime()    return expert(localtime());   };    - .Rule.Timezone tz_from_tzfile(string tzfile) + Calendar.Rule.Timezone tz_from_tzfile(string tzfile)   {    array header = array_sscanf(tzfile, "%4s%16s%4c%4c%4c%4c%4c%4c");    if( sizeof(header)<8 ) return 0;    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    - static .Rule.Timezone timezone_expert_rec(.Rule.Timezone try, + static 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 .Rule.Timezone timezone_select(.Rule.Timezone try, + static 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;
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:206:      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));   }      static object expert_cal, expert_tzn;    - .Rule.Timezone expert(.Rule.Timezone try) + 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);   }      // ----------------------------------------------------------------
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:301:    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   { -  .Rule.Timezone what; +  Calendar.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(.Rule.Timezone enc,string name,int off) +  static 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 .Rule.Timezone _make_new_timezone_i(string tz,int plusminus) + static private Calendar.Rule.Timezone _make_new_timezone_i(string tz, +  int plusminus)   { -  .Rule.Timezone z=`[](tz); +  Calendar.Rule.Timezone z=`[](tz);    if (!z) return UNDEFINED;    return make_new_timezone(z,plusminus);   }      // internal, don't use this outside calendar module - .Rule.Timezone make_new_timezone(.Rule.Timezone z,int plusminus) + Calendar.Rule.Timezone make_new_timezone(Calendar.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:392:       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 .Rule.Timezone _magic_timezone(string tz) + static 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:429:    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));   }    - .Rule.Timezone `[](string tz) + Calendar.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:1140:       object compile_handler = class {    mapping(string:mixed) get_default_module() {    return constants;    }       mapping constants = all_constants() +    (["TZrules":Dummymodule(find_rule),    "TZRules":TZRules,    "TZHistory":TZHistory, -  "Rule":.Rule, +  "Rule":Calendar.Rule,    "ZEROSHIFT":({0,0,0,""})    ]);       }();      // #define RTTZC_DEBUG   // #define RTTZC_TIMING       object find_zone(string s)    {
pike.git/lib/modules/Calendar.pmod/Timezone.pmod:1430:       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 -  .Rule.Timezone whatrule(int ux); +  Calendar.Rule.Timezone whatrule(int ux);       string name=sprintf("%O",this_program);       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);