c90abc1998-11-20Mirar (Pontus Hagland) //! submodule Stardate
a20af62000-09-26Fredrik Hübinette (Hubbe) //! time unit: TNGDate
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe) //! class TNGDate //! implements ST:TNG stardates //! can be used as create argument to Day
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe) #pike __VERSION__
78fd532000-07-12Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe) class TNGDate
78fd532000-07-12Mirar (Pontus Hagland) {
a20af62000-09-26Fredrik Hübinette (Hubbe)  inherit Calendar._TimeUnit; // 40759.5 2363-10-05 2584405 // 47391.2 2370-05-23 2586827
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  // 50893.5 2373-11-23 2588107
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  // 6631.7 ---------- 2422 // 10134.0 ---------- 3702 // 1000.0 ---------- 365.2425 // 0.0 - - 2569519 #define TNGSTARPERJULIAN (1000.0/365.2425)
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe) //-- variables ------------------------------------------------------
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  float jd; float tics; //-- standard methods -----------------------------------------------
c90abc1998-11-20Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  void create(int|float|object ... day)
c90abc1998-11-20Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  float jd; if (!sizeof(day)) day=({Calendar.Gregorian.Second()}); else if (floatp(day[0]))
c90abc1998-11-20Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  from_stardate(day[0]); return; } if (!intp(day[0])) { object o=day[0]; if (o->julian_day || o->julian_day_f) jd=(float)(o->julian_day_f||o->julian_day)(); else // dig if (o->day) // larger
c90abc1998-11-20Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  o=o->day(0); if (o->julian_day_f) jd=o->julian_day_f(); else if (o->julian_day) jd=(float)o->julian_day(); else ; // error, like
c90abc1998-11-20Mirar (Pontus Hagland)  }
a20af62000-09-26Fredrik Hübinette (Hubbe)  else // smaller
c90abc1998-11-20Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  float z=1.0; while (sizeof(o->greater())) { string name=o->is(); o=o[o->greater()[0]](); z*=o["number_of_"+name+"s"](); if (o->julian_day_f || o->julian_day) { jd=(o->julian_day||o->julian_day_f)()/z; break; } }
c90abc1998-11-20Mirar (Pontus Hagland)  }
78fd532000-07-12Mirar (Pontus Hagland)  } else
a20af62000-09-26Fredrik Hübinette (Hubbe)  jd=(float)day[0]; from_julian_day(jd);
c90abc1998-11-20Mirar (Pontus Hagland)  }
a20af62000-09-26Fredrik Hübinette (Hubbe)  static void from_stardate(float f)
c90abc1998-11-20Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  tics=f; jd=f/TNGSTARPERJULIAN+2569518.5;
c90abc1998-11-20Mirar (Pontus Hagland)  }
78fd532000-07-12Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  static void from_julian_day(float f)
78fd532000-07-12Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  jd=f; tics=(f-2569518.5)*TNGSTARPERJULIAN;
78fd532000-07-12Mirar (Pontus Hagland)  }
a20af62000-09-26Fredrik Hübinette (Hubbe) //-- nonstandard methods --------------------------------------------
78fd532000-07-12Mirar (Pontus Hagland) 
a20af62000-09-26Fredrik Hübinette (Hubbe)  float number()
78fd532000-07-12Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  return tics;
78fd532000-07-12Mirar (Pontus Hagland)  }
a20af62000-09-26Fredrik Hübinette (Hubbe)  int julian_day()
78fd532000-07-12Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  return (int)jd;
78fd532000-07-12Mirar (Pontus Hagland)  }
a20af62000-09-26Fredrik Hübinette (Hubbe)  float julian_day_f()
78fd532000-07-12Mirar (Pontus Hagland)  {
a20af62000-09-26Fredrik Hübinette (Hubbe)  return jd;
78fd532000-07-12Mirar (Pontus Hagland)  }
c90abc1998-11-20Mirar (Pontus Hagland) }