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__      import ".";      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; -  +  + //! Stardate clock tick.   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 ... args) +  //! @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. +  //! You can also omit any arguments to @[create()].    //! - //! known bugs: +  //! @bugs    //! Since the precision is limited to the float type    //! of pike you can get non-precise results:    //! - //! <pre> +  //! @pre{    //! > 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")    {    rules=args[1];    t=args[2];
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:88:    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. -  +     float tics()    {    return len;    }    - //! method int number_of_seconds() - //! method int number_of_days() - //! This gives back the Gregorian/Earth/ISO number of seconds +  //! @decl int number_of_seconds() +  //! @decl int number_of_days() +  //! These return the Gregorian/Earth/ISO number of seconds   //! and number of days, for convinience and conversion to   //! other calendars.       int number_of_seconds()    {    return (int)(len/TNGSTARPERSECOND);    }       int number_of_days()    {
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:263:    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() - //! string format_short() - //! string format_vshort() +  //! @decl string format_long() +  //! @decl string format_short() +  //! @decl string format_vshort()    //! Format the stardate tick nicely. - //! <pre> +  //! @pre{    //! long "-322537.312"    //! short "77463.312" (w/o >100000-component)    //! short "7463.312" (w/o >10000-component) - //! </pre> +  //! @}       string format_long()    {    return sprintf("%.3f",t);    }       string format_short()    {    return sprintf("%.3f",t-((int)t/100000)*100000);    }
pike.git/lib/modules/Calendar.pmod/Stardate.pmod:299:   // compat   function(mixed...:cTick) TNGDate=cTick;      // for events   function(mixed...:cTick) Day=cTick;      //------------------------------------------------------------------------   // global convinience functions   //------------------------------------------------------------------------    - //! method TimeofDay now() +    //! Give the zero-length time period of the   //! current time. -  +    TimeofDay now()   {    return Tick();   }