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

version» Context lines:

pike.git/lib/modules/Calendar.pmod/Stardate.pmod:1: - //! module Calendar - //! submodule Stardate - //! This implements TNG stardates. -  +    #pike __REAL_VERSION__    -  + //! This implements TNG stardates. +    inherit .TimeRanges;      static constant TNGSTARPERJULIAN=1000.0/365.2425;   static constant TNGSTARPERSECOND=TNGSTARPERJULIAN/86400;   static constant TNG0JULIAN=2569518.5;   static constant TNG0UNIX=11139552000;      string calendar_name() { return "Stardate"; }      function(mixed...:cTick) Tick=cTick; -  +  + //!   class cTick   {    inherit TimeRange;       constant is_stardate=1;       float t;    float len;    - //! method void create(mixed ...) - //! method void create(int|float date) - //! method void create() +  //! @decl void create(mixed ...) +  //! @decl void create(int|float date) +  //! @decl void create()    //! Apart from the standard creation methods    //! (julian day, etc), you can create a stardate    //! from the stardate number. The length    //! of the period will then be zero.    //!    //! You can also omit any arguments to create now.    //! - //! known bugs: +  //! @bugs    //! Since the precision is limited to the float type - //! of pike you can get non-precise results: +  //! of Pike you can get non-precise results:    //! - //! <pre> +  //! @code{    //! > Calendar.Second(Calendar.Stardate.Day(Calendar.Year()));    //! Result: Second(Fri 31 Dec 1999 23:59:18 CET - Sun 31 Dec 2000 23:59:18 CET) - //! </pre> +  //! @}          void create(mixed ...args)    {    switch (sizeof(args))    {    case 4:    // internal    if (args[0]=="stardate")    {
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:86:    t=(unixtime-TNG0UNIX)*TNGSTARPERSECOND;    len=0.0;    }       static void create_julian_day(int|float jd)    {    t=(jd-TNG0JULIAN)*TNGSTARPERJULIAN;    len=0.0;    }    - // method float tic() - // This gives back the start of the stardate period, - // as a float. -  +  //! This gives back the start of the stardate period, +  //! as a float.    float tic()    {    return t;    }    - //! method float tics() - //! This gives back the number of stardate tics - //! in the period. -  +  //! This gives back the number of stardate tics +  //! in the period.    float tics()    {    return len;    }    - //! method int number_of_seconds() - //! method int number_of_days() - //! This gives back the Gregorian/Earth/ISO number of seconds - //! and number of days, for convinience and conversion to - //! other calendars. -  +  //! This gives back the Gregorian/Earth/ISO number of seconds, +  //! for convinience and conversion to other calendars.    int number_of_seconds()    {    return (int)(len/TNGSTARPERSECOND);    }    -  +  //! This gives back the Gregorian/Earth/ISO number of days, +  //! for convinience and conversion to other calendars.    int number_of_days()    {    return (int)(len/TNGSTARPERJULIAN);    }       int unix_time()    {    return ((int)(t/TNGSTARPERSECOND))+TNG0UNIX;    }   
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:261:    return sprintf("%s..%s",nice_print(),end()->nice_print());    else    return sprintf("%s..%+g",nice_print(),len);    }       string nice_print()    {    return sprintf("%.3f",t);    }    - //! string format_long(void|int precision) - //! string format_short(void|int precision) - //! string format_vshort(void|int precision) - //! Format the stardate tick nicely. Precision is the number of decimals. Defaults to 3. - //! <pre> - //! long "-322537.312" - //! short "77463.312" (w/o >100000-component) - //! vshort "7463.312" (w/o >10000-component) - //! </pre> +  //! @decl string format_long(void|int precision) +  //! @decl string format_short(void|int precision) +  //! @decl string format_vshort(void|int precision) +  //! Format the stardate tick nicely. Precision is the number of +  //! decimals. Defaults to 3. +  //! @xml{<matrix> +  //! <r><c>long</c><c>"-322537.312"</c><c></c></r> +  //! <r><c>short</c><c>"77463.312"</c><c>(w/o >100000-component)</c></r> +  //! <r><c>vshort</c><c>"7463.312"</c><c>(w/o >10000-component)</c></r> +  //! </matrix>@}       string format_long(void|int p)    {    return sprintf("%.*f",p||3,t);    }       string format_short(void|int p)    {    return sprintf("%.*f",p||3,t-((int)t/100000)*100000);    }
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:297:   // compat   function(mixed...:cTick) TNGDate=cTick;      // for events   function(mixed...:cTick) Day=cTick;      //------------------------------------------------------------------------   // global convinience functions   //------------------------------------------------------------------------    - //! method Time.TimeofDay now() - //! Give the zero-length time period of the - //! current time. -  + //! Give the zero-length time period of the current time.   .Time.TimeofDay now()   {    return Tick();   }