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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Time.pmod:1:   //!   //! module Calendar   //! submodule Time   //!   //! Base for time of day in calendars, ie   //! calendars with hours, minutes, seconds   //!   //! This module can't be used by itself, but   //! is inherited by other modules (<ref>ISO</ref> by <ref>YMD</ref>,   //! for instance). + //! + //! inherits TimeRanges      #pike __REAL_VERSION__      // #pragma strict_types      //- these classes majorly works on seconds   //- an hour is 3600 seconds, a minute is 60 seconds      inherit Calendar.TimeRanges:TimeRanges;      #include "constants.h"      // from inherited module      function(mixed...:TimeRange) Day;    - // sanity check -  - #ifndef __AUTO_BIGNUM__ - #error Calendar.Time needs bignums (Gmp.mpz) - #endif -  +    Calendar.Rule.Timezone Timezone_UTC=    Calendar.Rule.Timezone(0,"UTC"); // needed for dumping      string calendar_name() { return "Time"; }      //------------------------------------------------------------------------   //! class TimeofDay   //! Virtual class used by e.g. Hour.   //------------------------------------------------------------------------   
pike.git/lib/modules/Calendar.pmod/Time.pmod:63:   //! a time of day can also be constructed with unixtime   //! as single argument consisting of the unix time   //! - as returned from <tt>time(2)</tt> - of the time unit start.   //!   //! It can also be constructed without argument, which   //! then means "now", as in "this minute".      //- for internal use:   //- method void create("timeofday",rules,unixtime,len)    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    rules=default_rules;    create_now();    return;    }    switch (args[0])    {    case "timeofday":
pike.git/lib/modules/Calendar.pmod/Time.pmod:152:    {   // 1970-01-01 is julian day 2440588    jd-=2440588;    float fjd=(jd-(int)jd)-0.5;    ls=CALUNKNOWN;    create_unixtime_default(((int)jd)*86400+(int)(fjd*86400));    }      // make base   // needed in ymd - /*static*/ TimeRange make_base() + /*protected*/ TimeRange make_base()    {    base=Day("unix_r",ux,rules);    if (len) base=base->range(Day("unix_r",ux+len,rules));   // werror("make base -> %O\n",base);    return base;    }      // make local second    protected void make_local()    {
pike.git/lib/modules/Calendar.pmod/Time.pmod:666:    {    if (ls==CALUNKNOWN) make_local();    return ls%60;    }       float fraction_no()    {    return 0.0;    }    - //! function mapping datetime() + //! method mapping datetime()   //! This gives back a mapping with the relevant   //! time information (representing the start of the period);   //! <pre>   //! ([ "year": int // year number (2000 AD=2000, 1 BC==0)   //! "month": int(1..) // month of year   //! "day": int(1..) // day of month   //! "yearday": int(1..) // day of year   //! "week": int(1..) // week of year   //! "week_day": int(1..) // day of week (depending on calendar)   //!
pike.git/lib/modules/Calendar.pmod/Time.pmod:1217:   #undef RBASE      // count parts elapsed    string format_elapsed()    {    TimeRange z=parts[0];    foreach (parts,TimeRange y) z+=y;    return parts[0]->distance(z)->format_elapsed();    }    -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    if (t=='t')    return "Calendar."+calendar_name()+".TimeofDay";    return ::_sprintf(t,m);    }   }      class cNullTimeRange   {    inherit TimeRanges::cNullTimeRange;
pike.git/lib/modules/Calendar.pmod/Time.pmod:1257:      function(mixed...:cHour) Hour=cHour; // inheritance purposes   class cHour   {    constant is_hour=1;      //! inherits TimeofDay       inherit TimeofDay;    -  int __hash() { return ux/(60*60); } +  protected int __hash() { return ux/(60*60); }       void create_unixtime_default(int unixtime)    {    create_unixtime(unixtime,3600);    }       protected void create_now()    {    create_unixtime(time(),3600);    }
pike.git/lib/modules/Calendar.pmod/Time.pmod:1297:       TimeofDay _move(int n,int m)    {    if (m==0 || n==0) return this;    if (m%3600)    return Second("timeofday",rules,ux,len)->_move(n,m);    return Hour("timeofday",rules,ux+n*m,len)->autopromote();    }       -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    if (catch {    switch (t)    {    case 'O':    if (!base) make_base();    if (len!=3600)    return sprintf("Hour(%s)",    nice_print_period());    return sprintf("Hour(%s %s)",
pike.git/lib/modules/Calendar.pmod/Time.pmod:1369:      function(mixed...:cMinute) Minute=cMinute; // inheritance purposes   class cMinute   {    constant is_minute=1;      //! inherits TimeofDay       inherit TimeofDay;    -  int __hash() { return ux/60; } +  protected int __hash() { return ux/60; }       protected void create_unixtime(int _ux,int _len)    {    ::create_unixtime(_ux,_len);    if (ls==CALUNKNOWN) make_local();    ux-=ls%60;    }       void create_unixtime_default(int unixtime)    {
pike.git/lib/modules/Calendar.pmod/Time.pmod:1409:    len-=len%60;    }       TimeofDay _move(int n,int m)    {    if (m==0 || n==0) return this;    if (m%60) return Second("timeofday",rules,ux,len)->_move(n,m);    return Minute("timeofday",rules,ux+n*m,len)->autopromote();    }    -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    if (!base) make_base();    if (len!=60)    return sprintf("Minute(%s)",    nice_print_period());    return sprintf("Minute(%s %s)",    base->nice_print(),
pike.git/lib/modules/Calendar.pmod/Time.pmod:1476:      function(mixed...:cSecond) Second=cSecond; // inheritance purposes   class cSecond   {    constant is_second=1;      //! inherits TimeofDay       inherit TimeofDay;    -  int __hash() { return ux; } +  protected int __hash() { return ux; }       void create_unixtime_default(int unixtime)    {    create_unixtime(unixtime,1);    }       protected void create_now()    {    create_unixtime(time(),1);    }
pike.git/lib/modules/Calendar.pmod/Time.pmod:1508:    return Minute("timeofday",rules,ux,len)->autopromote();    return ::autopromote();    }       TimeofDay _move(int n,int m)    {    if (m==0 || n==0) return this;    return Second("timeofday",rules,ux+n*m,len)->autopromote();    }    -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    if (len!=1)    return sprintf("Second(%s)",    nice_print_period());    if (!base) make_base();    return sprintf("Second(%s %s)",    base->nice_print(),
pike.git/lib/modules/Calendar.pmod/Time.pmod:1584:   //!   //! It contains everything that is possible to do with a   //! <ref>Second</ref>, and also some methods of grabbing   //! the time period with higher resolution.   //!   //! note:   //! Internally, the fraction time period is measured in   //! nanoseconds. A shorter or more precise time period then   //! in nanoseconds is not possible within the current Fraction class.   //! - //! inherits TimeofDay + //! inherits Second   //------------------------------------------------------------------------      function(mixed...:cFraction) Fraction=cFraction;   class cFraction   {    inherit cSecond;       constant is_timeofday_f=1;    constant is_fraction=1;   
pike.git/lib/modules/Calendar.pmod/Time.pmod:1619:   //! and the size of the period can be given in floats,   //! both representing seconds. Note that the default   //! float precision in pike is rather low (same as 'float' in C,   //! the 32 bit floating point precision, normally about 7 digits),   //! so beware that the resolution might bite you. (Internally   //! in a Fraction, the representation is an integer.)   //!   //! If created without explicit length, the fraction will always be   //! of zero length.    -  void create(mixed ...args) +  protected void create(mixed ...args)    {    if (!sizeof(args))    {    rules=default_rules;    create_now();    return;    }    else if (args[0]=="timeofday_f")    {    rules=[object(Calendar.Ruleset)]args[1];
pike.git/lib/modules/Calendar.pmod/Time.pmod:1766:    {   // 1970-01-01 is julian day 2440588    jd-=2440588;    float fjd=((jd-(int)jd)+0.5)*86400;    ux=((int)jd)*86400+(int)(fjd);    ns=(int)(inano*(fjd-(int)fjd));       ls=CALUNKNOWN;    }    -  string _sprintf(int t,mapping m) +  protected string _sprintf(int t,mapping m)    {    switch (t)    {    case 'O':    if (!base) make_base();    if (len_ns || len_s)    return sprintf("Fraction(%s)",    nice_print_period());    return sprintf("Fraction(%s %s)",    base->nice_print(),    nice_print());    case 't':    return "Calendar."+calendar_name()+".Fraction";    default:    return ::_sprintf(t,m);    }    }    -  int __hash() { return ux; } +  protected int __hash() { return ux; }       string nice_print()    {    if (ls==CALUNKNOWN) make_local();    return sprintf("%d:%02d:%02d.%06d %s",    ls/3600,ls/60%60,ls%60,ns/1000,tzname());    }       string format_nice()    {