[misc.misc] Zed Time

zed@mdbs.uucp (Bill Smith) (09/29/90)

/* 
**	Display the time and date in obsolete o-time and the (IMHO)
**      the more intuitive zedtime.  (o- prefix for obsolete.)
**
**      Zedtime is defined in terms of 22 zedmonths of 22 zeddays, 
**	(each zedday is exactly 18 o-hours).  Each zedday is made of 16 
**	zedhours of 64 zedminutes of 64 zedseconds.  (A zedsecond is
**	approximately 98.877 o-seconds and there are 2^16 of them in a
**	zedday.)  A zedyear has 3 intercalary days at the end of the year 
**	except during the leap year which only has 2 intercalary days.  
**	A leap zedyear occurs approximately once every 117 years and is 
**      not processed by this program.  (The Unix time structure will
**      probably overflow before the next one occurs anyway. :-)
**
**	It is defined so that zedyear 147 begins at 6pm March 20, 1990 
**	which is approximately Nawruz 147, the beginning of the Baha'i 
**	year spanning 1990-1991.
**
**	Author: William W. Smith
**	E-Mail: newton.physics.purdue.edu!sawmill!mdbs!zed
**
**	Copyright (c) 1990, William W. Smith 
**	Copyright (c) 1990, Recherche Computers
**	Copyright (c) 1990, mdbs Inc. {just for completeness sake}
**
**      Justification: A zedcalendar based on a day of 18 o-hour days
**      has 487 zed days a year which is 22^2 + 3.  18 o-hours divides
**      365.25 days exactly, thus requiring no leap years except for
**      for the fraction of a hour that the earth's rotation is off from
**      precisely 365.25 o-days per trip around the world and leads to the 
**      complex century rules in the o-calendar.  A person whose 
**      circadian rhythm is 18 o-hours will find the zedcalendar much more
**      convenient for maintaining consistent eating and sleeping times.
**
**      18 o-hours is very close to 2^16 o-seconds so it is natural to
**      define the zedday in terms of that fraction of the 18 o-hour day.
**
**      It is an open question what to call each zedmonth and each zedday
**      of the month.  A natural suggestion is to name both after the letters
**      of the alphabet in a language that has only 22 letters, but this
**      author does not know that much linguistics.  Also how to define the
**      idea of a "day of the week" is unclear.
**
*/

#define OSEC_per_OHOUR       3600L   
#define OHOUR_per_ZEDDAY     18      
#define ZEDSEC_per_ZEDMIN    64   
#define ZEDMIN_per_ZEDHOUR   64   
#define ZEDDAY_per_ZEDMONTH  22
#define ZEDMONTH_per_ZEDYEAR 22
#define ZEDDAY_per_ZEDYEAR   487

#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>

long zedepoch();
char * zedtime();

main()
{

	struct timeb timeofday;
	struct tm gmt, local;
	long atime;
	long offset;
	long localatime;


	ftime(&timeofday);
	atime = time(0);
	local = *localtime(&atime);
	gmt = *gmtime(&atime);

/* 
** print the current o-time 
*/
	printf("Obsolete: %s",ctime(&atime));  

/* 
** figure out how far away we are from GMT
*/
	offset = (gmt.tm_hour - local.tm_hour ) * OSEC_per_OHOUR +
		(gmt.tm_min - local.tm_min) * 60 +
		(gmt.tm_sec - local.tm_sec);
	localatime = atime - offset;  

/* 
** print the current zedtime 
*/
	printf("Zedtime: %s",zedtime(&localatime)); 
	

}

long zedepoch()
{
	 return 
		OSEC_per_OHOUR * /* o-seconds per o-hour */
	            (24 * /* o-hours per o-day */ 
		        (31 + /* days in January */ 
		         28 + /* days in February for 1990 */
		         19) + /* the first 19 days of March */
	            18 /*hours*/); /* 6PM (approx. sunset Nawruz) */
}

char * zedtime(pin)
long * pin;
{
	static char buffr[100];
	long now;
	int year, month, dayofmonth;
	int  hour, minute, second;
	double zedseconds;
	struct timeb timeofday;
	double jiffies;

	now = *pin - zedepoch();


/* 
** 127 == 1970, the unix o-epoch, which is year 127 in the Baha'i calendar 
*/
	year = 127 + 
		(now / (ZEDDAY_per_ZEDYEAR * 
			OHOUR_per_ZEDDAY * 
			OSEC_per_OHOUR));
	now %= (ZEDDAY_per_ZEDYEAR * OHOUR_per_ZEDDAY * OSEC_per_OHOUR);

	month = (int)(now / (ZEDDAY_per_ZEDMONTH * 
			     OHOUR_per_ZEDDAY * 
			     OSEC_per_OHOUR));
	now  %= (ZEDDAY_per_ZEDMONTH * 
		 OHOUR_per_ZEDDAY * 
		 OSEC_per_OHOUR);

	dayofmonth = (int)(now / (OHOUR_per_ZEDDAY * 
				  OSEC_per_OHOUR));
	now  %= (OHOUR_per_ZEDDAY * 
		 OSEC_per_OHOUR);

	ftime(&timeofday);
	jiffies = 1000.0 * (double)now + timeofday.millitm * 1.0;

	zedseconds = jiffies * 16.0 *  /* zedhours per zedday */
				(double)ZEDMIN_per_ZEDHOUR *  
				(double)ZEDSEC_per_ZEDMIN /  
		      (1000.0 * 
		       (double)OHOUR_per_ZEDDAY * 
		       (double)OSEC_per_OHOUR);
	now = (long)(zedseconds + 0.5); /* round */

	hour = now / (ZEDMIN_per_ZEDHOUR * ZEDSEC_per_ZEDMIN);
	now %= (ZEDMIN_per_ZEDHOUR * ZEDSEC_per_ZEDMIN);

	minute = now / ZEDSEC_per_ZEDMIN;
	second = now % ZEDSEC_per_ZEDMIN;

	sprintf(buffr,"%4d/%02d/%02d %02d:%02d:%02d\n",
			year,month + 1,dayofmonth + 1,hour,minute,second);
	return buffr;
	
}

eric@snark.thyrsus.com (Eric S. Raymond) (10/27/90)

In <1990Sep28.230231.27563@mdbs.uucp> Bill Smith wrote:
> **      It is an open question what to call each zedmonth and each zedday
> **      of the month.  A natural suggestion is to name both after the letters
> **      of the alphabet in a language that has only 22 letters, but this
> **      author does not know that much linguistics.

Hebrew should do nicely. Your months can be Aleph, Beth, Gimel, Yod...
-- 
      Eric S. Raymond = ...!uunet!snark!eric  (mad mastermind of TMN-Netnews)